[14] update trace

pull/1024/head
meisnate12 2 years ago
parent 3db3440f5d
commit 2dc36a747e

@ -1 +1 @@
1.17.3-develop13 1.17.3-develop14

@ -73,8 +73,7 @@ class AniDB:
raise Failed("AniDB Error: Login failed") raise Failed("AniDB Error: Login failed")
def _request(self, url, data=None): def _request(self, url, data=None):
if self.config.trace_mode: logger.trace(f"URL: {url}")
logger.debug(f"URL: {url}")
if data: if data:
return self.config.post_html(url, data=data, headers=util.header(self.language)) return self.config.post_html(url, data=data, headers=util.header(self.language))
else: else:

@ -77,13 +77,11 @@ class AniList:
return self._options return self._options
def _request(self, query, variables, level=1): def _request(self, query, variables, level=1):
if self.config.trace_mode: logger.trace(f"Query: {query}")
logger.debug(f"Query: {query}") logger.trace(f"Variables: {variables}")
logger.debug(f"Variables: {variables}")
response = self.config.post(base_url, json={"query": query, "variables": variables}) response = self.config.post(base_url, json={"query": query, "variables": variables})
json_obj = response.json() json_obj = response.json()
if self.config.trace_mode: logger.trace(f"Response: {json_obj}")
logger.debug(f"Response: {json_obj}")
if "errors" in json_obj: if "errors" in json_obj:
if json_obj['errors'][0]['message'] == "Too Many Requests.": if json_obj['errors'][0]['message'] == "Too Many Requests.":
wait_time = int(response.headers["Retry-After"]) if "Retry-After" in response.headers else 0 wait_time = int(response.headers["Retry-After"]) if "Retry-After" in response.headers else 0

@ -40,8 +40,7 @@ class FlixPatrol:
self.config = config self.config = config
def _request(self, url, language, xpath): def _request(self, url, language, xpath):
if self.config.trace_mode: logger.trace(f"URL: {url}")
logger.debug(f"URL: {url}")
return self.config.get_html(url, headers=util.header(language)).xpath(xpath) return self.config.get_html(url, headers=util.header(language)).xpath(xpath)
def _tmdb(self, flixpatrol_url, language): def _tmdb(self, flixpatrol_url, language):

@ -11,8 +11,7 @@ class ICheckMovies:
self.config = config self.config = config
def _request(self, url, language, xpath): def _request(self, url, language, xpath):
if self.config.trace_mode: logger.trace(f"URL: {url}")
logger.debug(f"URL: {url}")
return self.config.get_html(url, headers=util.header(language)).xpath(xpath) return self.config.get_html(url, headers=util.header(language)).xpath(xpath)
def _parse_list(self, list_url, language): def _parse_list(self, list_url, language):

@ -124,9 +124,8 @@ class IMDb:
params.pop("start", None) # noqa params.pop("start", None) # noqa
params.pop("count", None) # noqa params.pop("count", None) # noqa
params.pop("page", None) # noqa params.pop("page", None) # noqa
if self.config.trace_mode: logger.trace(f"URL: {imdb_base}")
logger.debug(f"URL: {imdb_base}") logger.trace(f"Params: {params}")
logger.debug(f"Params: {params}")
search_url = imdb_base.startswith(urls["searches"]) search_url = imdb_base.startswith(urls["searches"])
if limit < 1 or total < limit: if limit < 1 or total < limit:
limit = total limit = total

@ -32,8 +32,7 @@ class Letterboxd:
return items, next_url return items, next_url
def _parse_list(self, list_url, limit, language): def _parse_list(self, list_url, limit, language):
if self.config.trace_mode: logger.trace(f"URL: {list_url}")
logger.debug(f"URL: {list_url}")
items, next_url = self._parse_page(list_url, language) items, next_url = self._parse_page(list_url, language)
while len(next_url) > 0: while len(next_url) > 0:
time.sleep(2) time.sleep(2)
@ -44,8 +43,7 @@ class Letterboxd:
return items return items
def _tmdb(self, letterboxd_url, language): def _tmdb(self, letterboxd_url, language):
if self.config.trace_mode: logger.trace(f"URL: {letterboxd_url}")
logger.debug(f"URL: {letterboxd_url}")
response = self.config.get_html(letterboxd_url, headers=util.header(language)) response = self.config.get_html(letterboxd_url, headers=util.header(language))
ids = response.xpath("//a[@data-track-action='TMDb']/@href") ids = response.xpath("//a[@data-track-action='TMDb']/@href")
if len(ids) > 0 and ids[0]: if len(ids) > 0 and ids[0]:
@ -55,8 +53,7 @@ class Letterboxd:
raise Failed(f"Letterboxd Error: TMDb Movie ID not found at {letterboxd_url}") raise Failed(f"Letterboxd Error: TMDb Movie ID not found at {letterboxd_url}")
def get_list_description(self, list_url, language): def get_list_description(self, list_url, language):
if self.config.trace_mode: logger.trace(f"URL: {list_url}")
logger.debug(f"URL: {list_url}")
response = self.config.get_html(list_url, headers=util.header(language)) response = self.config.get_html(list_url, headers=util.header(language))
descriptions = response.xpath("//meta[@property='og:description']/@content") descriptions = response.xpath("//meta[@property='og:description']/@content")
return descriptions[0] if len(descriptions) > 0 and len(descriptions[0]) > 0 else None return descriptions[0] if len(descriptions) > 0 and len(descriptions[0]) > 0 else None

@ -28,12 +28,13 @@ _srcfile = os.path.normcase(fmt_filter.__code__.co_filename)
class MyLogger: class MyLogger:
def __init__(self, logger_name, default_dir, screen_width, separating_character, ignore_ghost, is_debug): def __init__(self, logger_name, default_dir, screen_width, separating_character, ignore_ghost, is_debug, is_trace):
self.logger_name = logger_name self.logger_name = logger_name
self.default_dir = default_dir self.default_dir = default_dir
self.screen_width = screen_width self.screen_width = screen_width
self.separating_character = separating_character self.separating_character = separating_character
self.is_debug = is_debug self.is_debug = is_debug
self.is_trace = is_trace
self.ignore_ghost = ignore_ghost self.ignore_ghost = ignore_ghost
self.log_dir = os.path.join(default_dir, LOG_DIR) self.log_dir = os.path.join(default_dir, LOG_DIR)
self.playlists_dir = os.path.join(self.log_dir, PLAYLIST_DIR) self.playlists_dir = os.path.join(self.log_dir, PLAYLIST_DIR)
@ -136,7 +137,9 @@ class MyLogger:
final_text = f"{text}{sep * side}{sep * side}" if left else f"{sep * side}{text}{sep * side}" final_text = f"{text}{sep * side}{sep * side}" if left else f"{sep * side}{text}{sep * side}"
return final_text return final_text
def separator(self, text=None, space=True, border=True, debug=False, side_space=True, left=False): def separator(self, text=None, space=True, border=True, debug=False, trace=False, side_space=True, left=False):
if trace and not self.is_trace:
return None
sep = " " if space else self.separating_character sep = " " if space else self.separating_character
for handler in self._logger.handlers: for handler in self._logger.handlers:
self._formatter(handler, border=False) self._formatter(handler, border=False)
@ -148,10 +151,13 @@ class MyLogger:
if text: if text:
text_list = text.split("\n") text_list = text.split("\n")
for t in text_list: for t in text_list:
if debug: msg = f"|{sep}{self._centered(t, sep=sep, side_space=side_space, left=left)}{sep}|"
self.debug(f"|{sep}{self._centered(t, sep=sep, side_space=side_space, left=left)}{sep}|") if trace:
self.trace(msg)
elif debug:
self.debug(msg)
else: else:
self.info(f"|{sep}{self._centered(t, sep=sep, side_space=side_space, left=left)}{sep}|") self.info(msg)
if border and debug: if border and debug:
self.debug(border_text) self.debug(border_text)
elif border: elif border:
@ -174,6 +180,10 @@ class MyLogger:
if self._logger.isEnabledFor(WARNING): if self._logger.isEnabledFor(WARNING):
self._log(WARNING, str(msg), args, **kwargs) self._log(WARNING, str(msg), args, **kwargs)
def trace(self, msg, *args, **kwargs):
if self.is_trace:
self._log(DEBUG, str(msg), args, **kwargs)
def error(self, msg, *args, **kwargs): def error(self, msg, *args, **kwargs):
if self.save_errors: if self.save_errors:
self.saved_errors.append(msg) self.saved_errors.append(msg)
@ -186,7 +196,10 @@ class MyLogger:
if self._logger.isEnabledFor(CRITICAL): if self._logger.isEnabledFor(CRITICAL):
self._log(CRITICAL, str(msg), args, **kwargs) self._log(CRITICAL, str(msg), args, **kwargs)
def stacktrace(self): def stacktrace(self, trace=False):
if trace:
self.trace(traceback.format_exc())
else:
self.debug(traceback.format_exc()) self.debug(traceback.format_exc())
def _space(self, display_title): def _space(self, display_title):

@ -162,12 +162,10 @@ class MyAnimeList:
def _request(self, url, authorization=None): def _request(self, url, authorization=None):
token = authorization["access_token"] if authorization else self.authorization["access_token"] token = authorization["access_token"] if authorization else self.authorization["access_token"]
if self.config.trace_mode: logger.trace(f"URL: {url}")
logger.debug(f"URL: {url}")
try: try:
response = self.config.get_json(url, headers={"Authorization": f"Bearer {token}"}) response = self.config.get_json(url, headers={"Authorization": f"Bearer {token}"})
if self.config.trace_mode: logger.trace(f"Response: {response}")
logger.debug(f"Response: {response}")
if "error" in response: raise Failed(f"MyAnimeList Error: {response['error']}") if "error" in response: raise Failed(f"MyAnimeList Error: {response['error']}")
else: return response else: return response
except JSONDecodeError: except JSONDecodeError:

@ -101,9 +101,8 @@ class Mdblist:
mdb_dict, expired = self.config.Cache.query_mdb(key, self.expiration) mdb_dict, expired = self.config.Cache.query_mdb(key, self.expiration)
if mdb_dict and expired is False: if mdb_dict and expired is False:
return MDbObj(mdb_dict) return MDbObj(mdb_dict)
if self.config.trace_mode: logger.trace(f"ID: {key}")
logger.debug(f"ID: {key}") logger.trace(f"Params: {params}")
logger.debug(f"Params: {params}")
try: try:
response = self.config.get_json(api_url, params=params) response = self.config.get_json(api_url, params=params)
except JSONDecodeError: except JSONDecodeError:

@ -31,7 +31,6 @@ class Notifiarr:
def get_url(self, path): def get_url(self, path):
url = f"{dev_url if self.develop else base_url}{'notification/test' if self.test else f'{path}{self.apikey}'}" url = f"{dev_url if self.develop else base_url}{'notification/test' if self.test else f'{path}{self.apikey}'}"
if self.config.trace_mode: logger.trace(url)
logger.debug(url)
params = {"event": "pmm"} if self.test else None params = {"event": "pmm"} if self.test else None
return url, params return url, params

@ -56,8 +56,7 @@ class OMDb:
omdb_dict, expired = self.config.Cache.query_omdb(imdb_id, self.expiration) omdb_dict, expired = self.config.Cache.query_omdb(imdb_id, self.expiration)
if omdb_dict and expired is False: if omdb_dict and expired is False:
return OMDbObj(imdb_id, omdb_dict) return OMDbObj(imdb_id, omdb_dict)
if self.config.trace_mode: logger.trace(f"IMDb ID: {imdb_id}")
logger.debug(f"IMDb ID: {imdb_id}")
response = self.config.get(base_url, params={"i": imdb_id, "apikey": self.apikey}) response = self.config.get(base_url, params={"i": imdb_id, "apikey": self.apikey})
if response.status_code < 400: if response.status_code < 400:
omdb = OMDbObj(imdb_id, response.json()) omdb = OMDbObj(imdb_id, response.json())

@ -178,28 +178,28 @@ class Operations:
try: try:
mdb_item = self.config.Mdblist.get_series(tvdb_id) mdb_item = self.config.Mdblist.get_series(tvdb_id)
except Failed as e: except Failed as e:
logger.error(str(e)) logger.trace(str(e))
except Exception: except Exception:
logger.error(f"TVDb ID: {tvdb_id}") logger.trace(f"TVDb ID: {tvdb_id}")
raise raise
if tmdb_id and mdb_item is None: if tmdb_id and mdb_item is None:
try: try:
mdb_item = self.config.Mdblist.get_movie(tmdb_id) mdb_item = self.config.Mdblist.get_movie(tmdb_id)
except Failed as e: except Failed as e:
logger.error(str(e)) logger.trace(str(e))
except Exception: except Exception:
logger.error(f"TMDb ID: {tmdb_id}") logger.trace(f"TMDb ID: {tmdb_id}")
raise raise
if imdb_id and mdb_item is None: if imdb_id and mdb_item is None:
try: try:
mdb_item = self.config.Mdblist.get_imdb(imdb_id) mdb_item = self.config.Mdblist.get_imdb(imdb_id)
except Failed as e: except Failed as e:
logger.error(str(e)) logger.trace(str(e))
except Exception: except Exception:
logger.error(f"IMDb ID: {imdb_id}") logger.trace(f"IMDb ID: {imdb_id}")
raise raise
if mdb_item is None: if mdb_item is None:
logger.info(f"No TMDb ID, TVDb ID, or IMDb ID for Guid: {item.guid}") logger.warning(f"No TMDb ID, TVDb ID, or IMDb ID for Guid: {item.guid}")
def get_rating(attribute): def get_rating(attribute):
if tmdb_item and attribute == "tmdb": if tmdb_item and attribute == "tmdb":

@ -224,8 +224,7 @@ class Overlays:
else: else:
actual_attr = format_var actual_attr = format_var
if not hasattr(item, actual_attr) or getattr(item, actual_attr) is None: if not hasattr(item, actual_attr) or getattr(item, actual_attr) is None:
logger.warning(f"Overlay Warning: No {full_text} found") raise Failed(f"Overlay Warning: No {full_text} found")
continue
actual_value = getattr(item, actual_attr) actual_value = getattr(item, actual_attr)
if self.config.Cache: if self.config.Cache:
cache_store = actual_value.strftime("%Y-%m-%d") if format_var in overlay.date_vars else actual_value cache_store = actual_value.strftime("%Y-%m-%d") if format_var in overlay.date_vars else actual_value

@ -817,8 +817,7 @@ class Plex(Library):
logger.warning(f"Plex Warning: {item.title} has no Season 1 Episode 1 ") logger.warning(f"Plex Warning: {item.title} has no Season 1 Episode 1 ")
elif method == "plex_search": elif method == "plex_search":
logger.info(f"Processing {data[1]}") logger.info(f"Processing {data[1]}")
if self.config.trace_mode: logger.trace(data[2])
logger.debug(data[2])
items = self.get_filter_items(data[2]) items = self.get_filter_items(data[2])
elif method == "plex_collectionless": elif method == "plex_collectionless":
good_collections = [] good_collections = []

@ -65,9 +65,8 @@ class Radarr:
if movie.path: if movie.path:
arr_paths[movie.path[:-1].lower() if movie.path.endswith(("/", "\\")) else movie.path.lower()] = movie.tmdbId arr_paths[movie.path[:-1].lower() if movie.path.endswith(("/", "\\")) else movie.path.lower()] = movie.tmdbId
arr_ids[movie.tmdbId] = movie arr_ids[movie.tmdbId] = movie
if self.config.trace_mode: logger.trace(arr_paths)
logger.debug(arr_paths) logger.trace(arr_ids)
logger.debug(arr_ids)
added = [] added = []
exists = [] exists = []
@ -110,8 +109,7 @@ class Radarr:
invalid_root.append(item) invalid_root.append(item)
continue continue
movie = self.api.get_movie(tmdb_id=tmdb_id) movie = self.api.get_movie(tmdb_id=tmdb_id)
if self.config.trace_mode: logger.trace(f"Folder to Check: {folder}/{movie.folder}")
logger.debug(f"Folder to Check: {folder}/{movie.folder}")
if f"{folder}/{movie.folder}".lower() in arr_paths: if f"{folder}/{movie.folder}".lower() in arr_paths:
path_in_use[f"{folder}/{movie.folder}"] = tmdb_id path_in_use[f"{folder}/{movie.folder}"] = tmdb_id
continue continue

@ -91,9 +91,8 @@ class Sonarr:
if series.path: if series.path:
arr_paths[series.path[:-1].lower() if series.path.endswith(("/", "\\")) else series.path.lower()] = series.tvdbId arr_paths[series.path[:-1].lower() if series.path.endswith(("/", "\\")) else series.path.lower()] = series.tvdbId
arr_ids[series.tvdbId] = series arr_ids[series.tvdbId] = series
if self.config.trace_mode: logger.trace(arr_paths)
logger.debug(arr_paths) logger.trace(arr_ids)
logger.debug(arr_ids)
added = [] added = []
exists = [] exists = []
@ -136,8 +135,7 @@ class Sonarr:
invalid_root.append(item) invalid_root.append(item)
continue continue
show = self.api.get_series(tvdb_id=tvdb_id) show = self.api.get_series(tvdb_id=tvdb_id)
if self.config.trace_mode: logger.trace(f"Folder to Check: {folder}/{show.folder}")
logger.debug(f"Folder to Check: {folder}/{show.folder}")
if f"{folder}/{show.folder}".lower() in arr_paths: if f"{folder}/{show.folder}".lower() in arr_paths:
path_in_use[f"{folder}/{show.folder}"] = tvdb_id path_in_use[f"{folder}/{show.folder}"] = tvdb_id
continue continue

@ -60,6 +60,5 @@ class Tautulli:
return rating_keys return rating_keys
def _request(self, url): def _request(self, url):
if self.config.trace_mode: logger.trace(f"Tautulli URL: {url}")
logger.debug(f"Tautulli URL: {url}")
return self.config.get_json(url) return self.config.get_json(url)

@ -331,8 +331,7 @@ class TMDb:
for date_attr in date_methods: for date_attr in date_methods:
if date_attr in attrs: if date_attr in attrs:
attrs[date_attr] = util.validate_date(attrs[date_attr], f"tmdb_discover attribute {date_attr}", return_as="%Y-%m-%d") attrs[date_attr] = util.validate_date(attrs[date_attr], f"tmdb_discover attribute {date_attr}", return_as="%Y-%m-%d")
if self.config.trace_mode: logger.trace(f"Params: {attrs}")
logger.debug(f"Params: {attrs}")
results = self.TMDb.discover_movies(**attrs) if is_movie else self.TMDb.discover_tv_shows(**attrs) results = self.TMDb.discover_movies(**attrs) if is_movie else self.TMDb.discover_tv_shows(**attrs)
amount = results.total_results if limit == 0 or results.total_results < limit else limit amount = results.total_results if limit == 0 or results.total_results < limit else limit
ids = [(i.id, result_type) for i in results.get_results(amount)] ids = [(i.id, result_type) for i in results.get_results(amount)]

@ -141,8 +141,7 @@ class Trakt:
raise Failed(f"Trakt Error: ({response.status_code}) {response.reason}") raise Failed(f"Trakt Error: ({response.status_code}) {response.reason}")
#raise Failed("Trakt Error: Invalid trakt pin. If you're sure you typed it in correctly your client_id or client_secret may be invalid") #raise Failed("Trakt Error: Invalid trakt pin. If you're sure you typed it in correctly your client_id or client_secret may be invalid")
response_json = response.json() response_json = response.json()
if self.config.trace_mode: logger.trace(response_json)
logger.debug(response_json)
if not self._save(response_json): if not self._save(response_json):
raise Failed("Trakt Error: New Authorization Failed") raise Failed("Trakt Error: New Authorization Failed")
@ -210,12 +209,11 @@ class Trakt:
params = {} params = {}
pages = 1 pages = 1
current = 1 current = 1
if self.config.trace_mode: logger.trace(f"URL: {base_url}{url}")
logger.debug(f"URL: {base_url}{url}")
if params: if params:
logger.debug(f"Params: {params}") logger.trace(f"Params: {params}")
if json: if json:
logger.debug(f"JSON: {json}") logger.trace(f"JSON: {json}")
while current <= pages: while current <= pages:
if pages > 1: if pages > 1:
params["page"] = current params["page"] = current
@ -228,9 +226,8 @@ class Trakt:
if response.status_code >= 400: if response.status_code >= 400:
raise Failed(f"({response.status_code}) {response.reason}") raise Failed(f"({response.status_code}) {response.reason}")
json_data = response.json() json_data = response.json()
if self.config.trace_mode: logger.trace(f"Headers: {response.headers}")
logger.debug(f"Headers: {response.headers}") logger.trace(f"Response: {json_data}")
logger.debug(f"Response: {json_data}")
if isinstance(json_data, dict): if isinstance(json_data, dict):
return json_data return json_data
else: else:

@ -136,8 +136,7 @@ class TVDb:
tvdb_id, expired = self.config.Cache.query_tvdb_map(tvdb_url, self.expiration) tvdb_id, expired = self.config.Cache.query_tvdb_map(tvdb_url, self.expiration)
if tvdb_id and not expired and not is_movie: if tvdb_id and not expired and not is_movie:
return tvdb_id, None, None return tvdb_id, None, None
if self.config.trace_mode: logger.trace(f"URL: {tvdb_url}")
logger.debug(f"URL: {tvdb_url}")
try: try:
response = self.get_request(tvdb_url) response = self.get_request(tvdb_url)
except ParserError: except ParserError:
@ -176,8 +175,7 @@ class TVDb:
def _ids_from_url(self, tvdb_url): def _ids_from_url(self, tvdb_url):
ids = [] ids = []
tvdb_url = tvdb_url.strip() tvdb_url = tvdb_url.strip()
if self.config.trace_mode: logger.trace(f"URL: {tvdb_url}")
logger.debug(f"URL: {tvdb_url}")
if tvdb_url.startswith((urls["list"], urls["alt_list"])): if tvdb_url.startswith((urls["list"], urls["alt_list"])):
try: try:
response = self.config.get_html(tvdb_url, headers=util.header(self.language)) response = self.config.get_html(tvdb_url, headers=util.header(self.language))

@ -15,14 +15,12 @@ class Webhooks:
self.notifiarr = notifiarr self.notifiarr = notifiarr
def _request(self, webhooks, json): def _request(self, webhooks, json):
if self.config.trace_mode: logger.separator("Webhooks", space=False, border=False, trace=True)
logger.separator("Webhooks", space=False, border=False, debug=True) logger.trace("")
logger.debug("") logger.trace(f"JSON: {json}")
logger.debug(f"JSON: {json}")
for webhook in list(set(webhooks)): for webhook in list(set(webhooks)):
response = None response = None
if self.config.trace_mode: logger.trace(f"Webhook: {webhook}")
logger.debug(f"Webhook: {webhook}")
if webhook == "notifiarr": if webhook == "notifiarr":
if self.notifiarr: if self.notifiarr:
url, params = self.notifiarr.get_url("notification/pmm/") url, params = self.notifiarr.get_url("notification/pmm/")
@ -39,8 +37,7 @@ class Webhooks:
if response: if response:
try: try:
response_json = response.json() response_json = response.json()
if self.config.trace_mode: logger.trace(f"Response: {response_json}")
logger.debug(f"Response: {response_json}")
if webhook == "notifiarr" and self.notifiarr and response.status_code == 400: if webhook == "notifiarr" and self.notifiarr and response.status_code == 400:
def remove_from_config(text, hook_cat): def remove_from_config(text, hook_cat):
if response_json["details"]["response"] == text: if response_json["details"]["response"] == text:

@ -111,7 +111,7 @@ elif not os.path.exists(os.path.join(default_dir, "config.yml")):
print(f"Config Error: config not found at {os.path.abspath(default_dir)}") print(f"Config Error: config not found at {os.path.abspath(default_dir)}")
sys.exit(0) sys.exit(0)
logger = MyLogger("Plex Meta Manager", default_dir, screen_width, divider[0], ignore_ghost, test or debug or trace) logger = MyLogger("Plex Meta Manager", default_dir, screen_width, divider[0], ignore_ghost, test or debug, trace)
from modules import util from modules import util
util.logger = logger util.logger = logger

Loading…
Cancel
Save