Skip to content

Commit

Permalink
[CHORE] Additional debug logs added in result parsing.
Browse files Browse the repository at this point in the history
This additional information is useful for debugging issues with ranking
and torrent profiles, where if nothing is filtered for a config, it's
very hard to debug which setting cause all things to filtered out.

[TESTING]

Changes tested by runing stack in local env with docker.
  • Loading branch information
arao committed Dec 1, 2024
1 parent 81bacd5 commit 6eb24f3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/program/services/scrapers/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,25 @@ def _parse_results(item: MediaItem, results: Dict[str, str], log_msg: bool = Tru
# Ex: [2018, 2019, 2020] for a 2019 movie
if _check_item_year(item, torrent.data):
torrents.add(torrent)
else:
logger.debug(f"Ignoring torrent {torrent.infohash} due to not in time year range, {item.log_string}")

elif item.type == "show":
if torrent.data.seasons and not torrent.data.episodes:
# We subtract one because Trakt doesn't always index
# shows according to uploaders
if len(torrent.data.seasons) >= (len(needed_seasons) - 1):
torrents.add(torrent)
else:
logger.debug(f"Ignoring torrent {torrent.infohash} due mismatch in season size, required {len(needed_seasons)} current {len(torrent.data.seasons)}, {item.log_string}")

elif item.type == "season":
# If the torrent has the needed seasons and no episodes, we can add it
if any(season in torrent.data.seasons for season in needed_seasons) and not torrent.data.episodes:
torrents.add(torrent)
else:
logger.debug(f"Ignoring torrent {torrent.infohash} due to missing required season, {item.log_string}")


elif item.type == "episode":
# If the torrent has the season and episode numbers, we can add it
Expand All @@ -117,17 +124,23 @@ def _parse_results(item: MediaItem, results: Dict[str, str], log_msg: bool = Tru
for season in needed_seasons
) and not torrent.data.episodes:
torrents.add(torrent)
else:
logger.debug(f"Ignoring torrent {torrent.infohash} due to mismatch in season and episode numbers, {item.log_string}")

else:
logger.debug(f"Skipping torrent {infohash} as it does not fit to any category. {item.log_string}")
processed_infohashes.add(infohash)

except (ValueError, AttributeError) as e:
logger.debug(f"Invalid torrent {raw_title} : {e}")
# The only stuff I've seen that show up here is titles with a date.
# Dates can be sometimes parsed incorrectly by Arrow library,
# so we'll just ignore them.
if settings_manager.settings.scraping.parse_debug and log_msg:
logger.debug(f"Skipping torrent: '{raw_title}' - {e}")
continue
except GarbageTorrent as e:
logger.debug(f"GarbageTorrent {raw_title} due to {e}")
if settings_manager.settings.scraping.parse_debug and log_msg:
logger.debug(e)
continue
Expand All @@ -140,6 +153,7 @@ def _parse_results(item: MediaItem, results: Dict[str, str], log_msg: bool = Tru
torrents_dict[torrent.infohash] = Stream(torrent)
logger.log("SCRAPER", f"Kept {len(torrents_dict)} streams for {item.log_string} after processing bucket limit")
return torrents_dict
logger.debug(f"No valid torrent remains after filtering for {item.log_string}: {raw_title}")
return {}


Expand Down

0 comments on commit 6eb24f3

Please sign in to comment.