find_playlist was not called under some circonstances

This commit is contained in:
bkfox
2022-05-21 14:48:04 +02:00
parent 428903acfd
commit f92aa8d1b2
3 changed files with 35 additions and 16 deletions

View File

@ -105,8 +105,9 @@ class SoundFile:
self.find_episode(program)
sound.save()
if self.info is not None:
self.find_playlist(sound)
# check for playlist
self.find_playlist(sound)
return sound
def read_path(self):
@ -175,12 +176,12 @@ class SoundFile:
"""
if sound is None:
sound = self.sound
if sound.track_set.count():
if sound.track_set.count() > 1:
return
# import playlist
path = os.path.splitext(self.sound.file.path)[0] + '.csv'
path_noext, ext = os.path.splitext(self.sound.file.path)
path = path_noext + '.csv'
if os.path.exists(path):
PlaylistImport(path, sound=sound).run()
# use metadata
@ -189,14 +190,18 @@ class SoundFile:
self.read_file_info()
if self.info.tags:
tags = self.info.tags
info = '{} ({})'.format(tags.get('album'), tags.get('year')) \
if ('album' and 'year' in tags) else tags.get('album') \
if 'album' in tags else tags.get('year', '')
title, artist, album, year = tuple(
t and ', '.join(t) for t in (
tags.get(k) for k in ('title', 'artist', 'album', 'year'))
)
title = title or (self.path_info and self.path_info.get('name')) or \
os.path.basename(path_noext)
info = '{} ({})'.format(album, year) if album and year else \
album or year or ''
track = Track(sound=sound,
position=int(tags.get('tracknumber', 0)),
title=tags.get('title', self.path_info['name']),
artist=tags.get('artist', _('unknown')),
title=title,
artist=artist or _('unknown'),
info=info)
track.save()