Skip to content

Instantly share code, notes, and snippets.

@grafuls
Created April 24, 2016 16:46
Show Gist options
  • Select an option

  • Save grafuls/70813734af244537db545cbd47d7aa09 to your computer and use it in GitHub Desktop.

Select an option

Save grafuls/70813734af244537db545cbd47d7aa09 to your computer and use it in GitHub Desktop.
Find spotify duplicate songs in one playlist
'''
export SPOTIPY_REDIRECT_URI='http://localhost:8888/callback'
export SPOTIPY_CLIENT_ID={API_CLIENT_ID}
export SPOTIPY_CLIENT_SECRET={API_CLIENT_SECRET}
'''
import collections
import math
import spotipy
import spotipy.util as util
USER = {spotify_username}
SCOPE = 'playlist-modify-public'
PLAYLIST_ID = {spotify_uri_playlist_id}
token = util.prompt_for_user_token(USER, SCOPE)
sp = spotipy.Spotify(auth=token)
total = sp.user_playlist_tracks(USER, PLAYLIST_ID)['total']
offsets = int(math.ceil(float(total)/100))
results = []
for offset in xrange(offsets):
result = sp.user_playlist_tracks(USER, PLAYLIST_ID, offset=offset*100)
tracks = result['items']
track_names = [track['track']['name'] for track in tracks]
track_artist = [track['track']['artists'][0]['name'] for track in tracks]
results += zip(track_names, track_artist)
print [item for item, count in collections.Counter(results).items() if count > 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment