mirror of
https://github.com/d0zingcat/MoviePilot-Plugins.git
synced 2026-05-29 23:16:50 +00:00
fix SiteStatistic
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
"SiteStatistic": {
|
||||
"name": "站点数据统计",
|
||||
"description": "自动统计和展示站点数据。",
|
||||
"version": "2.1",
|
||||
"version": "2.2",
|
||||
"icon": "statistic.png",
|
||||
"author": "lightolly",
|
||||
"level": 2
|
||||
|
||||
@@ -43,7 +43,7 @@ class SiteStatistic(_PluginBase):
|
||||
# 插件图标
|
||||
plugin_icon = "statistic.png"
|
||||
# 插件版本
|
||||
plugin_version = "2.1"
|
||||
plugin_version = "2.2"
|
||||
# 插件作者
|
||||
plugin_author = "lightolly"
|
||||
# 作者主页
|
||||
|
||||
@@ -242,7 +242,7 @@ class ISiteUserInfo(metaclass=ABCMeta):
|
||||
)
|
||||
|
||||
# 其他页处理
|
||||
while next_page:
|
||||
while next_page is not None and next_page is not False:
|
||||
next_page = self._parse_user_torrent_seeding_info(
|
||||
self._get_page_content(
|
||||
url=urljoin(urljoin(self._base_url, self._torrent_seeding_page), next_page),
|
||||
@@ -277,25 +277,32 @@ class ISiteUserInfo(metaclass=ABCMeta):
|
||||
req_headers = None
|
||||
proxies = settings.PROXY if self._proxy else None
|
||||
if self._ua or headers or self._addition_headers:
|
||||
req_headers = {}
|
||||
|
||||
req_headers.update({
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
req_headers = {
|
||||
"User-Agent": f"{self._ua}"
|
||||
})
|
||||
|
||||
if self._addition_headers:
|
||||
req_headers.update(self._addition_headers)
|
||||
}
|
||||
|
||||
if headers:
|
||||
req_headers.update(headers)
|
||||
else:
|
||||
req_headers.update({
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
})
|
||||
if self._addition_headers:
|
||||
req_headers.update(self._addition_headers)
|
||||
|
||||
if params:
|
||||
res = RequestUtils(cookies=self._site_cookie,
|
||||
session=self._session,
|
||||
timeout=60,
|
||||
proxies=proxies,
|
||||
headers=req_headers).post_res(url=url, data=params)
|
||||
if req_headers.get("Content-Type") == "application/json":
|
||||
res = RequestUtils(cookies=self._site_cookie,
|
||||
session=self._session,
|
||||
timeout=60,
|
||||
proxies=proxies,
|
||||
headers=req_headers).post_res(url=url, json=params)
|
||||
else:
|
||||
res = RequestUtils(cookies=self._site_cookie,
|
||||
session=self._session,
|
||||
timeout=60,
|
||||
proxies=proxies,
|
||||
headers=req_headers).post_res(url=url, data=params)
|
||||
else:
|
||||
res = RequestUtils(cookies=self._site_cookie,
|
||||
session=self._session,
|
||||
@@ -303,16 +310,19 @@ 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):
|
||||
# 如果cloudflare 有防护,尝试使用浏览器仿真
|
||||
if under_challenge(res.text):
|
||||
logger.warn(
|
||||
f"{self.site_name} 检测到Cloudflare,请更新Cookie和UA")
|
||||
return ""
|
||||
if re.search(r"charset=\"?utf-8\"?", res.text, re.IGNORECASE):
|
||||
res.encoding = "utf-8"
|
||||
if "application/json" in (req_headers.get("Accept") or ""):
|
||||
return json.dumps(res.json())
|
||||
else:
|
||||
res.encoding = res.apparent_encoding
|
||||
return res.text
|
||||
# 如果cloudflare 有防护,尝试使用浏览器仿真
|
||||
if under_challenge(res.text):
|
||||
logger.warn(
|
||||
f"{self.site_name} 检测到Cloudflare,请更新Cookie和UA")
|
||||
return ""
|
||||
if re.search(r"charset=\"?utf-8\"?", res.text, re.IGNORECASE):
|
||||
res.encoding = "utf-8"
|
||||
else:
|
||||
res.encoding = res.apparent_encoding
|
||||
return res.text
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import json
|
||||
from typing import Optional, Tuple
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from app.log import logger
|
||||
from app.plugins.sitestatistic.siteuserinfo import ISiteUserInfo, SITE_BASE_ORDER, SiteSchema
|
||||
|
||||
|
||||
@@ -10,6 +11,17 @@ class MTorrentSiteUserInfo(ISiteUserInfo):
|
||||
schema = SiteSchema.MTorrent
|
||||
order = SITE_BASE_ORDER + 60
|
||||
|
||||
# 用户级别字典
|
||||
MTeam_sysRoleList = {
|
||||
"1": "User",
|
||||
"2": "Power User",
|
||||
"3": "Elite User",
|
||||
"4": "Crazy User",
|
||||
"5": "Insane User",
|
||||
"6": "Veteran User",
|
||||
"7": "Extreme User",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def match(cls, html_text: str) -> bool:
|
||||
return 'M-Team' in html_text
|
||||
@@ -33,6 +45,10 @@ class MTorrentSiteUserInfo(ISiteUserInfo):
|
||||
"pageSize": 100
|
||||
}
|
||||
self._torrent_seeding_page = "api/member/getUserTorrentList"
|
||||
self._torrent_seeding_headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json, text/plain, */*"
|
||||
}
|
||||
|
||||
def _parse_logged_in(self, html_text):
|
||||
"""
|
||||
@@ -55,7 +71,7 @@ class MTorrentSiteUserInfo(ISiteUserInfo):
|
||||
user_info = detail.get("data", {})
|
||||
self.userid = user_info.get("id")
|
||||
self.username = user_info.get("username")
|
||||
self.user_level = user_info.get("role")
|
||||
self.user_level = self.MTeam_sysRoleList.get(user_info.get("role") or "1")
|
||||
self.join_at = user_info.get("memberStatus", {}).get("createdDate")
|
||||
|
||||
self.upload = int(user_info.get("memberCount", {}).get("uploaded") or '0')
|
||||
@@ -66,7 +82,7 @@ class MTorrentSiteUserInfo(ISiteUserInfo):
|
||||
|
||||
self._torrent_seeding_params = {
|
||||
"pageNumber": 1,
|
||||
"pageSize": 20000,
|
||||
"pageSize": 200,
|
||||
"type": "SEEDING",
|
||||
"userid": self.userid
|
||||
}
|
||||
@@ -91,26 +107,39 @@ class MTorrentSiteUserInfo(ISiteUserInfo):
|
||||
return None
|
||||
seeding_info = json.loads(html_text)
|
||||
if not seeding_info or seeding_info.get("code") != "0":
|
||||
return
|
||||
|
||||
return None
|
||||
torrents = seeding_info.get("data", {}).get("data", [])
|
||||
|
||||
page_seeding_size = 0
|
||||
page_seeding_info = []
|
||||
for info in torrents:
|
||||
torrent = info.get("torrent", {})
|
||||
size = int(torrent.get("size") or '0')
|
||||
seeders = int(torrent.get("source") or '0')
|
||||
|
||||
page_seeding_size += size
|
||||
page_seeding_info.append([seeders, size])
|
||||
|
||||
self.seeding += len(torrents)
|
||||
self.seeding_size += page_seeding_size
|
||||
self.seeding_info.extend(page_seeding_info)
|
||||
|
||||
# 是否存在下页数据
|
||||
return None
|
||||
# 查询总做种数
|
||||
seeder_count = 0
|
||||
try:
|
||||
result = self._get_page_content(
|
||||
url=urljoin(self.site_url, "api/tracker/myPeerStatus"),
|
||||
params={"uid": self.userid},
|
||||
)
|
||||
if result:
|
||||
seeder_info = json.loads(result)
|
||||
seeder_count = int(seeder_info.get("data", {}).get("seeder") or 0)
|
||||
except Exception as e:
|
||||
logger.error(f"获取做种数失败: {str(e)}")
|
||||
if not seeder_count:
|
||||
return None
|
||||
if self.seeding >= seeder_count:
|
||||
return None
|
||||
# 还有下一页
|
||||
self._torrent_seeding_params["pageNumber"] += 1
|
||||
return ""
|
||||
|
||||
def _parse_message_unread_links(self, html_text: str, msg_links: list) -> Optional[str]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user