For Lidarr searches, implemented 15 sec timeout before falling back to yt-dlp

This commit is contained in:
zebra 2025-06-09 13:33:32 -07:00
parent 6810c0ecbb
commit d186e32c03

View File

@ -5,6 +5,7 @@ import os
import re
import subprocess
import requests
from requests.exceptions import Timeout
# === CONFIGURATION ===
LIDARR_URL = "http://localhost:8686" # Your Lidarr base URL
@ -68,22 +69,33 @@ def yt_dlp_download(url_or_query, target_folder):
url_or_query
])
def search_artist(name):
def search_artist(name, timeout_seconds=15):
try:
resp = requests.get(
f"{LIDARR_URL}/api/v1/artist/lookup",
headers=headers,
params={"term": name}
params={"term": name},
timeout=timeout_seconds
)
resp.raise_for_status()
results = resp.json()
return results[0] if results else None
except Timeout:
print(f"Lidarr artist search timed out after {timeout_seconds} seconds.")
return None
except requests.RequestException as e:
print(f"Lidarr artist search failed: {e}")
return None
def get_existing_artist(name):
try:
resp = requests.get(f"{LIDARR_URL}/api/v1/artist", headers=headers)
resp.raise_for_status()
for artist in resp.json():
if artist["artistName"].lower() == name.lower():
return artist
except requests.RequestException as e:
print(f"Failed to get existing artists: {e}")
return None
def add_artist(metadata_artist):
@ -179,10 +191,10 @@ def main():
artist = get_existing_artist(artist_name)
if not artist:
print("Artist not found. Searching Lidarr metadata...")
print("Artist not found. Searching Lidarr metadata (with timeout)...")
metadata = search_artist(artist_name)
if not metadata:
print("No match found in Lidarr metadata. Falling back to yt-dlp.")
print("No match found or search timed out. Falling back to yt-dlp.")
yt_dlp_download(input_str, os.path.join(ROOT_FOLDER, artist_name, "youtube"))
return