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.
This commit is contained in:
parent
77ebfa93d3
commit
0cb5e2665e
|
@ -8,6 +8,7 @@ import urlparse
|
||||||
import posixpath
|
import posixpath
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import traceback
|
||||||
from mutagen.mp3 import MP3
|
from mutagen.mp3 import MP3
|
||||||
from mutagen.easyid3 import EasyID3
|
from mutagen.easyid3 import EasyID3
|
||||||
import mutagen.id3
|
import mutagen.id3
|
||||||
|
@ -154,13 +155,15 @@ def podcast_download(id, url, callback_url, api_key, podcast_name):
|
||||||
shutil.copyfileobj(r.raw, audiofile)
|
shutil.copyfileobj(r.raw, audiofile)
|
||||||
# currently hardcoded for mp3s may want to add support for oggs etc
|
# currently hardcoded for mp3s may want to add support for oggs etc
|
||||||
m = MP3(audiofile.name, ID3=EasyID3)
|
m = MP3(audiofile.name, ID3=EasyID3)
|
||||||
|
logger.debug('podcast_download loaded mp3 {0}'.format(audiofile.name))
|
||||||
try:
|
try:
|
||||||
m['album']
|
m['album']
|
||||||
except KeyError:
|
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()
|
m.save()
|
||||||
filetypeinfo = m.pprint()
|
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 = requests.post(callback_url, files={'file': (filename, open(audiofile.name, 'rb'))}, auth=requests.auth.HTTPBasicAuth(api_key, ''))
|
||||||
re.raise_for_status()
|
re.raise_for_status()
|
||||||
f = json.loads(re.content) # Read the response from the media API to get the file id
|
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
|
obj['status'] = 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
obj['error'] = e.message
|
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
|
obj['status'] = 0
|
||||||
return json.dumps(obj)
|
return json.dumps(obj)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue