- main.py:
- Added --import-json and --import-text for bulk playlist creation from local files.
- Implemented search-based creation: providing a name instead of a URL now searches YouTube for a matching playlist.
- Added --playlist-name to override the default title of any imported playlist.
- Added --cookies-browser to bypass YouTube bot detection using browser cookies.
- Improved import_text logic with intelligent Artist/Song detection for pop-punk genre.
- download_utils.py & youtube_utils.py:
- Integrated support for --cookies-browser.
- Added exponential backoff retry and random delays to downloads to minimize bot-detection triggers.
- Improved validation of cookies.txt (Netscape header check).
- metadata_utils.py:
- Implemented global rate-limiting (1 req/sec) and retries for MusicBrainz API calls to prevent 503 errors.
- clean_utils.py:
- Expanded artist-first pattern recognition and improved extraction robustness.
- artist_name_mapping.json:
- Significantly expanded the mapping table with common pop-punk and alternative artists.
|
||
|---|---|---|
| tests | ||
| .gitignore | ||
| ARCHITECTURE.md | ||
| artist_name_mapping.json | ||
| cache_utils.py | ||
| clean_utils.py | ||
| config.json | ||
| config_utils.py | ||
| constants.py | ||
| cookies.txt | ||
| download_utils.py | ||
| file_utils.py | ||
| gemini_hint.md | ||
| jellyfin_api.py | ||
| lastfm_api.py | ||
| log.txt | ||
| main.py | ||
| metadata_utils.py | ||
| output.txt | ||
| pytest.ini | ||
| README.md | ||
| requirements.txt | ||
| song_name_mapping.json | ||
| string_utils.py | ||
| youtube_utils.py | ||
Playlist Importer
A Python-based tool to import YouTube playlists into Jellyfin, with support for downloading missing songs, cleaning file names, adding metadata, and creating playlists from Last.fm data.
Table of Contents
Features
- Import YouTube Playlists: Fetch and import YouTube playlists into Jellyfin.
- Download Missing Songs: Automatically download missing songs from YouTube.
- Clean File Names: Remove unwanted prefixes (e.g.,
NA -) and content within parentheses or brackets. - Add Metadata: Fetch and add metadata (album, year, etc.) to audio files.
- Jellyfin Integration: Seamlessly add songs to Jellyfin playlists.
- Last.fm Integration:
- Create playlists from an artist's top tracks.
- Create playlists from top tracks by tag (e.g., "rock", "pop", "reggaeton").
- Discover popular tags on Last.fm.
Prerequisites
Before using this project, ensure you have the following installed:
- Python 3.8 or higher
- FFmpeg (for audio processing)
- Jellyfin Server (with API access)
- Last.fm API Key (required for Last.fm features)
Setup
1. Clone the Repository
git clone http://192.168.0.56:3000/slava/playlist-importer.git
cd playlist-importer
2. Install Dependencies
Install the required Python packages:
pip install -r requirements.txt
3. Configure the Application
Copy the config.json.example to config.json and fill in your Jellyfin and Last.fm API credentials.
{
"jellyfin": {
"server_url": "http://JELLYFIN_SERVER_IP:8096",
"api_key": "YOUR_JELLYFIN_API_KEY",
"user_id": "YOUR_JELLYFIN_USER_ID"
},
"lastfm": {
"api_key": "YOUR_LASTFM_API_KEY"
},
"download": {
"output_dir": "downloaded_songs"
}
}
Usage
Import a YouTube Playlist
To import a YouTube playlist into Jellyfin, run:
python main.py "YOUTUBE_PLAYLIST_URL"
Fetch Artist Top Tracks from Last.fm
Create a playlist of an artist's top tracks.
python main.py --artist-top-tracks "Artist Name" --limit 50
Fetch Top Tracks by Tag from Last.fm
Create a playlist of top tracks for a specific tag.
python main.py --top-tracks-by-tag "rock" --limit 100
Discover Popular Tags on Last.fm
List the most popular tags on Last.fm.
python main.py --popular-tags
Common Arguments
--download: Download any songs that are not found in your Jellyfin library.--limit <number>: Specify the number of tracks to fetch from Last.fm (default is 30).--ignore-cache: Ignores cached playlist data and fetches fresh data.--clear-cache: Clears all cached data.
Configuration
artist_name_mapping.json
This file allows you to correct artist names that may differ between Last.fm and your Jellyfin library. For example, if Last.fm returns "Artist Name & The Band" but your library has "Artist Name", you can add a mapping:
{
"artist name & the band": "Artist Name"
}
This helps improve the accuracy of song matching.
Troubleshooting
ModuleNotFoundError: Ensure you have installed the dependencies fromrequirements.txtand are running the script from the project's root directory.- FFmpeg Not Found: Make sure FFmpeg is installed and accessible in your system's PATH.
- 401 Unauthorized from Jellyfin: Double-check your Jellyfin server URL, API key, and user ID in
config.json. - Last.fm API Errors: Verify your Last.fm API key in
config.json.