handling for no uri, compacted csv code
This commit is contained in:
parent
f868d1425a
commit
2863525767
@ -22,17 +22,13 @@ def export_playlist(playlist, path, name=None):
|
|||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
|
|
||||||
for track in playlist.tracks:
|
for track in playlist.tracks:
|
||||||
|
writer.writerow({
|
||||||
trackdict = {
|
|
||||||
'name': track.name,
|
'name': track.name,
|
||||||
'album': track.album.name,
|
'album': track.album.name,
|
||||||
'added': track.added_at,
|
'added': track.added_at,
|
||||||
'track id':track.spotify_id,
|
'track id': track.uri.object_id if track.uri is not None else 'none',
|
||||||
'album id':track.album.spotify_id,
|
'album id': track.album.uri.object_id if track.album.uri is not None else 'none',
|
||||||
'added by':track.added_by.username}
|
'added by': track.added_by.username,
|
||||||
|
'album artist': ', '.join(x.name for x in track.album.artists),
|
||||||
trackdict['album artist'] = ', '.join(x.name for x in track.album.artists)
|
'artist': ', '.join(x.name for x in track.artists)
|
||||||
|
})
|
||||||
trackdict['artist'] = ', '.join(x.name for x in track.artists)
|
|
||||||
|
|
||||||
writer.writerow(trackdict)
|
|
||||||
|
@ -69,6 +69,7 @@ class SpotifyAlbum(Album):
|
|||||||
else:
|
else:
|
||||||
self.uri = uri
|
self.uri = uri
|
||||||
|
|
||||||
|
if self.uri:
|
||||||
if self.uri.object_type != Uri.ObjectType.album:
|
if self.uri.object_type != Uri.ObjectType.album:
|
||||||
raise TypeError('provided uri not for an album')
|
raise TypeError('provided uri not for an album')
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ class SpotifyArtist(Artist):
|
|||||||
else:
|
else:
|
||||||
self.uri = uri
|
self.uri = uri
|
||||||
|
|
||||||
|
if self.uri:
|
||||||
if self.uri.object_type != Uri.ObjectType.artist:
|
if self.uri.object_type != Uri.ObjectType.artist:
|
||||||
raise TypeError('provided uri not for an artist')
|
raise TypeError('provided uri not for an artist')
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ class Uri:
|
|||||||
self.object_type = None
|
self.object_type = None
|
||||||
self.object_id = None
|
self.object_id = None
|
||||||
self.username = None
|
self.username = None
|
||||||
|
self.is_local = False
|
||||||
|
|
||||||
parts = input_string.split(':')
|
parts = input_string.split(':')
|
||||||
|
|
||||||
@ -28,6 +29,12 @@ class Uri:
|
|||||||
raise ValueError('malformed uri')
|
raise ValueError('malformed uri')
|
||||||
self.object_type = self.ObjectType[parts[3]]
|
self.object_type = self.ObjectType[parts[3]]
|
||||||
self.object_id = parts[4]
|
self.object_id = parts[4]
|
||||||
|
elif len(parts) == 6:
|
||||||
|
if parts[1] == 'local':
|
||||||
|
self.object_type = self.ObjectType.track
|
||||||
|
self.is_local = True
|
||||||
|
else:
|
||||||
|
raise ValueError(f'malformed uri: {len(parts)} parts')
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'malformed uri: {len(parts)} parts')
|
raise ValueError(f'malformed uri: {len(parts)} parts')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user