mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
parent
a7cdeb0b2d
commit
918cd11262
@ -113,27 +113,24 @@ class Scanner:
|
|||||||
return
|
return
|
||||||
|
|
||||||
tag = self.__try_load_tag(path)
|
tag = self.__try_load_tag(path)
|
||||||
if not tag:
|
if tag is None:
|
||||||
self.remove_file(path)
|
self.remove_file(path)
|
||||||
return
|
return
|
||||||
trdict = {}
|
trdict = {}
|
||||||
else:
|
else:
|
||||||
tag = self.__try_load_tag(path)
|
tag = self.__try_load_tag(path)
|
||||||
if not tag:
|
if tag is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
trdict = { 'path': path }
|
trdict = { 'path': path }
|
||||||
|
|
||||||
artist = self.__try_read_tag(tag, 'artist')
|
artist = self.__try_read_tag(tag, 'artist', '[unknown]')
|
||||||
if not artist:
|
|
||||||
return
|
|
||||||
|
|
||||||
album = self.__try_read_tag(tag, 'album', '[non-album tracks]')
|
album = self.__try_read_tag(tag, 'album', '[non-album tracks]')
|
||||||
albumartist = self.__try_read_tag(tag, 'albumartist', artist)
|
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['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['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['year'] = self.__try_read_tag(tag, 'date', None, lambda x: int(x[0].split('-')[0]))
|
||||||
trdict['genre'] = self.__try_read_tag(tag, 'genre')
|
trdict['genre'] = self.__try_read_tag(tag, 'genre')
|
||||||
trdict['duration'] = int(tag.info.length)
|
trdict['duration'] = int(tag.info.length)
|
||||||
@ -252,10 +249,10 @@ class Scanner:
|
|||||||
def __try_load_tag(self, path):
|
def __try_load_tag(self, path):
|
||||||
try:
|
try:
|
||||||
return mutagen.File(path, easy = True)
|
return mutagen.File(path, easy = True)
|
||||||
except:
|
except mutagen.MutagenError:
|
||||||
return None
|
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:
|
try:
|
||||||
value = metadata[field]
|
value = metadata[field]
|
||||||
if not value:
|
if not value:
|
||||||
|
Loading…
Reference in New Issue
Block a user