diff --git a/app/chain/torrents.py b/app/chain/torrents.py index 22f95ac7..48d669dc 100644 --- a/app/chain/torrents.py +++ b/app/chain/torrents.py @@ -1,3 +1,4 @@ +import re from typing import Dict, List, Union from cachetools import cached, TTLCache @@ -7,12 +8,13 @@ from app.core.config import settings from app.core.context import TorrentInfo, Context, MediaInfo from app.core.metainfo import MetaInfo from app.db import SessionFactory +from app.db.site_oper import SiteOper from app.db.systemconfig_oper import SystemConfigOper from app.helper.rss import RssHelper from app.helper.sites import SitesHelper from app.log import logger from app.schemas import Notification -from app.schemas.types import SystemConfigKey, MessageChannel +from app.schemas.types import SystemConfigKey, MessageChannel, NotificationType from app.utils.singleton import Singleton from app.utils.string import StringUtils @@ -29,6 +31,7 @@ class TorrentsChain(ChainBase, metaclass=Singleton): self._db = SessionFactory() super().__init__(self._db) self.siteshelper = SitesHelper() + self.siteoper = SiteOper(self._db) self.rsshelper = RssHelper() self.systemconfig = SystemConfigOper() @@ -85,6 +88,10 @@ class TorrentsChain(ChainBase, metaclass=Singleton): logger.error(f'站点 {domain} 未配置RSS地址!') return [] rss_items = self.rsshelper.parse(site.get("rss"), True if site.get("proxy") else False) + if rss_items is None: + # rss过期,尝试保留原配置生成新的rss + self.__renew_rss_url(domain=domain, site=site) + return [] if not rss_items: logger.error(f'站点 {domain} 未获取到RSS数据!') return [] @@ -187,3 +194,37 @@ class TorrentsChain(ChainBase, metaclass=Singleton): self.save_cache(torrents_cache, self._rss_file) # 返回 return torrents_cache + + def __renew_rss_url(self, domain: str, site: dict): + """ + 保留原配置生成新的rss地址 + """ + try: + # RSS链接过期 + logger.error(f"站点 {domain} RSS链接已过期,正在尝试自动获取!") + # 自动生成rss地址 + rss_url, errmsg = self.rsshelper.get_rss_link( + url=site.get("url"), + cookie=site.get("cookie"), + ua=site.get("ua") or settings.USER_AGENT, + proxy=True if site.get("proxy") else False + ) + if rss_url: + # 获取新的日期的passkey + match = re.search(r'passkey=([a-zA-Z0-9]+)', rss_url) + if match: + new_passkey = match.group(1) + # 获取过期rss除去passkey部分 + new_rss = re.sub(r'&passkey=([a-zA-Z0-9]+)', f'&passkey={new_passkey}', site.get("rss")) + logger.info(f"更新站点 {domain} RSS地址 ...") + self.siteoper.update_rss(domain=domain, rss=new_rss) + else: + # 发送消息 + self.post_message( + Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期")) + else: + self.post_message( + Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期")) + except Exception as e: + print(str(e)) + self.post_message(Notification(mtype=NotificationType.SiteMessage, title=f"站点 {domain} RSS链接已过期")) diff --git a/app/helper/rss.py b/app/helper/rss.py index 7285edcb..24aaed8b 100644 --- a/app/helper/rss.py +++ b/app/helper/rss.py @@ -1,5 +1,5 @@ import xml.dom.minidom -from typing import List, Tuple +from typing import List, Tuple, Union from urllib.parse import urljoin from lxml import etree @@ -221,7 +221,7 @@ class RssHelper: } @staticmethod - def parse(url, proxy: bool = False) -> List[dict]: + def parse(url, proxy: bool = False) -> Union[List[dict], None]: """ 解析RSS订阅URL,获取RSS中的种子信息 :param url: RSS地址 @@ -288,6 +288,14 @@ class RssHelper: continue except Exception as e2: print(str(e2)) + # RSS过期 观众RSS 链接已过期,您需要获得一个新的! pthome RSS Link has expired, You need to get a new one! + _rss_expired_msg = [ + "RSS 链接已过期, 您需要获得一个新的!", + "RSS Link has expired, You need to get a new one!", + "RSS Link has expired, You need to get new!" + ] + if ret_xml in _rss_expired_msg: + return None return ret_array def get_rss_link(self, url: str, cookie: str, ua: str, proxy: bool = False) -> Tuple[str, str]: diff --git a/app/plugins/iyuuautoseed/__init__.py b/app/plugins/iyuuautoseed/__init__.py index ee6d7bd5..1aa2006e 100644 --- a/app/plugins/iyuuautoseed/__init__.py +++ b/app/plugins/iyuuautoseed/__init__.py @@ -676,6 +676,15 @@ class IYUUAutoSeed(_PluginBase): "info_hash": "a444850638e7a6f6220e2efdde94099c53358159" } """ + + def __is_special_site(url): + """ + 判断是否为特殊站点(是否需要添加https) + """ + if "hdsky.me" in url: + return False + return True + self.total += 1 # 获取种子站点及下载地址模板 site_url, download_page = self.iyuuhelper.get_torrent_url(seed.get("sid")) @@ -720,10 +729,11 @@ class IYUUAutoSeed(_PluginBase): self.cached += 1 return False # 强制使用Https - if "?" in torrent_url: - torrent_url += "&https=1" - else: - torrent_url += "?https=1" + if __is_special_site(torrent_url): + if "?" in torrent_url: + torrent_url += "&https=1" + else: + torrent_url += "?https=1" # 下载种子文件 _, content, _, _, error_msg = self.torrent.download_torrent( url=torrent_url, diff --git a/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py b/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py index 14f98e87..c85c96d2 100644 --- a/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py +++ b/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py @@ -56,5 +56,6 @@ class NexusHhanclubSiteUserInfo(NexusPhpSiteUserInfo): def _get_user_level(self, html): super()._get_user_level(html) - - self.user_level = html.xpath('//*[@id="mainContent"]/div/div[2]/div[2]/div[4]/img/@title')[0] + user_level_path = html.xpath('//*[@id="mainContent"]/div/div[2]/div[2]/div[4]/span[2]/img/@title') + if user_level_path: + self.user_level = user_level_path[0]