From 5f6b8e012d6e9d6bb50ad6245398e2ef2dfa7a8a Mon Sep 17 00:00:00 2001 From: William McBrine Date: Tue, 16 Feb 2010 02:53:44 -0500 Subject: [PATCH] Skip trying to extract data from "audioFile" when mutagen fails. --- plugins/music/music.py | 53 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/plugins/music/music.py b/plugins/music/music.py index 909a6dc..904248a 100644 --- a/plugins/music/music.py +++ b/plugins/music/music.py @@ -195,32 +195,33 @@ class Music(Plugin): # Otherwise, let mutagen figure it out audioFile = mutagen.File(fname) - # Pull the length from the FileType, if present - if audioFile.info.length > 0: - item['Duration'] = int(audioFile.info.length * 1000) - - # Grab our other tags, if present - def get_tag(tagname, d): - for tag in ([tagname] + TAGNAMES[tagname]): - try: - if tag in d: - value = d[tag][0] - if type(value) not in [str, unicode]: - value = str(value) - return value - except: - pass - return '' - - artist = get_tag('artist', audioFile) - title = get_tag('title', audioFile) - if artist == 'Various Artists' and '/' in title: - artist, title = [x.strip() for x in title.split('/')] - item['ArtistName'] = artist - item['SongTitle'] = title - item['AlbumTitle'] = get_tag('album', audioFile) - item['AlbumYear'] = get_tag('date', audioFile) - item['MusicGenre'] = get_tag('genre', audioFile) + if audioFile: + # Pull the length from the FileType, if present + if audioFile.info.length > 0: + item['Duration'] = int(audioFile.info.length * 1000) + + # Grab our other tags, if present + def get_tag(tagname, d): + for tag in ([tagname] + TAGNAMES[tagname]): + try: + if tag in d: + value = d[tag][0] + if type(value) not in [str, unicode]: + value = str(value) + return value + except: + pass + return '' + + artist = get_tag('artist', audioFile) + title = get_tag('title', audioFile) + if artist == 'Various Artists' and '/' in title: + artist, title = [x.strip() for x in title.split('/')] + item['ArtistName'] = artist + item['SongTitle'] = title + item['AlbumTitle'] = get_tag('album', audioFile) + item['AlbumYear'] = get_tag('date', audioFile) + item['MusicGenre'] = get_tag('genre', audioFile) except Exception, msg: print msg -- 2.11.4.GIT