Skip to content

Commit

Permalink
feat: add ignore hash feature
Browse files Browse the repository at this point in the history
Release-As: 0.9.2
  • Loading branch information
dreulavelle committed Jul 31, 2024
1 parent b037e2a commit d8e565f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/program/scrapers/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from program.settings.versions import models
from RTN import RTN, Torrent, sort_torrents
from RTN.exceptions import GarbageTorrent
from utils.ignore import get_ignore_hashes
from utils.logger import logger

settings_model = settings_manager.settings.ranking
Expand Down Expand Up @@ -36,13 +37,18 @@ def _parse_results(item: MediaItem, results: Dict[str, str]) -> Dict[str, Stream
torrents: Set[Torrent] = set()
processed_infohashes: Set[str] = set()
correct_title: str = item.get_top_title()
ignore_hashes: set = get_ignore_hashes()

logger.log("SCRAPER", f"Processing {len(results)} results for {item.log_string}")

if isinstance(item, Show):
needed_seasons = [season.number for season in item.seasons]

for infohash, raw_title in results.items():
if infohash in ignore_hashes:
logger.debug(f"Ignoring hash for torrent as it's in the ignore file: {infohash}")
continue

if infohash in processed_infohashes:
continue

Expand Down
18 changes: 18 additions & 0 deletions src/utils/ignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import regex

from utils import data_dir_path

ignore_file_path = data_dir_path / "ignore.txt"

def get_ignore_hashes() -> set:
"""Read the ignore.txt file and return a set of infohashes to ignore."""
infohashes = set()
infohash_pattern = regex.compile(r"[a-fA-F0-9]{40}")

if ignore_file_path.exists():
with open(ignore_file_path, "r") as file:
for line in file:
match = infohash_pattern.search(line)
if match:
infohashes.add(match.group(0))
return infohashes

0 comments on commit d8e565f

Please sign in to comment.