added trace

pull/431/head
meisnate12 3 years ago
parent 9312c5ec35
commit 54b9d53262

@ -22,15 +22,21 @@ class AniDB:
if params and not self._login(self.username, self.password).xpath("//li[@class='sub-menu my']/@title"): if params and not self._login(self.username, self.password).xpath("//li[@class='sub-menu my']/@title"):
raise Failed("AniDB Error: Login failed") raise Failed("AniDB Error: Login failed")
def _request(self, url, language=None, post=None): def _request(self, url, language=None, data=None):
if post: if self.config.trace_mode:
return self.config.post_html(url, post, headers=util.header(language)) logger.debug(f"URL: {url}")
if data:
return self.config.post_html(url, data=data, headers=util.header(language))
else: else:
return self.config.get_html(url, headers=util.header(language)) return self.config.get_html(url, headers=util.header(language))
def _login(self, username, password): def _login(self, username, password):
data = {"show": "main", "xuser": username, "xpass": password, "xdoautologin": "on"} return self._request(urls["login"], data={
return self._request(urls["login"], post=data) "show": "main",
"xuser": username,
"xpass": password,
"xdoautologin": "on"
})
def _popular(self, language): def _popular(self, language):
response = self._request(urls["popular"], language=language) response = self._request(urls["popular"], language=language)

@ -61,8 +61,13 @@ class AniList:
self.options["Tag Category"][media_tag["category"].lower().replace(" ", "-")] = media_tag["category"] self.options["Tag Category"][media_tag["category"].lower().replace(" ", "-")] = media_tag["category"]
def _request(self, query, variables, level=1): def _request(self, query, variables, level=1):
if self.config.trace_mode:
logger.debug(f"Query: {query}")
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.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

@ -42,6 +42,7 @@ class Config:
self.default_dir = default_dir self.default_dir = default_dir
self.test_mode = attrs["test"] if "test" in attrs else False self.test_mode = attrs["test"] if "test" in attrs else False
self.trace_mode = attrs["trace"] if "trace" in attrs else False
self.run_start_time = attrs["time"] self.run_start_time = attrs["time"]
self.run_hour = datetime.strptime(attrs["time"], "%H:%M").hour self.run_hour = datetime.strptime(attrs["time"], "%H:%M").hour
self.requested_collections = util.get_list(attrs["collections"]) if "collections" in attrs else None self.requested_collections = util.get_list(attrs["collections"]) if "collections" in attrs else None

@ -12,6 +12,8 @@ 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.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):

@ -66,9 +66,12 @@ class IMDb:
parsed_url = urlparse(imdb_url) parsed_url = urlparse(imdb_url)
params = parse_qs(parsed_url.query) params = parse_qs(parsed_url.query)
imdb_base = parsed_url._replace(query=None).geturl() imdb_base = parsed_url._replace(query=None).geturl()
params.pop("start", None) params.pop("start", None) # noqa
params.pop("count", None) params.pop("count", None) # noqa
params.pop("page", None) params.pop("page", None) # noqa
if self.config.trace_mode:
logger.debug(f"URL: {imdb_base}")
logger.debug(f"Params: {params}")
if limit < 1 or total < limit: if limit < 1 or total < limit:
limit = total limit = total
@ -80,10 +83,10 @@ class IMDb:
start_num = (i - 1) * item_count + 1 start_num = (i - 1) * item_count + 1
util.print_return(f"Parsing Page {i}/{num_of_pages} {start_num}-{limit if i == num_of_pages else i * item_count}") util.print_return(f"Parsing Page {i}/{num_of_pages} {start_num}-{limit if i == num_of_pages else i * item_count}")
if imdb_base.startswith((urls["list"], urls["keyword"])): if imdb_base.startswith((urls["list"], urls["keyword"])):
params["page"] = i params["page"] = i # noqa
else: else:
params["count"] = remainder if i == num_of_pages else item_count params["count"] = remainder if i == num_of_pages else item_count # noqa
params["start"] = start_num params["start"] = start_num # noqa
ids_found = self.config.get_html(imdb_base, headers=headers, params=params).xpath(xpath["imdb_id"]) ids_found = self.config.get_html(imdb_base, headers=headers, params=params).xpath(xpath["imdb_id"])
if imdb_base.startswith((urls["list"], urls["keyword"])) and i == num_of_pages: if imdb_base.startswith((urls["list"], urls["keyword"])) and i == num_of_pages:
ids_found = ids_found[:remainder] ids_found = ids_found[:remainder]

@ -12,6 +12,8 @@ class Letterboxd:
self.config = config self.config = config
def _parse_list(self, list_url, language): def _parse_list(self, list_url, language):
if self.config.trace_mode:
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))
letterboxd_ids = response.xpath("//li[contains(@class, 'poster-container')]/div/@data-film-id") letterboxd_ids = response.xpath("//li[contains(@class, 'poster-container')]/div/@data-film-id")
items = [] items = []
@ -25,6 +27,8 @@ class Letterboxd:
return items return items
def _tmdb(self, letterboxd_url, language): def _tmdb(self, letterboxd_url, language):
if self.config.trace_mode:
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]:
@ -34,6 +38,8 @@ 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.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

@ -128,7 +128,11 @@ class MyAnimeList:
def _request(self, url, authorization=None): def _request(self, url, authorization=None):
new_authorization = authorization if authorization else self.authorization new_authorization = authorization if authorization else self.authorization
if self.config.trace_mode:
logger.debug(f"URL: {url}")
response = self.config.get_json(url, headers={"Authorization": f"Bearer {new_authorization['access_token']}"}) response = self.config.get_json(url, headers={"Authorization": f"Bearer {new_authorization['access_token']}"})
if self.config.trace_mode:
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

@ -48,6 +48,8 @@ class OMDb:
omdb_dict, expired = self.config.Cache.query_omdb(imdb_id) omdb_dict, expired = self.config.Cache.query_omdb(imdb_id)
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.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())

@ -202,6 +202,8 @@ class TMDb:
for date_attr in discover_dates: for date_attr in discover_dates:
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.debug(f"Params: {attrs}")
self.Discover.discover_movies(attrs) if is_movie else self.Discover.discover_tv_shows(attrs) self.Discover.discover_movies(attrs) if is_movie else self.Discover.discover_tv_shows(attrs)
total_pages = int(self.TMDb.total_pages) total_pages = int(self.TMDb.total_pages)
total_results = int(self.TMDb.total_results) total_results = int(self.TMDb.total_results)

@ -107,6 +107,8 @@ class Trakt:
output_json = [] output_json = []
pages = 1 pages = 1
current = 1 current = 1
if self.config.trace_mode:
logger.debug(f"URL: {base_url}{url}")
while current <= pages: while current <= pages:
if pages == 1: if pages == 1:
response = self.config.get(f"{base_url}{url}", headers=headers) response = self.config.get(f"{base_url}{url}", headers=headers)
@ -116,6 +118,8 @@ class Trakt:
response = self.config.get(f"{base_url}{url}?page={current}", headers=headers) response = self.config.get(f"{base_url}{url}?page={current}", headers=headers)
if response.status_code == 200: if response.status_code == 200:
json_data = response.json() json_data = response.json()
if self.config.trace_mode:
logger.debug(f"Response: {json_data}")
if isinstance(json_data, dict): if isinstance(json_data, dict):
return json_data return json_data
else: else:

@ -27,6 +27,8 @@ class TVDbObj:
else: else:
raise Failed(f"TVDb Error: {self.tvdb_url} must begin with {urls['movies'] if self.is_movie else urls['series']}") raise Failed(f"TVDb Error: {self.tvdb_url} must begin with {urls['movies'] if self.is_movie else urls['series']}")
if self.config.trace_mode:
logger.debug(f"URL: {tvdb_url}")
response = self.config.get_html(self.tvdb_url, headers=util.header(self.language)) response = self.config.get_html(self.tvdb_url, headers=util.header(self.language))
results = response.xpath(f"//*[text()='TheTVDB.com {self.media_type} ID']/parent::node()/span/text()") results = response.xpath(f"//*[text()='TheTVDB.com {self.media_type} ID']/parent::node()/span/text()")
if len(results) > 0: if len(results) > 0:
@ -111,6 +113,8 @@ 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.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.tvdb_language)) response = self.config.get_html(tvdb_url, headers=util.header(self.tvdb_language))

@ -17,6 +17,7 @@ if sys.version_info[0] != 3 or sys.version_info[1] < 6:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-db", "--debug", dest="debug", help=argparse.SUPPRESS, action="store_true", default=False) parser.add_argument("-db", "--debug", dest="debug", help=argparse.SUPPRESS, action="store_true", default=False)
parser.add_argument("-tr", "--trace", dest="trace", help=argparse.SUPPRESS, action="store_true", default=False)
parser.add_argument("-c", "--config", dest="config", help="Run with desired *.yml file", type=str) parser.add_argument("-c", "--config", dest="config", help="Run with desired *.yml file", type=str)
parser.add_argument("-t", "--time", "--times", dest="times", help="Times to update each day use format HH:MM (Default: 03:00) (comma-separated list)", default="03:00", type=str) parser.add_argument("-t", "--time", "--times", dest="times", help="Times to update each day use format HH:MM (Default: 03:00) (comma-separated list)", default="03:00", type=str)
parser.add_argument("-re", "--resume", dest="resume", help="Resume collection run from a specific collection", type=str) parser.add_argument("-re", "--resume", dest="resume", help="Resume collection run from a specific collection", type=str)
@ -51,6 +52,7 @@ def get_arg(env_str, default, arg_bool=False, arg_int=False):
test = get_arg("PMM_TEST", args.test, arg_bool=True) test = get_arg("PMM_TEST", args.test, arg_bool=True)
debug = get_arg("PMM_DEBUG", args.debug, arg_bool=True) debug = get_arg("PMM_DEBUG", args.debug, arg_bool=True)
trace = get_arg("PMM_TRACE", args.trace, arg_bool=True)
run = get_arg("PMM_RUN", args.run, arg_bool=True) run = get_arg("PMM_RUN", args.run, arg_bool=True)
no_countdown = get_arg("PMM_NO_COUNTDOWN", args.no_countdown, arg_bool=True) no_countdown = get_arg("PMM_NO_COUNTDOWN", args.no_countdown, arg_bool=True)
no_missing = get_arg("PMM_NO_MISSING", args.no_missing, arg_bool=True) no_missing = get_arg("PMM_NO_MISSING", args.no_missing, arg_bool=True)
@ -93,7 +95,7 @@ def fmt_filter(record):
return True return True
cmd_handler = logging.StreamHandler() cmd_handler = logging.StreamHandler()
cmd_handler.setLevel(logging.DEBUG if test or debug else logging.INFO) cmd_handler.setLevel(logging.DEBUG if test or debug or trace else logging.INFO)
logger.addHandler(cmd_handler) logger.addHandler(cmd_handler)
@ -625,7 +627,8 @@ try:
"test": test, "test": test,
"collections": collections, "collections": collections,
"libraries": libraries, "libraries": libraries,
"resume": resume "resume": resume,
"trace": trace
}) })
else: else:
times_to_run = util.get_list(times) times_to_run = util.get_list(times)
@ -639,7 +642,7 @@ try:
else: else:
raise Failed(f"Argument Error: blank time argument") raise Failed(f"Argument Error: blank time argument")
for time_to_run in valid_times: for time_to_run in valid_times:
schedule.every().day.at(time_to_run).do(start, {"config_file": config_file, "time": time_to_run}) schedule.every().day.at(time_to_run).do(start, {"config_file": config_file, "time": time_to_run, "trace": trace})
while True: while True:
schedule.run_pending() schedule.run_pending()
if not no_countdown: if not no_countdown:

Loading…
Cancel
Save