fix error in playlist import + more verbose command
This commit is contained in:
parent
1ccaf7e0da
commit
8bbeb5fe6d
|
@ -26,6 +26,7 @@ logger = logging.getLogger('aircox.tools')
|
||||||
|
|
||||||
|
|
||||||
class Importer:
|
class Importer:
|
||||||
|
path = None
|
||||||
data = None
|
data = None
|
||||||
tracks = None
|
tracks = None
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ class Importer:
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return True
|
return True
|
||||||
with open(path, 'r') as file:
|
with open(path, 'r') as file:
|
||||||
|
logger.info('start reading csv ' + path)
|
||||||
|
self.path = path
|
||||||
self.data = list(csv.DictReader(
|
self.data = list(csv.DictReader(
|
||||||
(row for row in file if not row.startswith('#')),
|
(row for row in file if not row.startswith('#')),
|
||||||
fieldnames = settings.AIRCOX_IMPORT_PLAYLIST_CSV_COLS,
|
fieldnames = settings.AIRCOX_IMPORT_PLAYLIST_CSV_COLS,
|
||||||
|
@ -58,8 +61,13 @@ class Importer:
|
||||||
maps = settings.AIRCOX_IMPORT_PLAYLIST_CSV_COLS
|
maps = settings.AIRCOX_IMPORT_PLAYLIST_CSV_COLS
|
||||||
tracks = []
|
tracks = []
|
||||||
|
|
||||||
|
logger.info('parse csv file ' + self.path)
|
||||||
in_seconds = ('minutes' or 'seconds') in maps
|
in_seconds = ('minutes' or 'seconds') in maps
|
||||||
for index, line in enumerate(self.data):
|
for index, line in enumerate(self.data):
|
||||||
|
if ('title' or 'artist') not in line:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
position = \
|
position = \
|
||||||
int(line.get('minute') or 0) * 60 + \
|
int(line.get('minute') or 0) * 60 + \
|
||||||
int(line.get('seconds') or 0) \
|
int(line.get('seconds') or 0) \
|
||||||
|
@ -78,6 +86,10 @@ class Importer:
|
||||||
tags = line.get('tags')
|
tags = line.get('tags')
|
||||||
if tags:
|
if tags:
|
||||||
track.tags.add(*tags.split(','))
|
track.tags.add(*tags.split(','))
|
||||||
|
except:
|
||||||
|
logger.warning('an error occured for track {index}, it may not '
|
||||||
|
'have been saved'.format(index = index))
|
||||||
|
continue
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
track.save()
|
track.save()
|
||||||
|
|
|
@ -1004,12 +1004,15 @@ class Sound(Nameable):
|
||||||
except:
|
except:
|
||||||
meta = {}
|
meta = {}
|
||||||
|
|
||||||
|
if meta is None:
|
||||||
|
meta = {}
|
||||||
|
|
||||||
def get_meta(key, cast=str):
|
def get_meta(key, cast=str):
|
||||||
value = meta.get(key)
|
value = meta.get(key)
|
||||||
return cast(value[0]) if value else None
|
return cast(value[0]) if value else None
|
||||||
|
|
||||||
info = '{} ({})'.format(get_meta('album'), get_meta('year')) \
|
info = '{} ({})'.format(get_meta('album'), get_meta('year')) \
|
||||||
if 'album' and 'year' in meta else \
|
if meta and ('album' and 'year' in meta) else \
|
||||||
get_meta('album') \
|
get_meta('album') \
|
||||||
if 'album' else \
|
if 'album' else \
|
||||||
('year' in meta) and get_meta('year') or ''
|
('year' in meta) and get_meta('year') or ''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user