From a86e0a718590048c9700d5407721fd1e374bf3a8 Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 24 Dec 2019 22:49:00 -0600 Subject: [PATCH] remove decode, proper return application/json mimetype, fix url being null should have put in the url filling a long time ago, I just didn't wanna open up the massive JSON response and locate the key required. also, with this I'll have to clear the databases with new URLs (or maybe I should refresh all metadata?) --- app/sound.py | 2 +- app/sound_models.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/sound.py b/app/sound.py index 0af5906..ded6498 100644 --- a/app/sound.py +++ b/app/sound.py @@ -60,7 +60,7 @@ def status(service, mediaid): else: return Response('Invalid ID', status=400, mimetype='text/plain') else: - return Response(audio.toJSON(), status=200, mimetype='text/plain') + return Response(audio.toJSON(), status=200, mimetype='application/json') elif service == 'soundcloud': return Response('Not implemented', status=501, mimetype='text/plain') elif service == 'spotify': diff --git a/app/sound_models.py b/app/sound_models.py index 5e86475..6006aed 100644 --- a/app/sound_models.py +++ b/app/sound_models.py @@ -39,9 +39,10 @@ class YouTubeAudio(db.Model): print(f'Filename acquired for {self.id}') processJSON = subprocess.Popen(f'youtube-dl -4 -x --audio-format mp3 --restrict-filenames --dump-json {self.id}'.split(' '), encoding='utf-8', stdout=subprocess.PIPE) - data = json.loads(processJSON.communicate()[0].decode()) + data = json.loads(processJSON.communicate()[0]) print(f'JSON acquired for {self.id}, beginning to fill.') self.duration = data['duration'] + self.url = data['webpage_url'] # Could be created, but we'll just infer from JSON response self.creator = data['creator'] or data['uploader'] self.uploader = data['uploader'] or data['creator'] self.title = data['title'] or data['alt_title'] # Do not trust alt-title ; it is volatile and uploader set, e.x. https://i.imgur.com/Tgff4rI.png