Luke Plant avatar Luke Plant committed 93aacc6

Fixed crasher when uploaded sermon has no ID3 header

Comments (0)

Files changed (1)

 import sys
 
 from mutagen.id3 import ID3, TIT2, TDRC, TPE1, TIME, COMM
-
 from sermons.models import BIBLE_BOOKS, BIBLE_NAME_TO_VAL, Speaker, Series, Topic
 
 
 def write_id3_tags(sermon):
     fname = sermon.sermon.file.name
     UTF8 = 3 # mutagen.id3 says so.
-    tags = ID3(fname)
+    try:
+        tags = ID3(fname)
+    except Exception:
+        # Could be missing or malformed header
+        tags = ID3()
+        tags.filename = fname
+
     tags.add(TIT2(encoding=UTF8, text=sermon.title))
     tags.add(TDRC(encoding=UTF8, text=
                   sermon.date_delivered.strftime('%Y-%m-%d') + ' ' +
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.