Merge pull request #60 from radiorabe/feature/unicode-safe-podcast-downloading
Fix unicode issues in podcast downloader
This commit is contained in:
commit
f7ea88b5f0
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue