fix brushflow tracker mapping

This commit is contained in:
InfinityPacer
2024-04-02 17:28:33 +08:00
parent 0441e56774
commit e1dbd91012

View File

@@ -7,6 +7,7 @@ import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from threading import Event from threading import Event
from typing import Any, List, Dict, Tuple, Optional, Union, Set from typing import Any, List, Dict, Tuple, Optional, Union, Set
from urllib.parse import urlparse, parse_qs, unquote
import pytz import pytz
from app import schemas from app import schemas
@@ -2365,11 +2366,7 @@ class BrushFlow(_PluginBase):
""" """
torrent_info = self.__get_torrent_info(torrent=torrent) torrent_info = self.__get_torrent_info(torrent=torrent)
trackers = [tracker.get("url") for tracker in (torrent.trackers or []) if site_id, site_name = self.__get_site_by_torrent(torrent=torrent)
tracker.get("tier", -1) >= 0 and tracker.get("url")]
trackers.append(torrent_info.get("tracker"))
site_id, site_name = self.__get_site_by_tracker(trackers=trackers)
torrent_task = { torrent_task = {
"site": site_id, "site": site_id,
@@ -3334,10 +3331,26 @@ class BrushFlow(_PluginBase):
# 情况2: 时间段跨越午夜 # 情况2: 时间段跨越午夜
return now >= start_time or now <= end_time return now >= start_time or now <= end_time
def __get_site_by_tracker(self, trackers: list[str]) -> Tuple[int, str]: def __get_site_by_torrent(self, torrent: Any) -> Tuple[int, str]:
""" """
根据tracker获取站点信息 根据tracker获取站点信息
""" """
trackers = []
try:
tracker_url = torrent.get("tracker")
if tracker_url:
trackers.append(tracker_url)
magnet_link = torrent.get("magnet_uri")
if magnet_link:
query_params = parse_qs(urlparse(magnet_link).query)
encoded_tracker_urls = query_params.get('tr', [])
# 解码tracker URLs然后扩展到trackers列表中
decoded_tracker_urls = [unquote(url) for url in encoded_tracker_urls]
trackers.extend(decoded_tracker_urls)
except Exception as e:
logger.error(e)
domain = "未知" domain = "未知"
if not trackers: if not trackers:
return 0, domain return 0, domain
@@ -3350,6 +3363,8 @@ class BrushFlow(_PluginBase):
} }
for tracker in trackers: for tracker in trackers:
if not tracker:
continue
# 检查tracker是否包含特定的关键字并进行相应的映射 # 检查tracker是否包含特定的关键字并进行相应的映射
for key, mapped_domain in tracker_mappings.items(): for key, mapped_domain in tracker_mappings.items():
if key in tracker: if key in tracker: