Got an existing library but tired of Lidarr searches failing while they are rebuilding the server cache? Don't have time to search MusicBrainz?
Introducing MusicBrainz-Lidarr-Primer!
A two-stage Python script pipeline to bulk-import artists into Lidarr.
musicbrainz_lookup.py: Reads a list of artist names fromfolders.txt, finds their official MusicBrainz ID (MBID), and saves the results tosearch_results.txt.add_to_lidarr.py: Readssearch_results.txtand adds each artist to your Lidarr instance via its API.
- Resilient & Resumable: If the script fails (e.g., due to a network error), it can be restarted and will automatically resume from where it left off.
- Automatic Retries: Handles temporary network blips by automatically retrying failed requests.
- Efficient: Proactively checks your Lidarr library to skip artists that are already added.
- User-Friendly: Provides a progress bar (
tqdm) to show progress during the lookup phase. - Configurable: All sensitive information (API keys, URLs) and settings are passed as command-line arguments, not hardcoded.
- A running Lidarr instance
- Python 3.6+: These scripts require Python to run.
- To check if Python is installed, open your terminal and run:
python3 --version. - If it's not installed, follow the instructions for your operating system:
- Windows: Download the latest Python 3 release from python.org. During installation, make sure to check the box that says "Add Python to PATH".
- macOS: The recommended way to install Python is via Homebrew. After installing Homebrew, run:
brew install python. - Debian/Ubuntu:
sudo apt update sudo apt install python3
- To check if Python is installed, open your terminal and run:
-
Clone the repository:
git clone <your-repo-url> cd <your-repo-directory>
-
Ensure
pipis installed:pipis Python's package installer and is usually included with Python. You can check if it's installed by runningpython3 -m pip --version. If it's not found, you can install it with one of the following methods:- Using Python's
ensurepip(Recommended for most systems):python3 -m ensurepip --upgrade
- On Debian/Ubuntu systems:
sudo apt update sudo apt install python3-pip
- Using Python's
-
Install dependencies: This will install the
requestsandtqdmlibraries.pip3 install -r requirements.txt
-
Create your artist list: Create a file named
folders.txtin the same directory. Add one artist name per line.Example
folders.txt:Led Zeppelin Pink Floyd The BeatlesYou can use the included
create_artist_list.pyscript to automatically generatefolders.txtfrom your existing music library directory.Note: This script must be run on a machine that has access to your music library folder.
# Example for a library at /mnt/music python3 create_artist_list.py /mnt/music # Example for a library on a Windows machine python3 create_artist_list.py "D:\Media\Music"
-
Update the User-Agent: Open
musicbrainz_lookup.pyand replace the placeholder email in theHEADERSdictionary with your own. This is required by the MusicBrainz API policy.HEADERS = { "User-Agent": "MusicBrainzLookupScript/1.0 ( your-real-email@example.com )" }
You will run the pipeline from your terminal, providing your Lidarr details as arguments.
This command will run the MusicBrainz lookup and then automatically trigger the Lidarr import.
python3 musicbrainz_lookup.py --add-to-lidarr --lidarr-url "http://LIDARR_HOST:8686" --api-key "YOUR_LIDARR_API_KEY" --root-folder "/path/to/your/music"Argument Breakdown:
--add-to-lidarr: This flag tells the first script to automatically start the second script upon completion.--lidarr-url: The URL for your Lidarr instance.--api-key: Your Lidarr API key (found in Lidarr underSettings>General).--root-folder: The absolute path to your music library's root folder as seen by Lidarr.--quality-profile-id(Optional): The ID of the quality profile to use. Defaults to1.
If you need to re-run only the import step (e.g., to debug or after changing Lidarr settings), you can run the second script directly. This assumes search_results.txt already exists.
python3 add_to_lidarr.py --lidarr-url "http://LIDARR_HOST:8686" --api-key "YOUR_LIDARR_API_KEY" --root-folder "/path/to/your/music"