From 26fad97915e35a1565f581ba30cd7e1d6e41b267 Mon Sep 17 00:00:00 2001 From: Robbt Date: Thu, 27 Dec 2018 17:50:33 -0500 Subject: [PATCH 1/2] modified the code to treat a file mutagen fails to load as a mp3 --- python_apps/airtime-celery/airtime-celery/tasks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index 3b06e89e5..30f594d67 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -153,8 +153,14 @@ 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) + # mutagen should be able to guess the write file type metadata_audiofile = mutagen.File(audiofile.name, easy=True) - # replace album title as needed + # if for some reason this should fail lets try it as a mp3 specific code + if metadata_audiofile == None: + logger.info('got a blank from mutagen') + metadata_audiofile = mutagen.mp3.MP3(audiofile.name, ID3=mutagen.easyid3.EasyID3) + logger.info('made a mp3') + #replace album title as needed metadata_audiofile = podcast_override_album(metadata_audiofile, podcast_name, album_override) metadata_audiofile.save() filetypeinfo = metadata_audiofile.pprint() From 28d2b110c224ac2423bdffdd422c9122d7792f36 Mon Sep 17 00:00:00 2001 From: Robbt Date: Thu, 27 Dec 2018 18:38:17 -0500 Subject: [PATCH 2/2] made basic sanity checks to only do back up mp3 mutagen import on files with mp3 extension --- python_apps/airtime-celery/airtime-celery/tasks.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index 30f594d67..4a203cbf0 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -157,9 +157,11 @@ def podcast_download(id, url, callback_url, api_key, podcast_name, album_overrid metadata_audiofile = mutagen.File(audiofile.name, easy=True) # if for some reason this should fail lets try it as a mp3 specific code if metadata_audiofile == None: - logger.info('got a blank from mutagen') - metadata_audiofile = mutagen.mp3.MP3(audiofile.name, ID3=mutagen.easyid3.EasyID3) - logger.info('made a mp3') + # if this happens then mutagen couldn't guess what type of file it is + mp3suffix = ("mp3", "MP3", "Mp3", "mP3") + # so we treat it like a mp3 if it has a mp3 file extension and hope for the best + if filename.endswith(mp3suffix): + metadata_audiofile = mutagen.mp3.MP3(audiofile.name, ID3=mutagen.easyid3.EasyID3) #replace album title as needed metadata_audiofile = podcast_override_album(metadata_audiofile, podcast_name, album_override) metadata_audiofile.save()