Search functions now have verbosity
This commit is contained in:
parent
dd42d924ef
commit
255aae6459
79
musicfetch
79
musicfetch
@ -88,14 +88,21 @@ def search_artist(name, timeout_seconds=15):
|
||||
return None
|
||||
|
||||
def get_existing_artist(name):
|
||||
print(f"--> Checking if artist '{name}' already exists in Lidarr...")
|
||||
try:
|
||||
resp = requests.get(f"{LIDARR_URL}/api/v1/artist", headers=headers)
|
||||
print("...Sending request to /api/v1/artist")
|
||||
resp = requests.get(f"{LIDARR_URL}/api/v1/artist", headers=headers, timeout=10)
|
||||
print("...Got response from Lidarr")
|
||||
resp.raise_for_status()
|
||||
for artist in resp.json():
|
||||
if artist["artistName"].lower() == name.lower():
|
||||
print("...Artist match found!")
|
||||
return artist
|
||||
except requests.RequestException as e:
|
||||
print(f"Failed to get existing artists: {e}")
|
||||
print("...Artist not found in existing list.")
|
||||
except requests.exceptions.Timeout:
|
||||
print("!!! Timeout during existing artist check.")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"!!! Exception during existing artist check: {e}")
|
||||
return None
|
||||
|
||||
def add_artist(metadata_artist):
|
||||
@ -125,25 +132,87 @@ def add_artist(metadata_artist):
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
|
||||
def search_local_album(track_name, artist_id=None, artist_name=None):
|
||||
try:
|
||||
print(f"--> Searching local albums for track: '{track_name}'")
|
||||
resp = requests.get(
|
||||
f"{LIDARR_URL}/api/v1/album",
|
||||
headers=headers,
|
||||
timeout=10
|
||||
)
|
||||
resp.raise_for_status()
|
||||
albums = resp.json()
|
||||
print(f"...Loaded {len(albums)} local albums")
|
||||
|
||||
# Search by artist_id and track_name
|
||||
for album in albums:
|
||||
# Check artist ID match if provided
|
||||
if artist_id and album.get("artistId") != artist_id:
|
||||
continue
|
||||
# Check artist name match if provided
|
||||
if artist_name and album.get("artist", {}).get("artistName", "").lower() != artist_name.lower():
|
||||
continue
|
||||
# Check if track_name matches album title (case insensitive substring)
|
||||
if track_name.lower() in album.get("title", "").lower():
|
||||
print(f"!!! Found local album: {album.get('title')} by {album.get('artist', {}).get('artistName')}")
|
||||
return album
|
||||
print("!!! No matching local album found.")
|
||||
except requests.exceptions.Timeout:
|
||||
print("!!! Timeout during local album search.")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"!!! Exception during local album search: {e}")
|
||||
return None
|
||||
|
||||
def search_album(track_name, artist_id):
|
||||
# Check local albums first
|
||||
album = search_local_album(track_name, artist_id=artist_id)
|
||||
if album:
|
||||
return album
|
||||
|
||||
# Fallback to external lookup
|
||||
try:
|
||||
print(f"--> Searching album externally with track: '{track_name}' and artist ID: {artist_id}")
|
||||
resp = requests.get(
|
||||
f"{LIDARR_URL}/api/v1/album/lookup",
|
||||
headers=headers,
|
||||
params={"term": track_name, "artistId": artist_id}
|
||||
params={"term": track_name, "artistId": artist_id},
|
||||
timeout=10
|
||||
)
|
||||
resp.raise_for_status()
|
||||
results = resp.json()
|
||||
print(f"...Found {len(results)} results from album lookup with artist ID.")
|
||||
return results[0] if results else None
|
||||
except requests.exceptions.Timeout:
|
||||
print("!!! Timeout during album search (with artist ID).")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"!!! Exception during album search (with artist ID): {e}")
|
||||
return None
|
||||
|
||||
def search_album_by_artist(track_name, artist_name):
|
||||
# Check local albums first
|
||||
album = search_local_album(track_name, artist_name=artist_name)
|
||||
if album:
|
||||
return album
|
||||
|
||||
# Fallback to external lookup
|
||||
try:
|
||||
print(f"--> Fallback external search: '{artist_name} {track_name}'")
|
||||
resp = requests.get(
|
||||
f"{LIDARR_URL}/api/v1/album/lookup",
|
||||
headers=headers,
|
||||
params={"term": f"{artist_name} {track_name}"}
|
||||
params={"term": f"{artist_name} {track_name}"},
|
||||
timeout=10
|
||||
)
|
||||
resp.raise_for_status()
|
||||
results = resp.json()
|
||||
print(f"...Found {len(results)} results from fallback search.")
|
||||
return results[0] if results else None
|
||||
except requests.exceptions.Timeout:
|
||||
print("!!! Timeout during fallback album search.")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"!!! Exception during fallback album search: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def trigger_album_search(album_id):
|
||||
data = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user