From 918cd11262a15c581d9ea88bb399955e912fe940 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 20 May 2018 17:35:32 +0200 Subject: [PATCH] Allow missing/empty tags Closes #94, closes #99 --- supysonic/scanner.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/supysonic/scanner.py b/supysonic/scanner.py index 8bef577..ac6fcff 100644 --- a/supysonic/scanner.py +++ b/supysonic/scanner.py @@ -113,27 +113,24 @@ class Scanner: return tag = self.__try_load_tag(path) - if not tag: + if tag is None: self.remove_file(path) return trdict = {} else: tag = self.__try_load_tag(path) - if not tag: + if tag is None: return trdict = { 'path': path } - artist = self.__try_read_tag(tag, 'artist') - if not artist: - return - + artist = self.__try_read_tag(tag, 'artist', '[unknown]') album = self.__try_read_tag(tag, 'album', '[non-album tracks]') albumartist = self.__try_read_tag(tag, 'albumartist', artist) trdict['disc'] = self.__try_read_tag(tag, 'discnumber', 1, lambda x: int(x[0].split('/')[0])) trdict['number'] = self.__try_read_tag(tag, 'tracknumber', 1, lambda x: int(x[0].split('/')[0])) - trdict['title'] = self.__try_read_tag(tag, 'title', '') + trdict['title'] = self.__try_read_tag(tag, 'title', os.path.basename(path)) trdict['year'] = self.__try_read_tag(tag, 'date', None, lambda x: int(x[0].split('-')[0])) trdict['genre'] = self.__try_read_tag(tag, 'genre') trdict['duration'] = int(tag.info.length) @@ -252,10 +249,10 @@ class Scanner: def __try_load_tag(self, path): try: return mutagen.File(path, easy = True) - except: + except mutagen.MutagenError: return None - def __try_read_tag(self, metadata, field, default = None, transform = lambda x: x[0]): + def __try_read_tag(self, metadata, field, default = None, transform = lambda x: x[0].strip()): try: value = metadata[field] if not value: