refactor: enhance filtering logic with media type and year range handling

- Updated the filter_worker function to include media_type as a parameter.
- Introduced min_year and max_year calculations to improve year filtering logic.
- Adjusted year mismatch logging to reflect new expected formats based on media type.
This commit is contained in:
g0ldyy
2026-01-11 15:56:36 +01:00
parent feca4e03aa
commit c6f0790d68
2 changed files with 29 additions and 13 deletions
+28 -13
View File
@@ -17,13 +17,28 @@ def quick_alias_match(text_normalized: str, ez_aliases_normalized: list[str]):
return any(alias in text_normalized for alias in ez_aliases_normalized)
def filter_worker(torrents, title, year, year_end, aliases, remove_adult_content):
def filter_worker(
torrents, title, year, year_end, media_type, aliases, remove_adult_content
):
results = []
ez_aliases = aliases.get("ez", [])
if ez_aliases:
ez_aliases_normalized = [normalize_title(a) for a in ez_aliases]
min_year = 0
max_year = float("inf")
if year:
if year_end:
min_year = year
max_year = year_end
elif media_type == "series":
min_year = year - 1
else:
min_year = year - 1
max_year = year + 1
for torrent in torrents:
torrent_title = torrent["title"]
torrent_title_lower = torrent_title.lower()
@@ -53,18 +68,18 @@ def filter_worker(torrents, title, year, year_end, aliases, remove_adult_content
continue
if year and parsed.year:
if year_end is not None:
if not (year <= parsed.year <= year_end):
_log_exclusion(
f"📅 Rejected (Year Mismatch) | {torrent_title} | Year: {parsed.year} | Expected: {year}-{year_end}"
)
continue
else:
if year < (parsed.year - 1) or year > (parsed.year + 1):
_log_exclusion(
f"📅 Rejected (Year Mismatch) | {torrent_title} | Year: {parsed.year} | Expected: ~{year}"
)
continue
if not (min_year <= parsed.year <= max_year):
if year_end:
expected = f"{year}-{year_end}"
elif media_type == "series":
expected = f">{year}"
else:
expected = f"~{year}"
_log_exclusion(
f"📅 Rejected (Year Mismatch) | {torrent_title} | Year: {parsed.year} | Expected: {expected}"
)
continue
torrent["parsed"] = parsed
results.append(torrent)
+1
View File
@@ -225,6 +225,7 @@ class TorrentManager:
self.title,
self.year,
self.year_end,
self.media_type,
self.aliases,
self.remove_adult_content,
)