- Added a new command-line argument `--delete` to allow users to delete single albums after successful metadata migration. - Integrated the `unmonitor_and_delete_album` function to handle the deletion process for albums that meet the migration criteria. - Enhanced the `migrate_plex_metadata` function to support exclusion of smart playlists during migration. - Updated logging to provide detailed feedback on the deletion process and migration results.
lidarr-mb-gap
A tool to identify missing albums on MusicBrainz from Deezer releases for artists monitored in Lidarr, and generate submission links for easy import.
Features
- 🔍 Automated Discovery: Finds missing albums by comparing Lidarr monitored artists with Deezer releases via SAMBL
- 📊 Dual Reports: Generates both JSON and interactive HTML reports
- 🔗 Submission Links: Automatically generates a-tisket and Harmony links for MusicBrainz submissions
- 🎯 Smart Filtering:
- Identifies albums that need to be added to MusicBrainz (missing)
- Identifies albums that need to be updated (exist but need linking/updates)
- 🎨 Interactive HTML Report: Filter by type (add/update) and by artist
- 🐍 Python-based: Clean, functional codebase with proper logging
- ❄️ Nix Support: Fully packaged with Nix flake for reproducible builds
- 🚀 NixOS Module: Automated deployment with systemd service and timer
- 🌐 Web Serving: Ready for deployment with Caddy or any web server
Requirements
- Lidarr instance with API access
- SAMBL instance (defaults to
https://sambl.lioncat6.com) - Python 3.8+ (or use Nix)
Installation
Using Nix (Recommended)
# Run directly
nix run .#lidarr-mb-gap
# Or build and install
nix build .#lidarr-mb-gap
nix profile install .#lidarr-mb-gap
Development Setup
# Enter development shell
nix develop
# Run the script
python src/main.py
# Format code
black src/
Configuration
Create a .env file in the project root:
# Required
LIDARR_URL=http://your-lidarr-instance:8686
LIDARR_API_KEY=your-api-key-here
# Optional
SAMBL_URL=https://sambl.lioncat6.com
MAX_ARTISTS=5 # Limit number of artists processed (0 = no limit)
OUTPUT_DIR=. # Directory where output files will be written (default: current directory)
Getting Your Lidarr API Key
- Open Lidarr web interface
- Go to Settings → General
- Copy your API Key
Usage
Basic Usage
# Using Nix
nix run .#lidarr-mb-gap
# Or if installed
lidarr-mb-gap
The script will:
- Fetch all artists from Lidarr with
monitorNewItemsset to "new" or "all" - For each artist, query SAMBL to find missing albums on MusicBrainz
- Generate submission links (a-tisket and Harmony)
- Create two output files in the directory specified by
OUTPUT_DIR(or current directory):missing_albums.json- Machine-readable JSON reportmissing_albums.html- Interactive HTML report with filters
Output Files
missing_albums.json
Contains structured data with:
albums_to_add: Albums not in MusicBrainzalbums_to_update: Albums that exist but need updates/linkingsummary: Counts and totals
missing_albums.html
Interactive HTML report with:
- Filter buttons for type (Add/Update/All)
- Filter buttons for each artist
- Clickable submission links (a-tisket and Harmony)
- Direct links to Deezer and MusicBrainz
Project Structure
.
├── src/
│ ├── __init__.py
│ ├── main.py # Main application logic
│ ├── html_report.py # HTML report generation
│ └── pyproject.toml # Python package configuration
├── nix/
│ └── package.nix # Shared Nix package definition
├── nixos/
│ ├── lidarr-mb-gap.nix # NixOS module for automated deployment
│ └── DEPLOYMENT.md # Detailed deployment guide
├── flake.nix # Nix flake definition
├── Caddyfile # Caddy configuration for serving reports
├── .env # Environment variables (create this)
└── README.md
How It Works
- Lidarr Integration: Queries Lidarr API for monitored artists
- Deezer Search: Uses Deezer API to find artist IDs
- SAMBL Comparison: Calls SAMBL's
/api/compareArtistAlbumsendpoint to compare Deezer releases with MusicBrainz - Categorization:
- Red status or no MBID → Album to ADD
- Orange status → Album to UPDATE
- Link Generation: Creates submission links using:
Logging
The application uses Python's logging module with systemd-friendly output:
[INFO]- Informational messages[WARNING]- Warnings (e.g., missing MusicBrainz ID)[ERROR]- Errors (e.g., missing configuration, API failures)
Perfect for running as a systemd service.
Deployment
NixOS Automated Deployment
This project includes a NixOS module for automated deployment with:
- Systemd service for report generation
- Systemd timer for periodic execution (configurable)
- Optional automatic rsync sync to VPS
- SSH key management for secure VPS access
- Caddy configuration for serving the HTML report
See nixos/DEPLOYMENT.md for detailed deployment instructions.
Quick Start with NixOS
# In your NixOS configuration
services.lidarr-mb-gap = {
enable = true;
package = lidarr-mb-gap.packages.${system}.lidarr-mb-gap; # From flake
reportDir = "/var/lib/lidarr-mb-gap/reports";
envFile = "/var/lib/lidarr-mb-gap/.env";
runInterval = "daily";
# Optional: Auto-sync to VPS
syncToVPS = true;
vpsHost = "user@vps";
vpsPath = "/var/www/html";
sshKeyFile = "/var/lib/lidarr-mb-gap/.ssh/id_ed25519";
};
For complete setup instructions, including SSH key configuration and Caddy setup, see the deployment guide.
Example Output
[INFO] Fetching monitored artists from Lidarr...
[INFO] Found 10 monitored artists
[INFO] ================================================================================
[INFO] Artist: Angus & Julia Stone
[INFO] MusicBrainz ID: abc123-def456-...
[INFO] Albums to ADD (3):
[INFO] 📀 Life Is Strange
[INFO] Deezer: https://www.deezer.com/album/12345
[INFO] a-tisket: https://atisket.pulsewidth.org.uk/?url=...
[INFO] Harmony: https://harmony.pulsewidth.org.uk/release?url=...
...
Troubleshooting
"LIDARR_URL not set" or "LIDARR_API_KEY not set"
- Ensure your
.envfile exists and contains the required variables - Check that the file is in the project root directory
"No artists found"
- Verify that you have artists in Lidarr with
monitorNewItemsset to "new" or "all" - Check your Lidarr API key is correct
"ModuleNotFoundError: No module named 'html_report'"
- Make sure you're running from the project root
- If using Nix, ensure the flake is properly built
Output files not appearing
- Check that
OUTPUT_DIRenvironment variable points to a writable directory - Ensure the directory exists and has proper permissions
- Check logs for any permission errors
Contributing
- Format code with
black src/ - Ensure the flake builds:
nix flake check - Test your changes:
nix run .#lidarr-mb-gap
License
This project is open source. Use it as you wish!
Acknowledgments
Description
Languages
Python
89%
Nix
11%