From 0cb5e2665ed95108fce770fc6ae7957c63d67eb1 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sat, 11 Mar 2017 21:01:52 +0100 Subject: [PATCH] Fix unicode issues in podcast downloader The podcast downloader fails pretty badly when the podcast name contains non ascii chars. The main fail happens during logging; I have learnt way to much about pythons stupid unicode implementation. This adds addtional debug logging and also outputs the real reason a download fails properly. The content of the tags should be written as UTF-8 or whater is input into it, this commit mainly touches (and fixes) logging. --- python_apps/airtime-celery/airtime-celery/tasks.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index 2a8474c7b..d838b54b6 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -8,6 +8,7 @@ import urlparse import posixpath import shutil import tempfile +import traceback from mutagen.mp3 import MP3 from mutagen.easyid3 import EasyID3 import mutagen.id3 @@ -154,13 +155,15 @@ def podcast_download(id, url, callback_url, api_key, podcast_name): shutil.copyfileobj(r.raw, audiofile) # currently hardcoded for mp3s may want to add support for oggs etc m = MP3(audiofile.name, ID3=EasyID3) + logger.debug('podcast_download loaded mp3 {0}'.format(audiofile.name)) try: m['album'] except KeyError: - m['album'] = [podcast_name] + logger.debug('setting new album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore'))) + m['album'] = podcast_name m.save() filetypeinfo = m.pprint() - logger.info('filetypeinfo is {0}'.format(filetypeinfo)) + logger.info('filetypeinfo is {0}'.format(filetypeinfo.encode('ascii', 'ignore'))) re = requests.post(callback_url, files={'file': (filename, open(audiofile.name, 'rb'))}, auth=requests.auth.HTTPBasicAuth(api_key, '')) re.raise_for_status() f = json.loads(re.content) # Read the response from the media API to get the file id @@ -168,7 +171,8 @@ def podcast_download(id, url, callback_url, api_key, podcast_name): obj['status'] = 1 except Exception as e: obj['error'] = e.message - logger.info('Error during file download: {0}'.format(e.message)) + logger.info('Error during file download: {0}'.format(e)) + logger.debug('Original Traceback: %s' % (traceback.format_exc(e))) obj['status'] = 0 return json.dumps(obj)