diff --git a/app/core/context.py b/app/core/context.py index 2bd05d78..1c117ddc 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -1,5 +1,6 @@ import re from dataclasses import dataclass, field, asdict +from datetime import datetime from typing import List, Dict, Any, Tuple from app.core.config import settings @@ -123,6 +124,20 @@ class TorrentInfo: return "" return StringUtils.diff_time_str(self.freedate) + def pub_minutes(self) -> float: + """ + 返回发布时间距离当前时间的分钟数 + """ + if not self.pubdate: + return 0 + try: + pub_date = datetime.strptime(self.pubdate, "%Y-%m-%d %H:%M:%S") + now_datetime = datetime.now() + return (now_datetime - pub_date).total_seconds() // 60 + except Exception as e: + print(f"种子发布时间获取失败: {e}") + return 0 + def to_dict(self): """ 返回字典 diff --git a/app/modules/filter/__init__.py b/app/modules/filter/__init__.py index ab35ae86..80f2117a 100644 --- a/app/modules/filter/__init__.py +++ b/app/modules/filter/__init__.py @@ -366,6 +366,8 @@ class FilterModule(_ModuleBase): seeders = self.rule_set[rule_name].get("seeders") # FREE规则 downloadvolumefactor = self.rule_set[rule_name].get("downloadvolumefactor") + # 发布时间规则 + pubdate: str = self.rule_set[rule_name].get("publish_time") if includes and not any(re.search(r"%s" % include, content, re.IGNORECASE) for include in includes): # 未发现任何包含项 logger.debug(f"种子 {torrent.site_name} - {torrent.title} 不包含任何项 {includes}") @@ -392,6 +394,22 @@ class FilterModule(_ModuleBase): logger.debug( f"种子 {torrent.site_name} - {torrent.title} FREE值 {torrent.downloadvolumefactor} 不是 {downloadvolumefactor}") return False + if pubdate: + # 种子发布时间 + pub_minutes = torrent.pub_minutes() + # 发布时间规则 + pub_times = [float(t) for t in pubdate.split("-")] + if len(pub_times) == 1: + # 发布时间小于规则 + if pub_minutes < pub_times[0]: + logger.debug(f"种子 {torrent.site_name} - {torrent.title} 发布时间 {pub_minutes} 小于 {pub_times[0]}") + return False + else: + # 区间 + if not (pub_times[0] <= pub_minutes <= pub_times[1]): + logger.debug(f"种子 {torrent.site_name} - {torrent.title} 发布时间 {pub_minutes} 不在 {pub_times[0]}-{pub_times[1]} 时间区间") + return False + return True def __match_tmdb(self, tmdb: dict) -> bool: