From 73e4596d1aa285a90ee0c5ee09e93487e8acea84 Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:36:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(filter):=20add=20publish=20time=20filter?= =?UTF-8?q?=20for=20torrents=20-=20=E5=9C=A8=20`TorrentInfo`=20=E7=B1=BB?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=20`pub=5Fminutes`=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=BB=A5=E8=AE=A1=E7=AE=97=E8=87=AA=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E4=BB=A5=E6=9D=A5=E7=9A=84`=E5=88=86=E9=92=9F`=E6=95=B0=20-=20?= =?UTF-8?q?=E5=9C=A8=20FilterModule=20=E4=B8=AD=E5=AE=9E=E7=8E=B0=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=97=B6=E9=97=B4=E8=BF=87=E6=BB=A4=20-=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=91=E5=B8=83=E6=97=B6=E9=97=B4=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E5=80=BC=E5=92=8C=E8=8C=83=E5=9B=B4=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/context.py | 15 +++++++++++++++ app/modules/filter/__init__.py | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) 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: