def remove_playlist_duplicates(client: Client, playlist_name='VK2YA') -> Playlist: echo.c(f'Removing duplicates from playlist: {playlist_name}') p = create_playlist(client, playlist_name) unique_tracks = set() while len(p.tracks) != len(unique_tracks): was_len = len(p.tracks) unique_tracks = set() for i, t in enumerate(p.tracks): if t.id in unique_tracks: echo.y(f'Duplicate found: {t.track.artists[0].name} - {t.track.title}, removing') client.users_playlists_delete_track(p.kind, i, i+1, revision=p.revision) p = create_playlist(client, playlist_name) break unique_tracks.add(t.id) if was_len == len(p.tracks): break # recurse
def clear_playlist(client: Client, name='VK2YA'): echo.y(f'Clearing playlist: {name}') p = create_playlist(client, name) client.users_playlists_delete_track(p.kind, 0, p.track_count, revision=p.revision)