mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-10-11 01:10:45 +00:00
Update Playlist Endpoints and Add Following Endpoints (#531)
* Update playlist endpoints to modern format Deprecate user_playlist_* in favor of the following replacements: * user_playlist_change_details -> playlist_change_details * user_playlist_unfollow -> current_user_unfollow_playlist * user_playlist_add_tracks -> playlist_add_tracks * user_playlist_replace_tracks -> playlist_replace_tracks * user_playlist_reorder_tracks -> playlist_reorder_tracks * user_playlist_remove_all_occurrences_of_tracks -> playlist_remove_all_occurrences_of_tracks * user_playlist_remove_specific_occurrences_of_tracks -> playlist_remove_specific_occurrences_of_tracks * user_playlist_follow_playlist -> current_user_follow_playlist * user_playlist_is_following -> playlist_is_following * Add current_user_following_artists and current_user_following_users * Update tests and examples Resolve TODO in test_user_endpoints.py > SpotifyFollowApiTests.test_user_follows_and_unfollows_user Use modern playlist endpoints (no username required) in tests and examples. * Update changelog * Deprecate playlist_tracks in favor of playlist_items * Link deprecated functions to new functions and change tracks to items * Fix references to playlist_tracks * Change test_playlist_add_items as requested
This commit is contained in:
1 parent
cc5e234a28
commit
88cf75b778
10 files changed
+361
-117
No files matched your search
@@ -22,8 +22,7 @@ def main():
|
||||
args = get_args()
|
||||
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
user_id = sp.me()['id']
|
||||
sp.user_playlist_add_tracks(user_id, args.playlist, args.tids)
|
||||
sp.playlist_add_items(args.playlist, args.tids)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -35,8 +35,7 @@ def get_args():
|
||||
def main():
|
||||
args = get_args()
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
sp.user_playlist_change_details(
|
||||
args.username,
|
||||
sp.playlist_change_details(
|
||||
args.playlist,
|
||||
name=args.name,
|
||||
public=args.public or args.private,
|
||||
|
||||
@@ -10,20 +10,20 @@ sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
|
||||
|
||||
# load the first 100 songs
|
||||
tracks = []
|
||||
result = sp.playlist_tracks(PlaylistExample)
|
||||
result = sp.playlist_items(PlaylistExample, additional_types=['track'])
|
||||
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'])
|
||||
result = sp.next(result)
|
||||
tracks.extend(result['items'])
|
||||
|
||||
# remove all local songs
|
||||
i = 0 # just for counting how many tracks are local
|
||||
i = 0 # just for counting how many tracks are local
|
||||
for item in tracks:
|
||||
if item['is_local']:
|
||||
tracks.remove(item)
|
||||
i += 1
|
||||
if item['is_local']:
|
||||
tracks.remove(item)
|
||||
i += 1
|
||||
|
||||
|
||||
# print result
|
||||
|
||||
@@ -8,9 +8,10 @@ pl_id = 'spotify:playlist:5RIbzhG2QqdkaP24iXLnZX'
|
||||
offset = 0
|
||||
|
||||
while True:
|
||||
response = sp.playlist_tracks(pl_id,
|
||||
offset=offset,
|
||||
fields='items.track.id,total')
|
||||
response = sp.playlist_items(pl_id,
|
||||
offset=offset,
|
||||
fields='items.track.id,total',
|
||||
additional_types=['track'])
|
||||
pprint(response['items'])
|
||||
offset = offset + len(response['items'])
|
||||
print(offset, "/", response['total'])
|
||||
|
||||
@@ -22,8 +22,6 @@ else:
|
||||
scope = 'playlist-modify-public'
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
user_id = sp.me()['id']
|
||||
|
||||
results = sp.user_playlist_remove_specific_occurrences_of_tracks(
|
||||
user_id, playlist_id, track_ids)
|
||||
results = sp.playlist_remove_specific_occurrences_of_items(
|
||||
playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
@@ -17,8 +17,6 @@ scope = 'playlist-modify-public'
|
||||
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
user_id = sp.me()['id']
|
||||
|
||||
results = sp.user_playlist_remove_all_occurrences_of_tracks(
|
||||
user_id, playlist_id, track_ids)
|
||||
results = sp.playlist_remove_all_occurrences_of_items(
|
||||
playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
@@ -16,8 +16,6 @@ else:
|
||||
scope = 'playlist-modify-public'
|
||||
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
user_id = sp.me()['id']
|
||||
|
||||
results = sp.user_playlist_replace_tracks(user_id, playlist_id, track_ids)
|
||||
results = sp.playlist_replace_items(playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
|
||||
Reference in new issue
Block a user