Added support for lidarr (UNTESTED!)

This commit is contained in:
Benjamin Harder
2023-10-20 08:53:36 +02:00
parent 45fc205c2a
commit c32340b081
6 changed files with 75 additions and 32 deletions

View File

@@ -19,7 +19,7 @@ async def get_queue(BASE_URL, API_KEY, params = {}):
queue = await rest_get(f'{BASE_URL}/queue', API_KEY, {'page': '1', 'pageSize': totalRecords}|params)
return queue
async def remove_failed(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads):
async def remove_failed(settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads):
# Detects failed and triggers delete. Does not add to blocklist
queue = await get_queue(BASE_URL, API_KEY)
if not queue: return 0
@@ -32,7 +32,7 @@ async def remove_failed(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, dele
failedItems.append(queueItem)
return len(failedItems)
async def remove_stalled(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads, defective_tracker):
async def remove_stalled(settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, defective_tracker):
# Detects stalled and triggers repeat check and subsequent delete. Adds to blocklist
queue = await get_queue(BASE_URL, API_KEY)
if not queue: return 0
@@ -56,7 +56,7 @@ async def remove_stalled(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, del
logger.debug('remove_stalled/queue OUT: %s', str(queue))
return len(stalledItems)
async def test_remove_ALL(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads, defective_tracker):
async def test_remove_ALL(settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, defective_tracker):
# Detects stalled and triggers repeat check and subsequent delete. Adds to blocklist
queue = await get_queue(BASE_URL, API_KEY)
if not queue: return 0
@@ -75,7 +75,7 @@ async def test_remove_ALL(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, de
return len(stalledItems)
async def remove_metadata_missing(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads, defective_tracker):
async def remove_metadata_missing(settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, defective_tracker):
# Detects downloads stuck downloading meta data and triggers repeat check and subsequent delete. Adds to blocklist
queue = await get_queue(BASE_URL, API_KEY)
if not queue: return 0
@@ -91,9 +91,9 @@ async def remove_metadata_missing(settings_dict, radarr_or_sonarr, BASE_URL, API
logger.debug('remove_metadata_missing/queue OUT: %s', str(queue))
return len(missing_metadataItems)
async def remove_orphans(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads):
async def remove_orphans(settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, full_queue_param):
# Removes downloads belonging to movies/tv shows that have been deleted in the meantime
full_queue = await get_queue(BASE_URL, API_KEY, params = {'includeUnknownMovieItems' if radarr_or_sonarr == 'radarr' else 'includeUnknownSeriesItems': 'true'})
full_queue = await get_queue(BASE_URL, API_KEY, params = {full_queue_param: True})
if not full_queue: return 0 # By now the queue may be empty
queue = await get_queue(BASE_URL, API_KEY)
full_queue_items = [{'id': queueItem['id'], 'title': queueItem['title'], 'downloadId': queueItem['downloadId']} for queueItem in full_queue['records']]
@@ -106,17 +106,19 @@ async def remove_orphans(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, del
await remove_download(settings_dict, BASE_URL, API_KEY, queueItem['id'], queueItem['title'], queueItem['downloadId'], 'orphan', False, deleted_downloads)
return len(orphanItems)
async def remove_unmonitored(settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads):
async def remove_unmonitored(settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads):
# Removes downloads belonging to movies/tv shows that are not monitored
queue = await get_queue(BASE_URL, API_KEY)
if not queue: return 0
unmonitoredItems= []
downloadItems = []
for queueItem in queue['records']:
if radarr_or_sonarr == 'sonarr':
if arr_type == 'sonarr':
monitored = (await rest_get(f'{BASE_URL}/episode/{str(queueItem["episodeId"])}', API_KEY))['monitored']
else:
elif arr_type == 'radarr':
monitored = (await rest_get(f'{BASE_URL}/movie/{str(queueItem["movieId"])}', API_KEY))['monitored']
elif arr_type == 'lidarr':
monitored = (await rest_get(f'{BASE_URL}/album/{str(queueItem["albumId"])}', API_KEY))['monitored']
downloadItems.append({'downloadId': queueItem['downloadId'], 'id': queueItem['id'], 'monitored': monitored})
monitored_downloadIds = [downloadItem['downloadId'] for downloadItem in downloadItems if downloadItem['monitored']]
unmonitoredItems = [downloadItem for downloadItem in downloadItems if downloadItem['downloadId'] not in monitored_downloadIds]
@@ -167,22 +169,33 @@ async def remove_download(settings_dict, BASE_URL, API_KEY, queueId, queueTitle,
return
########### MAIN FUNCTION ###########
async def queue_cleaner(settings_dict, radarr_or_sonarr, defective_tracker):
async def queue_cleaner(settings_dict, arr_type, defective_tracker):
# Read out correct instance depending on radarr/sonarr flag
run_dict = {}
if radarr_or_sonarr == 'radarr':
if arr_type == 'radarr':
BASE_URL = settings_dict['RADARR_URL']
API_KEY = settings_dict['RADARR_KEY']
NAME = settings_dict['RADARR_NAME']
else:
full_queue_param = 'includeUnknownMovieItems'
elif arr_type == 'sonarr':
BASE_URL = settings_dict['SONARR_URL']
API_KEY = settings_dict['SONARR_KEY']
NAME = settings_dict['SONARR_NAME']
full_queue_param = 'includeUnknownSeriesItems'
elif arr_type == 'lidarr':
BASE_URL = settings_dict['LIDARR_URL']
API_KEY = settings_dict['LIDARR_KEY']
NAME = settings_dict['LIDARR_NAME']
full_queue_param = 'includeUnknownArtistItems'
else:
logger.error('Unknown arr_type specified, exiting: %s', str(arr_type))
sys.exit()
# Cleans up the downloads queue
logger.verbose('Cleaning queue on %s:', NAME)
try:
full_queue = await get_queue(BASE_URL, API_KEY, params = {'includeUnknownMovieItems' if radarr_or_sonarr == 'radarr' else 'includeUnknownSeriesItems': 'true'})
full_queue = await get_queue(BASE_URL, API_KEY, params = {full_queue_param: True})
if not full_queue:
logger.verbose('>>> Queue is empty.')
return
@@ -190,22 +203,22 @@ async def queue_cleaner(settings_dict, radarr_or_sonarr, defective_tracker):
deleted_downloads = Deleted_Downloads([])
items_detected = 0
#items_detected += await test_remove_ALL( settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads, defective_tracker)
#items_detected += await test_remove_ALL( settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, defective_tracker)
if settings_dict['REMOVE_FAILED']:
items_detected += await remove_failed( settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads)
items_detected += await remove_failed( settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads)
if settings_dict['REMOVE_STALLED']:
items_detected += await remove_stalled( settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads, defective_tracker)
items_detected += await remove_stalled( settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, defective_tracker)
if settings_dict['REMOVE_METADATA_MISSING']:
items_detected += await remove_metadata_missing( settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads, defective_tracker)
items_detected += await remove_metadata_missing( settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, defective_tracker)
if settings_dict['REMOVE_ORPHANS']:
items_detected += await remove_orphans( settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads)
items_detected += await remove_orphans( settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads, full_queue_param)
if settings_dict['REMOVE_UNMONITORED']:
items_detected += await remove_unmonitored( settings_dict, radarr_or_sonarr, BASE_URL, API_KEY, deleted_downloads)
items_detected += await remove_unmonitored( settings_dict, arr_type, BASE_URL, API_KEY, deleted_downloads)
if items_detected == 0:
logger.verbose('>>> Queue is clean.')