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
This commit is contained in:
Omglolyes 2020-06-30 19:15:25 +02:00 committed by GitHub
parent 24df9ea4cf
commit a8b77ac37d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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))