mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
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:
parent
24df9ea4cf
commit
a8b77ac37d
30
examples/playlist_all_non_local_tracks.py
Normal file
30
examples/playlist_all_non_local_tracks.py
Normal 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))
|
||||||
Loading…
Reference in New Issue
Block a user