diff --git a/spotframework/io/csv.py b/spotframework/io/csv.py index a1f0fda..9ed3435 100644 --- a/spotframework/io/csv.py +++ b/spotframework/io/csv.py @@ -22,17 +22,13 @@ def export_playlist(playlist, path, name=None): writer.writeheader() for track in playlist.tracks: - - trackdict = { - 'name':track.name, - 'album':track.album.name, - 'added':track.added_at, - 'track id':track.spotify_id, - 'album id':track.album.spotify_id, - 'added by':track.added_by.username} - - trackdict['album artist'] = ', '.join(x.name for x in track.album.artists) - - trackdict['artist'] = ', '.join(x.name for x in track.artists) - - writer.writerow(trackdict) + writer.writerow({ + 'name': track.name, + 'album': track.album.name, + 'added': track.added_at, + 'track id': track.uri.object_id if track.uri is not None else 'none', + 'album id': track.album.uri.object_id if track.album.uri is not None else 'none', + 'added by': track.added_by.username, + 'album artist': ', '.join(x.name for x in track.album.artists), + 'artist': ', '.join(x.name for x in track.artists) + }) diff --git a/spotframework/model/album.py b/spotframework/model/album.py index ccdbcb1..577b387 100644 --- a/spotframework/model/album.py +++ b/spotframework/model/album.py @@ -69,8 +69,9 @@ class SpotifyAlbum(Album): else: self.uri = uri - if self.uri.object_type != Uri.ObjectType.album: - raise TypeError('provided uri not for an album') + if self.uri: + if self.uri.object_type != Uri.ObjectType.album: + raise TypeError('provided uri not for an album') self.genres = genres diff --git a/spotframework/model/artist.py b/spotframework/model/artist.py index db9c51c..e4d1c6e 100644 --- a/spotframework/model/artist.py +++ b/spotframework/model/artist.py @@ -34,8 +34,9 @@ class SpotifyArtist(Artist): else: self.uri = uri - if self.uri.object_type != Uri.ObjectType.artist: - raise TypeError('provided uri not for an artist') + if self.uri: + if self.uri.object_type != Uri.ObjectType.artist: + raise TypeError('provided uri not for an artist') self.genres = genres diff --git a/spotframework/model/uri.py b/spotframework/model/uri.py index e26201d..2698d01 100644 --- a/spotframework/model/uri.py +++ b/spotframework/model/uri.py @@ -14,6 +14,7 @@ class Uri: self.object_type = None self.object_id = None self.username = None + self.is_local = False parts = input_string.split(':') @@ -28,6 +29,12 @@ class Uri: raise ValueError('malformed uri') self.object_type = self.ObjectType[parts[3]] 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: raise ValueError(f'malformed uri: {len(parts)} parts')