Created
April 24, 2016 16:46
-
-
Save grafuls/70813734af244537db545cbd47d7aa09 to your computer and use it in GitHub Desktop.
Find spotify duplicate songs in one playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 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