Skip to content

Instantly share code, notes, and snippets.

@Syzygianinfern0
Created October 29, 2022 23:32
Show Gist options
  • Save Syzygianinfern0/a87ce0988b797d92bf5cb0f74926ebfe to your computer and use it in GitHub Desktop.
Save Syzygianinfern0/a87ce0988b797d92bf5cb0f74926ebfe to your computer and use it in GitHub Desktop.
Sort Spotify Playlists by Followers/Likes
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
sp = spotipy.Spotify(
auth_manager=SpotifyClientCredentials(
client_id="",
client_secret="",
),
)
results = sp.search("lofi", 20, type="playlist")["playlists"]["items"]
likes = {playlist["id"]: sp.playlist(playlist["id"])["followers"]["total"] for playlist in results}
sorted_results = sorted(results, key=lambda playlist: likes[playlist["id"]], reverse=True)
for result in sorted_results:
print(f"{result['name'][:30]:<30}\t{likes[result['id']]:<10}\t{result['external_urls']['spotify']:>}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment