Merge pull request #3517 from wikrin/match_rule

This commit is contained in:
jxxghp
2024-12-11 06:54:58 +08:00
committed by GitHub
2 changed files with 33 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import re import re
from dataclasses import dataclass, field, asdict from dataclasses import dataclass, field, asdict
from datetime import datetime
from typing import List, Dict, Any, Tuple from typing import List, Dict, Any, Tuple
from app.core.config import settings from app.core.config import settings
@@ -123,6 +124,20 @@ class TorrentInfo:
return "" return ""
return StringUtils.diff_time_str(self.freedate) 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): def to_dict(self):
""" """
返回字典 返回字典

View File

@@ -366,6 +366,8 @@ class FilterModule(_ModuleBase):
seeders = self.rule_set[rule_name].get("seeders") seeders = self.rule_set[rule_name].get("seeders")
# FREE规则 # FREE规则
downloadvolumefactor = self.rule_set[rule_name].get("downloadvolumefactor") 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): 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}") logger.debug(f"种子 {torrent.site_name} - {torrent.title} 不包含任何项 {includes}")
@@ -392,6 +394,22 @@ class FilterModule(_ModuleBase):
logger.debug( logger.debug(
f"种子 {torrent.site_name} - {torrent.title} FREE值 {torrent.downloadvolumefactor} 不是 {downloadvolumefactor}") f"种子 {torrent.site_name} - {torrent.title} FREE值 {torrent.downloadvolumefactor} 不是 {downloadvolumefactor}")
return False 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 return True
def __match_tmdb(self, tmdb: dict) -> bool: def __match_tmdb(self, tmdb: dict) -> bool: