[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")
def _request(self, url, data=None):
if self.config.trace_mode:
logger.debug(f"URL: {url}")
logger.trace(f"URL: {url}")
if data:
return self.config.post_html(url, data=data, headers=util.header(self.language))
else:

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

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

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

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

@ -32,8 +32,7 @@ class Letterboxd:
return items, next_url
def _parse_list(self, list_url, limit, language):
if self.config.trace_mode:
logger.debug(f"URL: {list_url}")
logger.trace(f"URL: {list_url}")
items, next_url = self._parse_page(list_url, language)
while len(next_url) > 0:
time.sleep(2)
@ -44,8 +43,7 @@ class Letterboxd:
return items
def _tmdb(self, letterboxd_url, language):
if self.config.trace_mode:
logger.debug(f"URL: {letterboxd_url}")
logger.trace(f"URL: {letterboxd_url}")
response = self.config.get_html(letterboxd_url, headers=util.header(language))
ids = response.xpath("//a[@data-track-action='TMDb']/@href")
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}")
def get_list_description(self, list_url, language):
if self.config.trace_mode:
logger.debug(f"URL: {list_url}")
logger.trace(f"URL: {list_url}")
response = self.config.get_html(list_url, headers=util.header(language))
descriptions = response.xpath("//meta[@property='og:description']/@content")
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:
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.default_dir = default_dir
self.screen_width = screen_width
self.separating_character = separating_character
self.is_debug = is_debug
self.is_trace = is_trace
self.ignore_ghost = ignore_ghost
self.log_dir = os.path.join(default_dir, LOG_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}"
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
for handler in self._logger.handlers:
self._formatter(handler, border=False)
@ -148,10 +151,13 @@ class MyLogger:
if text:
text_list = text.split("\n")
for t in text_list:
if debug:
self.debug(f"|{sep}{self._centered(t, sep=sep, side_space=side_space, left=left)}{sep}|")
msg = 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:
self.info(f"|{sep}{self._centered(t, sep=sep, side_space=side_space, left=left)}{sep}|")
self.info(msg)
if border and debug:
self.debug(border_text)
elif border:
@ -174,6 +180,10 @@ class MyLogger:
if self._logger.isEnabledFor(WARNING):
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):
if self.save_errors:
self.saved_errors.append(msg)
@ -186,8 +196,11 @@ class MyLogger:
if self._logger.isEnabledFor(CRITICAL):
self._log(CRITICAL, str(msg), args, **kwargs)
def stacktrace(self):
self.debug(traceback.format_exc())
def stacktrace(self, trace=False):
if trace:
self.trace(traceback.format_exc())
else:
self.debug(traceback.format_exc())
def _space(self, display_title):
display_title = str(display_title)

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

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

@ -31,7 +31,6 @@ class Notifiarr:
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}'}"
if self.config.trace_mode:
logger.debug(url)
logger.trace(url)
params = {"event": "pmm"} if self.test else None
return url, params

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

@ -178,28 +178,28 @@ class Operations:
try:
mdb_item = self.config.Mdblist.get_series(tvdb_id)
except Failed as e:
logger.error(str(e))
logger.trace(str(e))
except Exception:
logger.error(f"TVDb ID: {tvdb_id}")
logger.trace(f"TVDb ID: {tvdb_id}")
raise
if tmdb_id and mdb_item is None:
try:
mdb_item = self.config.Mdblist.get_movie(tmdb_id)
except Failed as e:
logger.error(str(e))
logger.trace(str(e))
except Exception:
logger.error(f"TMDb ID: {tmdb_id}")
logger.trace(f"TMDb ID: {tmdb_id}")
raise
if imdb_id and mdb_item is None:
try:
mdb_item = self.config.Mdblist.get_imdb(imdb_id)
except Failed as e:
logger.error(str(e))
logger.trace(str(e))
except Exception:
logger.error(f"IMDb ID: {imdb_id}")
logger.trace(f"IMDb ID: {imdb_id}")
raise
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):
if tmdb_item and attribute == "tmdb":

@ -224,8 +224,7 @@ class Overlays:
else:
actual_attr = format_var
if not hasattr(item, actual_attr) or getattr(item, actual_attr) is None:
logger.warning(f"Overlay Warning: No {full_text} found")
continue
raise Failed(f"Overlay Warning: No {full_text} found")
actual_value = getattr(item, actual_attr)
if self.config.Cache:
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 ")
elif method == "plex_search":
logger.info(f"Processing {data[1]}")
if self.config.trace_mode:
logger.debug(data[2])
logger.trace(data[2])
items = self.get_filter_items(data[2])
elif method == "plex_collectionless":
good_collections = []

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

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

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

@ -331,8 +331,7 @@ class TMDb:
for date_attr in date_methods:
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")
if self.config.trace_mode:
logger.debug(f"Params: {attrs}")
logger.trace(f"Params: {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
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("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()
if self.config.trace_mode:
logger.debug(response_json)
logger.trace(response_json)
if not self._save(response_json):
raise Failed("Trakt Error: New Authorization Failed")
@ -210,12 +209,11 @@ class Trakt:
params = {}
pages = 1
current = 1
if self.config.trace_mode:
logger.debug(f"URL: {base_url}{url}")
if params:
logger.debug(f"Params: {params}")
if json:
logger.debug(f"JSON: {json}")
logger.trace(f"URL: {base_url}{url}")
if params:
logger.trace(f"Params: {params}")
if json:
logger.trace(f"JSON: {json}")
while current <= pages:
if pages > 1:
params["page"] = current
@ -228,9 +226,8 @@ class Trakt:
if response.status_code >= 400:
raise Failed(f"({response.status_code}) {response.reason}")
json_data = response.json()
if self.config.trace_mode:
logger.debug(f"Headers: {response.headers}")
logger.debug(f"Response: {json_data}")
logger.trace(f"Headers: {response.headers}")
logger.trace(f"Response: {json_data}")
if isinstance(json_data, dict):
return json_data
else:

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

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

Loading…
Cancel
Save