Search functions now have verbosity
This commit is contained in:
parent
dd42d924ef
commit
255aae6459
107
musicfetch
107
musicfetch
@ -88,14 +88,21 @@ def search_artist(name, timeout_seconds=15):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_existing_artist(name):
|
def get_existing_artist(name):
|
||||||
|
print(f"--> Checking if artist '{name}' already exists in Lidarr...")
|
||||||
try:
|
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()
|
resp.raise_for_status()
|
||||||
for artist in resp.json():
|
for artist in resp.json():
|
||||||
if artist["artistName"].lower() == name.lower():
|
if artist["artistName"].lower() == name.lower():
|
||||||
|
print("...Artist match found!")
|
||||||
return artist
|
return artist
|
||||||
except requests.RequestException as e:
|
print("...Artist not found in existing list.")
|
||||||
print(f"Failed to get existing artists: {e}")
|
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
|
return None
|
||||||
|
|
||||||
def add_artist(metadata_artist):
|
def add_artist(metadata_artist):
|
||||||
@ -125,25 +132,87 @@ def add_artist(metadata_artist):
|
|||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp.json()
|
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):
|
def search_album(track_name, artist_id):
|
||||||
resp = requests.get(
|
# Check local albums first
|
||||||
f"{LIDARR_URL}/api/v1/album/lookup",
|
album = search_local_album(track_name, artist_id=artist_id)
|
||||||
headers=headers,
|
if album:
|
||||||
params={"term": track_name, "artistId": artist_id}
|
return album
|
||||||
)
|
|
||||||
resp.raise_for_status()
|
# Fallback to external lookup
|
||||||
results = resp.json()
|
try:
|
||||||
return results[0] if results else None
|
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},
|
||||||
|
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):
|
def search_album_by_artist(track_name, artist_name):
|
||||||
resp = requests.get(
|
# Check local albums first
|
||||||
f"{LIDARR_URL}/api/v1/album/lookup",
|
album = search_local_album(track_name, artist_name=artist_name)
|
||||||
headers=headers,
|
if album:
|
||||||
params={"term": f"{artist_name} {track_name}"}
|
return album
|
||||||
)
|
|
||||||
resp.raise_for_status()
|
# Fallback to external lookup
|
||||||
results = resp.json()
|
try:
|
||||||
return results[0] if results else None
|
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}"},
|
||||||
|
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):
|
def trigger_album_search(album_id):
|
||||||
data = {
|
data = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user