From a0329a3eb015e692613aad1d89c051d8c9bbecda Mon Sep 17 00:00:00 2001 From: noone Date: Thu, 6 Nov 2025 16:32:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(rss):=20=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89User-Agent=E8=8E=B7=E5=8F=96RSS=E3=80=82?= =?UTF-8?q?=E7=9B=AE=E5=89=8D=E6=9C=89=E4=BA=9B=E7=AB=99=E7=82=B9=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E9=85=8D=E7=BD=AEUA=E6=97=B6=E4=BC=9A=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96RSS=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在RSS方法中新增ua参数用于指定User-Agent - 更新RequestUtils调用以传递自定义User-Agent - 修改torrents链中RSS解析逻辑以支持站点配置的ua字段 - 设置默认超时时间为30秒以增强稳定性 --- app/chain/torrents.py | 2 +- app/helper/rss.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/chain/torrents.py b/app/chain/torrents.py index 93a799c4..eb1362bc 100644 --- a/app/chain/torrents.py +++ b/app/chain/torrents.py @@ -150,7 +150,7 @@ class TorrentsChain(ChainBase): return [] # 解析RSS rss_items = RssHelper().parse(site.get("rss"), True if site.get("proxy") else False, - timeout=int(site.get("timeout") or 30)) + timeout=int(site.get("timeout") or 30), ua=site.get("ua") if site.get("ua") else None) if rss_items is None: # rss过期,尝试保留原配置生成新的rss self.__renew_rss_url(domain=domain, site=site) diff --git a/app/helper/rss.py b/app/helper/rss.py index caf820f0..5cd309d8 100644 --- a/app/helper/rss.py +++ b/app/helper/rss.py @@ -228,13 +228,14 @@ class RssHelper: } def parse(self, url, proxy: bool = False, - timeout: Optional[int] = 15, headers: dict = None) -> Union[List[dict], None, bool]: + timeout: Optional[int] = 15, headers: dict = None, ua: str = None) -> Union[List[dict], None, bool]: """ 解析RSS订阅URL,获取RSS中的种子信息 :param url: RSS地址 :param proxy: 是否使用代理 :param timeout: 请求超时 :param headers: 自定义请求头 + :param ua: 自定义User-Agent :return: 种子信息列表,如为None代表Rss过期,如果为False则为错误 """ # 开始处理 @@ -243,8 +244,9 @@ class RssHelper: return False try: - ret = RequestUtils(proxies=settings.PROXY if proxy else None, - timeout=timeout, headers=headers).get_res(url) + ret = RequestUtils(ua=ua, + proxies=settings.PROXY if proxy else None, + timeout=timeout or 30, headers=headers).get_res(url) if not ret: logger.error(f"获取RSS失败:请求返回空值,URL: {url}") return False