diff --git a/plugins/sitestatistic/__init__.py b/plugins/sitestatistic/__init__.py index a829ad3..17ff09d 100644 --- a/plugins/sitestatistic/__init__.py +++ b/plugins/sitestatistic/__init__.py @@ -43,7 +43,7 @@ class SiteStatistic(_PluginBase): # 插件图标 plugin_icon = "statistic.png" # 插件版本 - plugin_version = "2.2" + plugin_version = "2.3" # 插件作者 plugin_author = "lightolly" # 作者主页 @@ -1185,7 +1185,9 @@ class SiteStatistic(_PluginBase): return site_user_info except Exception as e: + import traceback logger.error(f"站点 {site_name} 获取流量数据失败:{str(e)}") + logger.error(traceback.format_exc()) return None def __notify_unread_msg(self, site_name: str, site_user_info: ISiteUserInfo, unread_msg_notify: bool): diff --git a/plugins/sitestatistic/siteuserinfo/__init__.py b/plugins/sitestatistic/siteuserinfo/__init__.py index df2af5b..f678294 100644 --- a/plugins/sitestatistic/siteuserinfo/__init__.py +++ b/plugins/sitestatistic/siteuserinfo/__init__.py @@ -116,6 +116,7 @@ class ISiteUserInfo(metaclass=ABCMeta): self.site_name = site_name self.site_url = url self._base_url = f"{split_url.scheme}://{split_url.netloc}" + self.site_domain = split_url.netloc self._site_cookie = site_cookie self._index_html = index_html self._session = session if session else None @@ -292,9 +293,7 @@ class ISiteUserInfo(metaclass=ABCMeta): if params: if req_headers.get("Content-Type") == "application/json": - res = RequestUtils(cookies=self._site_cookie, - session=self._session, - timeout=60, + res = RequestUtils(timeout=60, proxies=proxies, headers=req_headers).post_res(url=url, json=params) else: @@ -310,7 +309,7 @@ class ISiteUserInfo(metaclass=ABCMeta): proxies=proxies, headers=req_headers).get_res(url=url) if res is not None and res.status_code in (200, 500, 403): - if "application/json" in (req_headers.get("Accept") or ""): + if "application/json" in ((req_headers and req_headers.get("Accept")) or ""): return json.dumps(res.json()) else: # 如果cloudflare 有防护,尝试使用浏览器仿真 diff --git a/plugins/sitestatistic/siteuserinfo/mtorrent.py b/plugins/sitestatistic/siteuserinfo/mtorrent.py index b797f1d..5f73f48 100644 --- a/plugins/sitestatistic/siteuserinfo/mtorrent.py +++ b/plugins/sitestatistic/siteuserinfo/mtorrent.py @@ -2,8 +2,10 @@ import json from typing import Optional, Tuple from urllib.parse import urljoin +from lxml import etree from app.log import logger +from app.db.systemconfig_oper import SystemConfigOper from app.plugins.sitestatistic.siteuserinfo import ISiteUserInfo, SITE_BASE_ORDER, SiteSchema @@ -20,11 +22,27 @@ class MTorrentSiteUserInfo(ISiteUserInfo): "5": "Insane User", "6": "Veteran User", "7": "Extreme User", + "8": "Ultimate User", + "9": "Nexus Master", + "10": "VIP", + "11": "Retiree", + "12": "Uploader", + "13": "Moderator", + "14": "Administrator", + "15": "Sysop", + "16": "Staff", + "17": "Offer memberStaff", + "18": "Bet memberStaff", } @classmethod def match(cls, html_text: str) -> bool: - return 'M-Team' in html_text + html = etree.HTML(html_text) + if not html: + return False + if html.xpath("//title/text()") and "M-Team" in html.xpath("//title/text()")[0]: + return True + return False def _parse_site_page(self, html_text: str): """ @@ -45,9 +63,11 @@ class MTorrentSiteUserInfo(ISiteUserInfo): "pageSize": 100 } self._torrent_seeding_page = "api/member/getUserTorrentList" + domain = self.site_domain.split(".")[-2] self._torrent_seeding_headers = { "Content-Type": "application/json", - "Accept": "application/json, text/plain, */*" + "Accept": "application/json, text/plain, */*", + "x-api-key": SystemConfigOper().get(f"site.{domain}.apikey"), } def _parse_logged_in(self, html_text):