diff --git a/comet/api/stream.py b/comet/api/stream.py index a0f5d6f..1e44653 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -105,6 +105,10 @@ async def stream(request: Request, b64config: str, type: str, id: str): name = element["l"] year = element.get("y") + + year_end = None + if "yr" in element: + year_end = int(element["yr"].split("-")[1]) except Exception as e: logger.warning(f"Exception while getting metadata for {id}: {e}") @@ -345,6 +349,7 @@ async def stream(request: Request, b64config: str, type: str, id: str): aliases = await get_aliases( session, "movies" if type == "movie" else "shows", id ) + # print(aliases) indexed_torrents = [(i, torrents[i]["Title"]) for i in range(len(torrents))] chunk_size = 50 @@ -355,7 +360,7 @@ async def stream(request: Request, b64config: str, type: str, id: str): tasks = [] for chunk in chunks: - tasks.append(filter(chunk, name, year, aliases)) + tasks.append(filter(chunk, name, year, year_end, aliases)) filtered_torrents = await asyncio.gather(*tasks) index_less = 0 diff --git a/comet/utils/general.py b/comet/utils/general.py index d45b25a..ed90c25 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -467,7 +467,7 @@ async def get_mediafusion(log_name: str, type: str, full_id: str): return results -async def filter(torrents: list, name: str, year: int, aliases: dict): +async def filter(torrents: list, name: str, year: int, year_end: int, aliases: dict): results = [] for torrent in torrents: index = torrent[0] @@ -482,11 +482,20 @@ async def filter(torrents: list, name: str, year: int, aliases: dict): name, parsed.parsed_title, aliases=aliases ): results.append((index, False)) + # print(title, "|", parsed.parsed_title, "| title mismatch") continue - if year and parsed.year and year != parsed.year: - results.append((index, False)) - continue + if year and parsed.year: + if year_end is not None: + if not (year <= parsed.year <= year_end): + # print(title, "|", year, "to", year_end, "!=", parsed.year, "| year mismatch") + results.append((index, False)) + continue + else: + if year < (parsed.year - 1) or year > (parsed.year + 1): + # print(title, "|", year, "!=", parsed.year, "| year mismatch") + results.append((index, False)) + continue results.append((index, True))