main
1#!/usr/bin/env -S uv run --script
2# /// script
3# requires-python = ">=3.11"
4# dependencies = [
5# "requests>=2.31.0",
6# ]
7# ///
8"""
9Fix Lidarr naming configuration to remove duplicate 'library' folder.
10
11Changes artistFolderFormat from 'library/{Artist Name}' to '{Artist Name}'.
12"""
13
14import os
15import sys
16import requests
17
18# Get API key from environment
19api_key = os.environ.get("LIDARR_API_KEY")
20if not api_key:
21 print("Error: LIDARR_API_KEY environment variable not set")
22 sys.exit(1)
23
24base_url = "https://lidarr.sbr.pm"
25headers = {"X-Api-Key": api_key, "Content-Type": "application/json"}
26
27print("Fetching current naming configuration...")
28try:
29 response = requests.get(f"{base_url}/api/v1/config/naming", headers=headers)
30 response.raise_for_status()
31 config = response.json()
32except Exception as e:
33 print(f"Error fetching config: {e}")
34 sys.exit(1)
35
36print(f"\nCurrent Artist Folder Format: {config.get('artistFolderFormat')}")
37
38if config.get('artistFolderFormat') == 'library/{Artist Name}':
39 print("\nChanging to: {Artist Name}")
40
41 config['artistFolderFormat'] = '{Artist Name}'
42
43 try:
44 response = requests.put(f"{base_url}/api/v1/config/naming/{config['id']}",
45 headers=headers, json=config)
46 response.raise_for_status()
47 print("✓ Successfully updated naming configuration!")
48 print("\nNew Artist Folder Format: {Artist Name}")
49 print("\nNote: This only affects NEW artists added to Lidarr.")
50 print("Existing artists with duplicate paths need to be fixed with:")
51 print(" arr lidarr fix-duplicate-paths https://lidarr.sbr.pm -k $LIDARR_API_KEY")
52 except Exception as e:
53 print(f"Error updating config: {e}")
54 sys.exit(1)
55elif config.get('artistFolderFormat') == '{Artist Name}':
56 print("✓ Already configured correctly!")
57else:
58 print(f"\nUnexpected format: {config.get('artistFolderFormat')}")
59 print("Please manually review this setting.")