This project is designed to retrieve all genres from a user's saved tracks on Spotify and map them to broader, general genres. It then counts the number of tracks in each general genre and displays the results.
-
Retrieves Saved Tracks: The code connects to the Spotify API and fetches the user's saved tracks in batches of 50.
-
Maps Specific Genres to General Genres: Using a predefined mapping, the code categorizes specific Spotify genres into broader general genres (e.g., "dance pop" becomes "Pop").
-
Counts Tracks by Genre: The code counts the number of tracks in each general genre and outputs these counts.
-
Environment Setup: The script requires Spotify API credentials to authenticate and fetch data from the user's library.
-
Python: Make sure Python is installed on your system. You can download it from Python's official website.
-
bashCopiar códigopip install spotipy
-
Spotify Developer Account: You need a Spotify Developer account to obtain API credentials. Sign up at Spotify Developer.
-
You can get these by creating an application in the Spotify Developer Dashboard.
-
Client ID
-
Client Secret
-
Redirect URI
-
-
Environment Variables: The script requires environment variables to securely store your Spotify API credentials.
Set up the following environment variables on your system:
-
SPOTIFY_CLIENT_ID: Your Spotify API client ID.
-
SPOTIFY_CLIENT_SECRET: Your Spotify API client secret.
-
SPOTIFY_REDIRECT_URI: Your Spotify API redirect URI.
-
Spotipy Documentation: Documentation for the Spotipy library used to interact with the Spotify API.
-
Spotify Developer API: Official documentation for the Spotify Web API, used for fetching user data and managing playlists.
49E4
ul>