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?)
This commit is contained in:
Xevion
2019-12-24 22:49:00 -06:00
parent 88b7884e55
commit a86e0a7185
2 changed files with 3 additions and 2 deletions

View File

@@ -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':

View File

@@ -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