1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Sanitize tags a bit when readong them

Closes #133, closes #134
This commit is contained in:
spl0k 2019-02-09 15:48:16 +01:00
parent d7bbbfe383
commit 29429bbbf2

View File

@ -134,10 +134,10 @@ class Scanner:
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['disc'] = self.__try_read_tag(tag, 'discnumber', 1, lambda x: int(x.split('/')[0]))
trdict['number'] = self.__try_read_tag(tag, 'tracknumber', 1, lambda x: int(x.split('/')[0]))
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['year'] = self.__try_read_tag(tag, 'date', None, lambda x: int(x.split('-')[0]))
trdict['genre'] = self.__try_read_tag(tag, 'genre')
trdict['duration'] = int(tag.info.length)
trdict['has_art'] = bool(Track._extract_cover_art(path))
@ -299,9 +299,11 @@ class Scanner:
except mutagen.MutagenError:
return None
def __try_read_tag(self, metadata, field, default = None, transform = lambda x: x[0].strip()):
def __try_read_tag(self, metadata, field, default = None, transform = None):
try:
value = metadata[field]
value = metadata[field][0]
value = value.replace('\x00', '').strip()
if not value:
return default
if transform: