Created
October 29, 2022 23:32
-
-
Save Syzygianinfern0/a87ce0988b797d92bf5cb0f74926ebfe to your computer and use it in GitHub Desktop.
Sort Spotify Playlists by Followers/Likes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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