Merge pull request #60 from radiorabe/feature/unicode-safe-podcast-downloading

Fix unicode issues in podcast downloader
This commit is contained in:
Robb 2017-03-11 19:14:23 -05:00 committed by GitHub
commit f7ea88b5f0
1 changed files with 7 additions and 3 deletions

View File

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