mirror of
https://github.com/plexguide/Huntarr-Sonarr.git
synced 2025-12-16 20:04:16 -06:00
Add ID validation to get_artist_by_id, get_albums and upgrade.py
Co-authored-by: Admin9705 <24727006+Admin9705@users.noreply.github.com>
This commit is contained in:
@@ -191,10 +191,18 @@ def get_artists(api_url: str, api_key: str, api_timeout: int, artist_id: Optiona
|
||||
def get_albums(api_url: str, api_key: str, api_timeout: int, album_id: Optional[int] = None, artist_id: Optional[int] = None) -> Union[List, Dict, None]:
|
||||
"""Get album information from Lidarr."""
|
||||
params = {}
|
||||
if artist_id:
|
||||
|
||||
# Validate IDs if provided
|
||||
if artist_id is not None:
|
||||
if artist_id <= 0:
|
||||
lidarr_logger.error(f"Invalid artist ID: {artist_id}. Artist ID must be a positive integer.")
|
||||
return None
|
||||
params['artistId'] = artist_id
|
||||
|
||||
if album_id:
|
||||
if album_id is not None:
|
||||
if album_id <= 0:
|
||||
lidarr_logger.error(f"Invalid album ID: {album_id}. Album ID must be a positive integer.")
|
||||
return None
|
||||
endpoint = f"album/{album_id}"
|
||||
else:
|
||||
endpoint = "album"
|
||||
@@ -472,4 +480,9 @@ def get_command_status(api_url: str, api_key: str, api_timeout: int, command_id:
|
||||
|
||||
def get_artist_by_id(api_url: str, api_key: str, api_timeout: int, artist_id: int) -> Optional[Dict[str, Any]]:
|
||||
"""Get artist details by ID from Lidarr."""
|
||||
# Validate artist_id to prevent errors
|
||||
if artist_id is None or artist_id <= 0:
|
||||
lidarr_logger.error(f"Invalid artist ID: {artist_id}. Artist ID must be a positive integer.")
|
||||
return None
|
||||
|
||||
return arr_request(api_url, api_key, api_timeout, f"artist/{artist_id}")
|
||||
@@ -113,10 +113,24 @@ def process_cutoff_upgrades(
|
||||
albums_to_search = random.sample(unprocessed_albums, min(len(unprocessed_albums), hunt_upgrade_items))
|
||||
lidarr_logger.info(f"Randomly selected {len(albums_to_search)} albums for upgrade search.")
|
||||
|
||||
album_ids_to_search = [album['id'] for album in albums_to_search]
|
||||
# Filter out invalid album IDs
|
||||
original_count = 0
|
||||
album_ids_to_search = []
|
||||
for album in albums_to_search:
|
||||
original_count += 1
|
||||
album_id = album.get('id')
|
||||
album_title = album.get('title', 'Unknown Album')
|
||||
# Validate album ID - ensure it's a positive integer
|
||||
if album_id is not None and isinstance(album_id, int) and album_id > 0:
|
||||
album_ids_to_search.append(album_id)
|
||||
else:
|
||||
lidarr_logger.warning(f"Skipping album '{album_title}' with invalid ID: {album_id}")
|
||||
|
||||
if len(album_ids_to_search) < original_count:
|
||||
lidarr_logger.warning(f"Filtered out {original_count - len(album_ids_to_search)} albums with invalid IDs")
|
||||
|
||||
if not album_ids_to_search:
|
||||
lidarr_logger.info("No album IDs selected for upgrade search. Skipping trigger.")
|
||||
lidarr_logger.info("No valid album IDs selected for upgrade search. Skipping trigger.")
|
||||
return False
|
||||
|
||||
# Prepare detailed album information for logging
|
||||
|
||||
Reference in New Issue
Block a user