diff --git a/__init__.py b/__init__.py index 4c73b5f..8b13789 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1 @@ -from . import const + diff --git a/__pycache__/database.cpython-37.pyc b/__pycache__/database.cpython-37.pyc new file mode 100644 index 0000000..c1b33fc Binary files /dev/null and b/__pycache__/database.cpython-37.pyc differ diff --git a/app.py b/app.py index f24f802..8e49ad9 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +from database import Model from flask import Flask, render_template from redis import Redis from utils.processor import process_download @@ -5,6 +6,7 @@ from utils.processor import process_download app = Flask(__name__) redis = Redis(host='redis', port=6379) +Album = Model('album') @app.route('/') @@ -15,7 +17,7 @@ def index(): return render_template('base.html') -@app.route('/api/v1/get/') +@app.route('/api/v1/get/artist/') def get_artist(path): """ Process for the requested Artist @@ -23,10 +25,20 @@ def get_artist(path): :return: a status """ if path: - proc = process_download(path) - return {'status': 200, 'data': proc, 'artist': path} + res = process_download(path) else: - return {'status': 501} + res = {'status': 501, 'message': 'Could not process download..'} + + return res + + +@app.route('/api/v1/get/queue') +def get_queue(): + album_ids = Album.search([('downloaded', '=', False)]) + data = {'album_ids': album_ids} + print('======================') + print(data) + return render_template('download_queue.html', **data) if __name__ == "__main__": diff --git a/database.py b/database.py new file mode 100644 index 0000000..4f951ff --- /dev/null +++ b/database.py @@ -0,0 +1,84 @@ +import operator as oprtr +from pysondb import PysonDB + + +def evaluate_condition(record_field, operator, condition): + return operator(record_field, condition) + + +def evaluate_operator(op): + if op == '>': + op = oprtr.gt + elif op == '<': + op = oprtr.lt + elif op == '=': + op = oprtr.eq + elif op == '!=': + op = oprtr.ne + else: + raise UserWarning('Invalid Operator: %s' % op) + return op + + +class Model: + # TODO: Modify some of this to be wrapped into an ENV wrapper that gets loaded in when the server starts and creates + # class objects that can be manipulated easier by things like update_by_id + + def __init__(self, name): + self.env = PysonDB('/home/stonesoft/Apps/getDiscography/database/%s.json' % name) + + def _search(self, records, params): + """ + Iterate through list of condition tuples and append results to a checklist that will evaluate at the end + ex params: [('name', '=', 'John'), ('zip', '!=', '12345')] + :param params: List of tuples + :return: Record to search recordset if True + """ + filtered_record_ids =[] + for record in records: + record_id = self.env.get_by_id(record) + print('===') + print(record_id) + checklist = [] + for param in params: + field = param[0] + operator = evaluate_operator(param[1]) + condition = param[2] + checklist.append(evaluate_condition(record_id[field], operator, condition)) + + passed = all(x for x in checklist) + if passed: + filtered_record_ids.append(record_id) + + return filtered_record_ids + + def search(self, params): + """ + :param params: List of tuples that will be evaluated and return a total list of records + :return: None, List or Single record + """ + records = self.env.get_all() + record_ids = self._search(records, params) + if not record_ids: + record_ids = None + + return record_ids + + def read(self, record_id): + data = self.env.get_by_id(record_id) + return data + + def create(self, vals): + record = self.env.add(vals) + return record + + def create_many(self, record_list): + record_ids = self.env.add_many(record_list) + return record_ids + + def write(self, record_id, vals): + self.env.update_by_id(record_id, vals) + + def unlink(self, record_id): + self.env.delete_by_id(record_id) + return True diff --git a/database/album.json b/database/album.json new file mode 100644 index 0000000..4b6401d --- /dev/null +++ b/database/album.json @@ -0,0 +1,93 @@ +{ + "version": 2, + "keys": [ + "album", + "artist", + "cover", + "downloaded", + "downloading", + "link" + ], + "data": { + "199074445401889600": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_nr-vlAyokNEb25RLBNe1XHsFo9gkvu2Pg&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_nr-vlAyokNEb25RLBNe1XHsFo9gkvu2Pg/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCN-N_qMG&rs=AOn4CLBo8tjoBHrUytlN1kfqTHYVMaVA4Q&v=1686079199", + "album": "Quick Revive" + }, + "187732915376923467": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_lS0tCQXZ-1ppWJOMhaMel8GKGtnUzsvnU&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_lS0tCQXZ-1ppWJOMhaMel8GKGtnUzsvnU/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCPDOhaQG&rs=AOn4CLBa8Mmhg8B0A7ljEpCsig_bzTju0A&v=1686202224", + "album": "Winds of Paradise" + }, + "206562046422345861": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_movr4fRkYisvKvX92G_D6fWfV1umrn3hs&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_movr4fRkYisvKvX92G_D6fWfV1umrn3hs/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCIKr_6MG&rs=AOn4CLDiszLRoh4cueTcK9h20CQ3KNpeXQ&v=1686099330", + "album": "Selection:3" + }, + "321688139888393359": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_kW87DzVan7NyJ7j06XBmOHlg1WaFm38LA&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_kW87DzVan7NyJ7j06XBmOHlg1WaFm38LA/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCIDi_aMG&rs=AOn4CLA4dE1oa2TYSqb0pvfNTdK7ZSgERw&v=1686073600", + "album": "Bruh Moment (2020 Scraps)" + }, + "633598784099856320": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_n1DHIq4LZlVVBvyilCzrjxAyCmsBSRfY0&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_n1DHIq4LZlVVBvyilCzrjxAyCmsBSRfY0/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCJGzn6QG&rs=AOn4CLD_qLcb-Z1EabBDe3449f3d0mh3Cg&v=1686624657", + "album": "Yent Szn 3" + }, + "131921253377227610": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_nm2zfpc5MDyzOp2ftFqdlHBQ-L3tE2BQM&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_nm2zfpc5MDyzOp2ftFqdlHBQ-L3tE2BQM/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCIPhgaQG&rs=AOn4CLBM_1qrbE_tAOEp51oGRYQMeTkRsw&v=1686139011", + "album": "Voyager" + }, + "271867710382714948": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_kEzRY57fWs2iqQv7mg9jA8XEwdctH3vdk&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_kEzRY57fWs2iqQv7mg9jA8XEwdctH3vdk/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCLKkkaQG&rs=AOn4CLCsG_4SxEMgAp96U-dAiavg1BZggQ&v=1686393394", + "album": "Chapter III" + }, + "322585091946466973": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_nWWfDckTPSOY4nN_5bXMz1y83Qrc160sM&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_nWWfDckTPSOY4nN_5bXMz1y83Qrc160sM/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCILUmaQG&rs=AOn4CLBW1i3Fi_0G31s8k81YFjUNM6ui_w&v=1686530562", + "album": "Chapter II" + }, + "219693029017574393": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_kwpt9qeeS577nxNUo8kh2S4R_3gFFf5Ys&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_kwpt9qeeS577nxNUo8kh2S4R_3gFFf5Ys/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCJeClqQG&rs=AOn4CLD82PHRl_xq8BKF2EtuLOC2d-WStg&v=1686470935", + "album": "Chapter 1" + }, + "106299219586508927": { + "artist": "Inteus", + "downloaded": false, + "downloading": false, + "link": "/playlist?list=OLAK5uy_kA-xQTNx8Az1t4HAFQ9vB1oTWG4A5cAIQ&playnext=1&index=1", + "cover": "https://i9.ytimg.com/s_p/OLAK5uy_kA-xQTNx8Az1t4HAFQ9vB1oTWG4A5cAIQ/mqdefault.jpg?sqp=CJT0pKQGir7X7AMGCNaakaQG&rs=AOn4CLDN92pGYYBFP0Vwi5c28qE7L43K_w&v=1686392150", + "album": "Selection: 2" + } + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b29213c..671499c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ Jinja2==3.1.2 MarkupSafe==2.1.3 mutagen==1.46.0 pycryptodomex==3.18.0 +pysondb-v2==2.0.0 redis==4.5.5 requests==2.31.0 requests-file==1.5.1 diff --git a/static/css/style.css b/static/css/style.css index cd9c019..cf7a163 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -60,8 +60,16 @@ a { width: 100%; } -.page-wrapper { - padding-top: 144px; +#action_list { + float: right; + padding: 20px; + color: white; + position: fixed; + right: 0; +} + +#action_list a { + color: white; } #logo { @@ -104,11 +112,22 @@ a { width: 100%; } +.dl_queue_img { + position: relative; +} + .icn-spinner { animation: spin-animation 0.9s infinite; display: inline-block; } +.icn-downloading { + top: 50%; + left: 50%; + position: absolute; + transform: translate(-50%, -50%); +} + @keyframes spin-animation { 0% { transform: rotate(0deg); diff --git a/static/js/app.js b/static/js/app.js index fad9647..2cbba93 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1,20 +1,48 @@ +const appModal = $('#modalDownloadQueue'); +const appModalContent = $('#modal_content'); + +function proc_notification(icon, title, text) { + Swal.fire({ + title: title, + icon: icon, + text: text + }) +} + +$('.queue_btn').on('click', () => { + console.log('Get Queue!'); + $.ajax({ + url: '/api/v1/get/queue' + }).done( (res) => { + console.log(res); + appModalContent.html(res); + appModal.modal('toggle'); + }) +}) + $('#download_btn').on('click', () => { let artist = $('#search_bar').val(); // Prevent $('#search_bar').val(''); + let icon = 'error'; + let title = 'What the flip?!'; + let text = 'You need to add an artist bro..'; if (artist) { $("#loader-wrapper").fadeIn(300); $.ajax({ - url: `/api/v1/get/${artist}`, + url: `/api/v1/get/artist/${artist}`, }).done(function (res) { - console.log('---'); - console.log(res); - console.log('---'); + text = res.message; + if (res.status === 200) { + icon = 'success'; + title = 'Shazam!'; + } $("#loader-wrapper").fadeOut(700); + proc_notification(icon, title, text); }); } else { - console.log('No artist'); + proc_notification(icon, title, text); } }) \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 077c652..bfc5f5f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -15,6 +15,7 @@ +
@@ -27,6 +28,18 @@
+ +
+ + + + + + + + +
+
@@ -65,6 +78,26 @@
+ + +