From a8b77ac37d686b6e203dd9c2f657eeb34f620d5b Mon Sep 17 00:00:00 2001 From: Omglolyes <58954125+Omglolyes@users.noreply.github.com> Date: Tue, 30 Jun 2020 19:15:25 +0200 Subject: [PATCH] Get all non-local tracks from a spotify playlist (#518) * Create playlist_all_tracks.py * Update playlist_all_tracks.py forgot first items from playlist * print result instead of returning it * rename to playlist_all_non_local_tracks * Update playlist_all_non_local_tracks.py removed "== True" as it's implied give an example playlist (global top 50) more comments corrected typo * print only length and excluding instead of entire result --- examples/playlist_all_non_local_tracks.py | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/playlist_all_non_local_tracks.py diff --git a/examples/playlist_all_non_local_tracks.py b/examples/playlist_all_non_local_tracks.py new file mode 100644 index 0000000..81ca47b --- /dev/null +++ b/examples/playlist_all_non_local_tracks.py @@ -0,0 +1,30 @@ +# get all non-local tracks of a playlist +from spotipy.oauth2 import SpotifyClientCredentials +import spotipy + +# playlist id of global top 50 +PlaylistExample = '37i9dQZEVXbMDoHDwVN2tF' + +# create spotipy client +sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) + +# load the first 100 songs +tracks = [] +result = sp.playlist_tracks(PlaylistExample) +tracks.extend(result['items']) + +# if playlist is larger than 100 songs, continue loading it until end +while result['next']: + result = sp.next(result) + tracks.extend(result['items']) + +# remove all local songs +i = 0 # just for counting how many tracks are local +for item in tracks: + if item['is_local']: + tracks.remove(item) + i += 1 + + +# print result +print("Playlist length: " + str(len(tracks)) + "\nExcluding: " + str(i))