A comprehensive Python-based music library organizer that integrates with Spotify to manage, organize, and create playlists from your local music collection. This tool helps you maintain a well-organized music library with proper metadata, cover art, and synchronized Spotify playlists.
- Automatic metadata updating from Spotify
- Cover art downloading and embedding
- BPM (tempo) detection
- Smart track matching using Levenshtein distance
- Playlist generation (both M3U and Spotify):
- BPM-based workout playlists
- Decade-based playlists
- Folder-based playlists
- File format conversion (FLAC/M4A to MP3)
- Automatic file renaming based on metadata
- Cover art collage generation
- Python 3.8 or higher
- Spotify Developer Account (for API access)
- AudD API key (for music recognition)
- Clone the repository:
git clone https://github.com/leodr/music_organizer.git
cd music_organizer
- Install required Python packages:
pip install mutagen requests spotipy python-dotenv pydub tqdm librosa Pillow
- Create a
.env
file in the project root with your API credentials:
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
AUDD_API_KEY=your_audd_api_key
- Create the following directory structure:
music_organizer/
├── music/ # Place your music files here
├── cover_art/ # Auto-generated folder for album artwork
└── playlists/ # Auto-generated folder for M3U playlists
The main script processes your music files, updates metadata, and organizes your library:
python main.py
This will:
- Convert FLAC/M4A files to MP3
- Match songs with Spotify tracks
- Update metadata (title, artist, album, year, etc.)
- Download and embed cover art
- Rename files based on metadata
Generate both M3U and Spotify playlists based on your library:
python create_playlists.py
This creates:
- BPM-based workout playlists (110-160 BPM ranges)
- Decade-based playlists
- Folder-based playlists
- All Songs playlist or adds songs to Spotify Liked Songs
- Create Cover Art Collage:
python create_cover_collage.py
- Count Missing Metadata:
python count_missing.py
main.py
: Core functionality for organizing music filescreate_playlists.py
: Playlist generation scriptcreate_cover_collage.py
: Creates album art collagescount_missing.py
: Reports on missing metadatarecognize.py
: Music recognition functionality- Utility modules:
bpm.py
: BPM detectionstring_cleaning.py
: String normalization and cleaninglevenshtein.py
: String similarity matchingparse_year.py
: Release date parsingsafe_json.py
: JSON handling utilitiessort_tracks.py
: Track sorting logicspotify_track_id.py
: Spotify ID extraction
- The tool uses Levenshtein distance for fuzzy matching of track names
- Files are automatically renamed based on the pattern: "Artist - Title"
- Special characters are handled and cleaned in filenames
- Cover art is stored locally to avoid repeated downloads
- BPM detection is performed only if not already present in metadata
Feel free to submit issues and enhancement requests!