diff --git a/sort_playlist.py b/sort_playlist.py index 29410c0..da84841 100644 --- a/sort_playlist.py +++ b/sort_playlist.py @@ -33,14 +33,7 @@ def go(playlist_name): os.environ['SPOTREFRESH'])) engine = PlaylistEngine(net) - engine.load_user_playlists() - playlist = next((j for j in engine.playlists if j.name == playlist_name), None) - - if playlist is not None: - engine.get_playlist_tracks(playlist) - engine.reorder_playlist_by_added_date(playlist_name) - else: - logger.error('playlist not found') + engine.reorder_playlist_by_added_date(playlist_name) if __name__ == '__main__': diff --git a/spotframework/engine/playlistengine.py b/spotframework/engine/playlistengine.py index c067cce..fb6ddf4 100644 --- a/spotframework/engine/playlistengine.py +++ b/spotframework/engine/playlistengine.py @@ -133,6 +133,9 @@ class PlaylistEngine: logger.error('playlist not found') return None + if playlist.has_tracks() is False: + playlist_source.get_playlist_tracks(playlist) + tracks_to_sort = list(playlist.tracks) for i in range(len(playlist)): counter_track = tracks_to_sort[0] @@ -145,7 +148,7 @@ class PlaylistEngine: counter_track = track if counter_track != tracks_to_sort[0]: - self.net.reorder_playlist_tracks(playlist.playlist_id, + self.net.reorder_playlist_tracks(playlist.uri, i + tracks_to_sort.index(counter_track), 1, i) tracks_to_sort.remove(counter_track)