Merge pull request #562 from thsrite/main
This commit is contained in:
commit
0414854832
@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union
|
||||||
|
|
||||||
from cachetools import cached, TTLCache
|
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.context import TorrentInfo, Context, MediaInfo
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.db import SessionFactory
|
from app.db import SessionFactory
|
||||||
|
from app.db.site_oper import SiteOper
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.rss import RssHelper
|
from app.helper.rss import RssHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import Notification
|
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.singleton import Singleton
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
self._db = SessionFactory()
|
self._db = SessionFactory()
|
||||||
super().__init__(self._db)
|
super().__init__(self._db)
|
||||||
self.siteshelper = SitesHelper()
|
self.siteshelper = SitesHelper()
|
||||||
|
self.siteoper = SiteOper(self._db)
|
||||||
self.rsshelper = RssHelper()
|
self.rsshelper = RssHelper()
|
||||||
self.systemconfig = SystemConfigOper()
|
self.systemconfig = SystemConfigOper()
|
||||||
|
|
||||||
@ -85,6 +88,10 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
logger.error(f'站点 {domain} 未配置RSS地址!')
|
logger.error(f'站点 {domain} 未配置RSS地址!')
|
||||||
return []
|
return []
|
||||||
rss_items = self.rsshelper.parse(site.get("rss"), True if site.get("proxy") else False)
|
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:
|
if not rss_items:
|
||||||
logger.error(f'站点 {domain} 未获取到RSS数据!')
|
logger.error(f'站点 {domain} 未获取到RSS数据!')
|
||||||
return []
|
return []
|
||||||
@ -187,3 +194,37 @@ class TorrentsChain(ChainBase, metaclass=Singleton):
|
|||||||
self.save_cache(torrents_cache, self._rss_file)
|
self.save_cache(torrents_cache, self._rss_file)
|
||||||
# 返回
|
# 返回
|
||||||
return torrents_cache
|
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链接已过期"))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple, Union
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -221,7 +221,7 @@ class RssHelper:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(url, proxy: bool = False) -> List[dict]:
|
def parse(url, proxy: bool = False) -> Union[List[dict], None]:
|
||||||
"""
|
"""
|
||||||
解析RSS订阅URL,获取RSS中的种子信息
|
解析RSS订阅URL,获取RSS中的种子信息
|
||||||
:param url: RSS地址
|
:param url: RSS地址
|
||||||
@ -288,6 +288,14 @@ class RssHelper:
|
|||||||
continue
|
continue
|
||||||
except Exception as e2:
|
except Exception as e2:
|
||||||
print(str(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
|
return ret_array
|
||||||
|
|
||||||
def get_rss_link(self, url: str, cookie: str, ua: str, proxy: bool = False) -> Tuple[str, str]:
|
def get_rss_link(self, url: str, cookie: str, ua: str, proxy: bool = False) -> Tuple[str, str]:
|
||||||
|
@ -676,6 +676,15 @@ class IYUUAutoSeed(_PluginBase):
|
|||||||
"info_hash": "a444850638e7a6f6220e2efdde94099c53358159"
|
"info_hash": "a444850638e7a6f6220e2efdde94099c53358159"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __is_special_site(url):
|
||||||
|
"""
|
||||||
|
判断是否为特殊站点(是否需要添加https)
|
||||||
|
"""
|
||||||
|
if "hdsky.me" in url:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
self.total += 1
|
self.total += 1
|
||||||
# 获取种子站点及下载地址模板
|
# 获取种子站点及下载地址模板
|
||||||
site_url, download_page = self.iyuuhelper.get_torrent_url(seed.get("sid"))
|
site_url, download_page = self.iyuuhelper.get_torrent_url(seed.get("sid"))
|
||||||
@ -720,10 +729,11 @@ class IYUUAutoSeed(_PluginBase):
|
|||||||
self.cached += 1
|
self.cached += 1
|
||||||
return False
|
return False
|
||||||
# 强制使用Https
|
# 强制使用Https
|
||||||
if "?" in torrent_url:
|
if __is_special_site(torrent_url):
|
||||||
torrent_url += "&https=1"
|
if "?" in torrent_url:
|
||||||
else:
|
torrent_url += "&https=1"
|
||||||
torrent_url += "?https=1"
|
else:
|
||||||
|
torrent_url += "?https=1"
|
||||||
# 下载种子文件
|
# 下载种子文件
|
||||||
_, content, _, _, error_msg = self.torrent.download_torrent(
|
_, content, _, _, error_msg = self.torrent.download_torrent(
|
||||||
url=torrent_url,
|
url=torrent_url,
|
||||||
|
@ -56,5 +56,6 @@ class NexusHhanclubSiteUserInfo(NexusPhpSiteUserInfo):
|
|||||||
|
|
||||||
def _get_user_level(self, html):
|
def _get_user_level(self, html):
|
||||||
super()._get_user_level(html)
|
super()._get_user_level(html)
|
||||||
|
user_level_path = html.xpath('//*[@id="mainContent"]/div/div[2]/div[2]/div[4]/span[2]/img/@title')
|
||||||
self.user_level = html.xpath('//*[@id="mainContent"]/div/div[2]/div[2]/div[4]/img/@title')[0]
|
if user_level_path:
|
||||||
|
self.user_level = user_level_path[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user