updated inline playlist sorting

This commit is contained in:
aj 2019-09-24 10:34:02 +01:00
parent 08d23872c4
commit 933e70ee44
2 changed files with 5 additions and 9 deletions

View File

@ -33,14 +33,7 @@ def go(playlist_name):
os.environ['SPOTREFRESH'])) os.environ['SPOTREFRESH']))
engine = PlaylistEngine(net) engine = PlaylistEngine(net)
engine.load_user_playlists() engine.reorder_playlist_by_added_date(playlist_name)
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')
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -133,6 +133,9 @@ class PlaylistEngine:
logger.error('playlist not found') logger.error('playlist not found')
return None return None
if playlist.has_tracks() is False:
playlist_source.get_playlist_tracks(playlist)
tracks_to_sort = list(playlist.tracks) tracks_to_sort = list(playlist.tracks)
for i in range(len(playlist)): for i in range(len(playlist)):
counter_track = tracks_to_sort[0] counter_track = tracks_to_sort[0]
@ -145,7 +148,7 @@ class PlaylistEngine:
counter_track = track counter_track = track
if counter_track != tracks_to_sort[0]: 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), i + tracks_to_sort.index(counter_track),
1, i) 1, i)
tracks_to_sort.remove(counter_track) tracks_to_sort.remove(counter_track)