From 626e682aad9fa1ef5c5ecfaf8116536e8090c641 Mon Sep 17 00:00:00 2001 From: Robbt Date: Thu, 13 Dec 2018 12:36:10 -0500 Subject: [PATCH] changed celery podcast download to use mutagen for all supported files vs. mp3 only --- .../airtime-celery/airtime-celery/tasks.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index c25f24528..bd8e6b953 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -9,9 +9,7 @@ import posixpath import shutil import tempfile import traceback -from mutagen.mp3 import MP3 -from mutagen.easyid3 import EasyID3 -import mutagen.id3 +import mutagen from StringIO import StringIO from celery import Celery from celery.utils.log import get_task_logger @@ -155,15 +153,12 @@ def podcast_download(id, url, callback_url, api_key, podcast_name, album_overrid with tempfile.NamedTemporaryFile(mode ='wb+', delete=False) as audiofile: r.raw.decode_content = True 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)) - + metadata_audiofile = mutagen.File(audiofile.name, easy=True) + logger.debug('podcast_download loaded {0}'.format(audiofile.name)) # replace album title as needed - m = podcast_override_album(m, podcast_name, album_override) - - m.save() - filetypeinfo = m.pprint() + metadata_audiofile = podcast_override_album(metadata_audiofile, podcast_name, album_override) + metadata_audiofile.save() + filetypeinfo = metadata_audiofile.pprint() 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()