This script removes songs of a certain language from an existing playlist by creating a new one without it. It uses the Spotify API to access playlists and track information, the Genius API to fetch song lyrics, and the langdetect
library to determine the language of the lyrics.
- Fetches songs from a specified Spotify playlist.
- Retrieves lyrics for each song using the Genius API.
- Detects the language of the lyrics.
- Filters songs based on a specified language code.
- Creates a new Spotify playlist with only the songs that match the desired language.
- Caches lyrics language detection results to minimize redundant API calls.
- Uses parallel processing to speed up lyrics fetching and analysis.
- Python 3.6 or higher (Might work on 3.6 or below, I never tested ¯_(ツ)_/¯)
- Spotify Developer Account
- Genius API Token
- Go to the Spotify Developer Dashboard.
- Log in with your Spotify account or create a new one if necessary.
- Click "Create an App". Provide an app name and description, then agree to the terms.
- Note the
Client ID
andClient Secret
.
- Visit the Genius API clients page.
- Sign in with your Genius account or create one.
- Create a new API client. Note the
Client Access Token
.
-
Download Filter.py:
Download Filter.py from latest release.
-
Install dependencies:
Filter.py checks and installs the required packages automatically. However, you can manually install them using pip, just to be safe:
pip install spotipy lyricsgenius langdetect
-
Update the script with your settings:
Open
filter.py
in your editor and update the following variables:filter_language_code
: Set the desired language code (e.g.,'en'
for English,'es'
for Spanish).original_playlist_id
: Set the Spotify playlist ID you want to filter.client_id
,client_secret
,genius_token
,redirect_uri
: Set your Spotify and Genius API credentials.
Run the script:
python filter.py
The script will:
- Load the cache from
song_language_cache.json
. - Fetch the songs from the specified Spotify playlist.
- Retrieve lyrics for each song using the Genius API.
- Detect the language of the lyrics.
- Create a new Spotify playlist containing only the songs that match the specified language.
- Save the language detection results to the cache file.
-
Logging: The script uses Python's
logging
module for logging information, warnings, and errors. By default, it logs to the console with theINFO
level. -
Cache: The cache file (
song_language_cache.json
) stores the language detection results to minimize redundant API calls. Each entry is stored as a JSON object on a new line for easy readability.
filter.py
: The main script that performs the filtering.song_language_cache.json
: The cache file storing language detection results.README.md
: This file.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
- Spotipy: A lightweight Python library for the Spotify Web API.
- lyricsgenius: A Python client for the Genius API.
- langdetect: A port of Google's language-detection library.
For any questions or suggestions, please open an issue on GitHub.