Skip to content

Instantly share code, notes, and snippets.

@jackskhakis
Last active July 19, 2025 23:07
Show Gist options
  • Save jackskhakis/a7da48ae11b3a78401d7527e9ddb80da to your computer and use it in GitHub Desktop.
Save jackskhakis/a7da48ae11b3a78401d7527e9ddb80da to your computer and use it in GitHub Desktop.
Script to add list of artists (in a folder) to lidarr, this method bypasses the difficulties that are currently present in lidarr with relation to searching and adding new artists
#!/bin/bash
# Folder where existing artist folders are located (source)
source_dir="/mnt/media/music/old"
# The Lidarr root folder path to add new artists under
# This must match a configured Root Folder in Lidarr settings
lidarr_root="/music/new"
# Lidarr API access
lidarr_url="http://localhost:8686"
api_key="YOUR_API_KEY_HERE"
# Set a delay (in seconds) between each add operation to avoid rate limits
delay_between_adds=120
# IDs required by Lidarr – see comments below for how to gather these
quality_profile_id=1
metadata_profile_id=1
# --- HOW TO FETCH PROFILE IDs ---
# curl -s "$lidarr_url/api/v1/qualityprofile" -H "X-Api-Key: $api_key" | jq
# curl -s "$lidarr_url/api/v1/metadataprofile" -H "X-Api-Key: $api_key" | jq
# --- START SCRIPT ---
echo "πŸ“₯ Fetching list of existing artists from Lidarr..."
existing_ids=$(curl -s "$lidarr_url/api/v1/artist" \
-H "X-Api-Key: $api_key" | jq -r '.[].foreignArtistId')
# Loop through each artist folder in the source directory
find "$source_dir" -mindepth 1 -maxdepth 1 -type d | while read -r artist_folder; do
artist_name=$(basename "$artist_folder")
echo "πŸ” Searching for: $artist_name"
# Lookup artist metadata from Lidarr
search_result=$(curl -s -G "$lidarr_url/api/v1/artist/lookup" \
--data-urlencode "term=$artist_name" \
-H "X-Api-Key: $api_key")
artist_json=$(echo "$search_result" | jq '.[0]')
if [ "$artist_json" == "null" ] || [ -z "$artist_json" ]; then
echo "❌ Not found in lookup: $artist_name"
continue
fi
# Skip artist if it already exists in Lidarr
foreign_id=$(echo "$artist_json" | jq -r '.foreignArtistId')
if echo "$existing_ids" | grep -q "$foreign_id"; then
echo "⏩ Already exists in Lidarr: $artist_name"
continue
fi
# Root path only (Lidarr creates the subfolder automatically)
target_path="$lidarr_root"
# Build the JSON payload
payload=$(jq -n \
--argjson artist "$artist_json" \
--arg path "$target_path" \
--argjson qualityProfileId "$quality_profile_id" \
--argjson metadataProfileId "$metadata_profile_id" \
'{
artistMetadataId: $artist.artistMetadataId,
qualityProfileId: $qualityProfileId,
metadataProfileId: $metadataProfileId,
rootFolderPath: $path,
monitored: true,
foreignArtistId: $artist.foreignArtistId,
artistName: $artist.artistName,
addOptions: {
monitor: "all",
searchForMissingAlbums: true
}
}')
echo "βž• Adding to Lidarr: $artist_name β†’ $target_path"
curl -s -X POST "$lidarr_url/api/v1/artist" \
-H "Content-Type: application/json" \
-H "X-Api-Key: $api_key" \
-d "$payload"
echo "βœ… Done: $artist_name"
echo "⏳ Waiting $delay_between_adds seconds before next artist..."
sleep $delay_between_adds
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment