From ece97b41c767a535c42ac221fa9b5caf37c6739c Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sun, 6 Jul 2008 04:21:17 -0400 Subject: [PATCH] Tighter AudioFileFilter(). (Extension comparison is actually all that eyeD3.isMp3File() does, so we can save some steps here.) --- plugins/music/music.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/plugins/music/music.py b/plugins/music/music.py index 26b6098..9693b08 100644 --- a/plugins/music/music.py +++ b/plugins/music/music.py @@ -143,31 +143,20 @@ class Music(Plugin): def QueryContainer(self, handler, query): def AudioFileFilter(f, filter_type=None): + ext = os.path.splitext(f)[1].lower() - if filter_type: - filter_start = filter_type.split('/')[0] + if ext in ('.mp3', '.mp2') or ext in TRANSCODE: + return self.AUDIO else: - filter_start = filter_type + file_type = False - if os.path.isdir(f): - ftype = self.DIRECTORY + if not filter_type or filter_type.split('/')[0] != self.AUDIO: + if ext in PLAYLISTS: + file_type = self.PLAYLIST + elif os.path.isdir(f): + file_type = self.DIRECTORY - elif eyeD3.isMp3File(f): - ftype = self.AUDIO - elif os.path.splitext(f)[1].lower() in PLAYLISTS: - ftype = self.PLAYLIST - elif os.path.splitext(f)[1].lower() in TRANSCODE: - ftype = self.AUDIO - else: - ftype = False - - if filter_start == self.AUDIO: - if ftype == self.AUDIO: - return ftype - else: - return False - else: - return ftype + return file_type def media_data(f): if f.name in self.media_data_cache: -- 2.11.4.GIT