Log outpout tweaking

pull/5/head
desimaniac 7 years ago
parent f9aa7ebe04
commit 6c118e743f

@ -1,5 +1,5 @@
# Traktarr # Traktarr
Script to add new TV series & movies to Sonarr/Radarr based on Trakt lists. Script to add new shows & movies to Sonarr/Radarr based on Trakt lists.
# Requirements # Requirements
1. Python 3.5 or higher (`sudo apt install python3 python3-pip`). 1. Python 3.5 or higher (`sudo apt install python3 python3-pip`).
@ -127,21 +127,21 @@ Options:
``` ```
## TV Shows ## Shows
``` ```
Usage: python3 traktarr.py shows [OPTIONS] Usage: python3 traktarr.py shows [OPTIONS]
Add new series to Sonarr. Add new shows to Sonarr.
Options: Options:
-t, --list-type [anticipated|trending|popular] -t, --list-type [anticipated|trending|popular]
Trakt list to process. [required] Trakt list to process. [required]
-l, --add-limit INTEGER Limit number of series added to Sonarr. -l, --add-limit INTEGER Limit number of shows added to Sonarr.
[default: 0] [default: 0]
-d, --add-delay FLOAT Seconds between each add request to Sonarr. -d, --add-delay FLOAT Seconds between each add request to Sonarr.
[default: 2.5] [default: 2.5]
--no-search Disable search when adding series to Sonarr. --no-search Disable search when adding shows to Sonarr.
--help Show this message and exit. --help Show this message and exit.
``` ```

@ -46,12 +46,12 @@ class Sonarr:
if req.status_code == 200: if req.status_code == 200:
resp_json = req.json() resp_json = req.json()
log.debug("Found %d series", len(resp_json)) log.debug("Found %d shows", len(resp_json))
return resp_json return resp_json
else: else:
log.error("Failed to retrieve all series, request response: %d", req.status_code) log.error("Failed to retrieve all shows, request response: %d", req.status_code)
except Exception: except Exception:
log.exception("Exception retrieving series: ") log.exception("Exception retrieving show: ")
return None return None
@backoff.on_predicate(backoff.expo, lambda x: x is None, max_tries=4, on_backoff=backoff_handler) @backoff.on_predicate(backoff.expo, lambda x: x is None, max_tries=4, on_backoff=backoff_handler)
@ -105,5 +105,5 @@ class Sonarr:
log.error("Failed to add %s (%d), unexpected response:\n%s", series_title, series_tvdbid, req.text) log.error("Failed to add %s (%d), unexpected response:\n%s", series_title, series_tvdbid, req.text)
return False return False
except Exception: except Exception:
log.exception("Exception adding series %s (%d): ", series_title, series_tvdbid) log.exception("Exception adding show %s (%d): ", series_title, series_tvdbid)
return None return None

@ -13,12 +13,12 @@ def sonarr_series_to_tvdb_dict(sonarr_series):
try: try:
for tmp in sonarr_series: for tmp in sonarr_series:
if 'tvdbId' not in tmp: if 'tvdbId' not in tmp:
log.debug("Could not handle series: %s", tmp['title']) log.debug("Could not handle show: %s", tmp['title'])
continue continue
series[tmp['tvdbId']] = tmp series[tmp['tvdbId']] = tmp
return series return series
except Exception: except Exception:
log.exception("Exception processing sonarr series to tvdb dict: ") log.exception("Exception processing Sonarr shows to TVDB dict: ")
return None return None
@ -47,11 +47,11 @@ def sonarr_remove_existing_series(sonarr_series, trakt_series):
new_series_list.append(tmp) new_series_list.append(tmp)
log.debug("Filtered %d trakt shows to %d shows that weren't already in Sonarr", len(trakt_series), log.debug("Filtered %d Trakt shows to %d shows that weren't already in Sonarr", len(trakt_series),
len(new_series_list)) len(new_series_list))
return new_series_list return new_series_list
except Exception: except Exception:
log.exception("Exception removing existing series from trakt list: ") log.exception("Exception removing existing show from Trakt list: ")
return None return None
@ -173,7 +173,7 @@ def radarr_movies_to_tmdb_dict(radarr_movies):
movies[tmp['tmdbId']] = tmp movies[tmp['tmdbId']] = tmp
return movies return movies
except Exception: except Exception:
log.exception("Exception processing radarr movies to tmdb dict: ") log.exception("Exception processing Radarr movies to TMDB dict: ")
return None return None
@ -202,11 +202,11 @@ def radarr_remove_existing_movies(radarr_movies, trakt_movies):
new_movies_list.append(tmp) new_movies_list.append(tmp)
log.debug("Filtered %d trakt movies to %d movies that weren't already in Radarr", len(trakt_movies), log.debug("Filtered %d Trakt movies to %d movies that weren't already in Radarr", len(trakt_movies),
len(new_movies_list)) len(new_movies_list))
return new_movies_list return new_movies_list
except Exception: except Exception:
log.exception("Exception removing existing movies from trakt list: ") log.exception("Exception removing existing movies from Trakt list: ")
return None return None

@ -19,7 +19,7 @@ log = logger.get_logger('traktarr')
# Click # Click
@click.group(help='Add new series/movies to Sonarr & Radarr from Trakt.') @click.group(help='Add new shows & movies to Sonarr/Radarr from Trakt lists.')
def app(): def app():
pass pass
@ -28,12 +28,12 @@ def app():
# SHOWS # SHOWS
############################################################ ############################################################
@app.command(help='Add new series to Sonarr.') @app.command(help='Add new shows to Sonarr.')
@click.option('--list-type', '-t', type=click.Choice(['anticipated', 'trending', 'popular']), @click.option('--list-type', '-t', type=click.Choice(['anticipated', 'trending', 'popular']),
help='Trakt list to process.', required=True) help='Trakt list to process.', required=True)
@click.option('--add-limit', '-l', default=0, help='Limit number of series added to Sonarr.', show_default=True) @click.option('--add-limit', '-l', default=0, help='Limit number of shows added to Sonarr.', show_default=True)
@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr.', show_default=True) @click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr.', show_default=True)
@click.option('--no-search', is_flag=True, help='Disable search when adding series to Sonarr.') @click.option('--no-search', is_flag=True, help='Disable search when adding shows to Sonarr.')
def shows(list_type, add_limit=0, add_delay=2.5, no_search=False): def shows(list_type, add_limit=0, add_delay=2.5, no_search=False):
added_shows = 0 added_shows = 0
@ -64,10 +64,10 @@ def shows(list_type, add_limit=0, add_delay=2.5, no_search=False):
# get sonarr series list # get sonarr series list
sonarr_series_list = sonarr.get_series() sonarr_series_list = sonarr.get_series()
if not sonarr_series_list: if not sonarr_series_list:
log.error("Aborting due to failure to retrieve Sonarr series list") log.error("Aborting due to failure to retrieve Sonarr shows list")
return return
else: else:
log.info("Retrieved Sonarr series list, series found: %d", len(sonarr_series_list)) log.info("Retrieved Sonarr shows list, shows found: %d", len(sonarr_series_list))
# get trakt series list # get trakt series list
trakt_series_list = None trakt_series_list = None
@ -81,23 +81,23 @@ def shows(list_type, add_limit=0, add_delay=2.5, no_search=False):
log.error("Aborting due to unknown Trakt list type") log.error("Aborting due to unknown Trakt list type")
return return
if not trakt_series_list: if not trakt_series_list:
log.error("Aborting due to failure to retrieve Trakt %s series list", list_type) log.error("Aborting due to failure to retrieve Trakt %s shows list", list_type)
return return
else: else:
log.info("Retrieved Trakt %s series list, series found: %d", list_type, len(trakt_series_list)) log.info("Retrieved Trakt %s shows list, shows found: %d", list_type, len(trakt_series_list))
# build filtered series list without series that exist in sonarr # build filtered series list without series that exist in sonarr
processed_series_list = helpers.sonarr_remove_existing_series(sonarr_series_list, trakt_series_list) processed_series_list = helpers.sonarr_remove_existing_series(sonarr_series_list, trakt_series_list)
if not processed_series_list: if not processed_series_list:
log.error("Aborting due to failure to remove existing Sonarr series from retrieved Trakt series list") log.error("Aborting due to failure to remove existing Sonarr shows from retrieved Trakt shows list")
return return
else: else:
log.info("Removed existing Sonarr series from Trakt series list, series left to process: %d", log.info("Removed existing Sonarr shows from Trakt shows list, shows left to process: %d",
len(processed_series_list)) len(processed_series_list))
# sort filtered series list by highest votes # sort filtered series list by highest votes
sorted_series_list = sorted(processed_series_list, key=lambda k: k['show']['votes'], reverse=True) sorted_series_list = sorted(processed_series_list, key=lambda k: k['show']['votes'], reverse=True)
log.info("Sorted series list to process by highest votes") log.info("Sorted shows list to process by highest votes")
# loop series_list # loop series_list
log.info("Processing list now...") log.info("Processing list now...")
@ -125,7 +125,7 @@ def shows(list_type, add_limit=0, add_delay=2.5, no_search=False):
time.sleep(add_delay) time.sleep(add_delay)
except Exception: except Exception:
log.exception("Exception while processing series %s: ", series['show']['title']) log.exception("Exception while processing show %s: ", series['show']['title'])
log.info("Added %d new shows to Sonarr", added_shows) log.info("Added %d new shows to Sonarr", added_shows)

Loading…
Cancel
Save