No description
- Python 96.9%
- Dockerfile 2.1%
- Nix 1%
| .gitignore | ||
| docker-compose.yml | ||
| Dockerfile | ||
| music_sorter.py | ||
| README.md | ||
| requirements.txt | ||
| shell.nix | ||
| test_acoustid_tagging.py | ||
| test_recovery.py | ||
| test_sorter.py | ||
| test_watcher.py | ||
Music Sorter
Sorts music files based on metadata.
Prerequisites
- AcoustID API Key: This project uses AcoustID for audio fingerprinting to identify files with missing metadata.
- Go to https://acoustid.org/login and log in.
- Click on "My applications" (or "Register a new application") to get an API key.
- You will need to set this key as
ACOUSTID_API_KEYin your environment ordocker-compose.yml.
A Python-based utility to organize your music library into a folder structure optimized for Navidrome.
The tool reads metadata tags from your audio files and organizes them into Artist/Album/Disc-Track - Title.ext structure.
Features
- Metadata-based Sorting: Uses
Album Artist(orArtist),Album,Disc Number,Track Number, andTitle. - Metadata Recovery: Attempts to recover missing tags from file paths or using a local LLM (Ollama).
- Supports Multiple Formats:
mp3,flac,ogg,m4a,opus,wav. - Safe Modes: Default behavior attempts to move files, but
--copyand--dry-runmodes are available. - File Watcher: Optional service to continuously watch download directories and sort new files automatically.
- Dockerized: Easy to run anywhere without installing Python/dependencies locally.
Usage
Option 1: Docker (Recommended)
Run with Docker Compose:
- Place your messy music in a folder (e.g.,
./music_in). - Run the sorter:
Note: Modify environment variables indocker-compose up -d music-sorter # Run once docker-compose up -d music-watcher # Run continuouslydocker-compose.ymlto change settings.
Run with Docker CLI:
docker build -t music-sorter .
docker run --rm \
-v /path/to/source:/data/input \
-v /path/to/destination:/data/output \
-e OLLAMA_URL=http://host.docker.internal:11434 \
-e OLLAMA_MODEL=llama3 \
--add-host=host.docker.internal:host-gateway \
music-sorter --input /data/input --output /data/output --copy
Option 2: Local (Nix)
If you have Nix installed:
nix-shell shell.nix
python3 music_sorter.py --input /path/to/source --output /path/to/destination --dry-run
Option 3: Local (Python)
Requires Python 3.11+ and mutagen.
pip install -r requirements.txt
python3 music_sorter.py --input /path/to/source --output /path/to/destination
Troubleshooting
AcoustID Error: status: error
If you see AcoustID WebServiceError: status: error in the logs:
- Verify your
ACOUSTID_API_KEYis correct indocker-compose.yml. - Ensure you have not exceeded your API limit (though our rate limiter helps).
- Check if your API key application is active on acoustid.org.
Configuration
You can use CLI arguments or Environment Variables (prefixed with MSC_).
| Argument | Env Var | Description |
|---|---|---|
--input |
MSC_INPUT |
Input directory path(s) (comma separated for Env). |
--output |
MSC_OUTPUT |
Output directory path. |
--dry-run |
MSC_DRY_RUN |
Set to true to simulate without moving. |
--copy |
MSC_COPY |
Set to true to copy instead of move. |
--verbose |
MSC_VERBOSE |
Set to true for debug logging. |
--watch |
MSC_WATCH |
Set to true to enable file watcher mode. |
OLLAMA_URL |
URL to Ollama instance (e.g., http://localhost:11434). |
|
OLLAMA_MODEL |
Model to use (default: llama3). |
|
ACOUSTID_API_KEY |
AcoustID API Key for audio fingerprinting. |