fix hhanclub数据统计
This commit is contained in:
@ -26,6 +26,7 @@ class SiteSchema(Enum):
|
|||||||
NexusPhp = "NexusPhp"
|
NexusPhp = "NexusPhp"
|
||||||
NexusProject = "NexusProject"
|
NexusProject = "NexusProject"
|
||||||
NexusRabbit = "NexusRabbit"
|
NexusRabbit = "NexusRabbit"
|
||||||
|
NexusHhanclub = "NexusHhanclub"
|
||||||
SmallHorse = "Small Horse"
|
SmallHorse = "Small Horse"
|
||||||
Unit3d = "Unit3d"
|
Unit3d = "Unit3d"
|
||||||
TorrentLeech = "TorrentLeech"
|
TorrentLeech = "TorrentLeech"
|
||||||
|
60
app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py
Normal file
60
app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import re
|
||||||
|
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from app.plugins.sitestatistic.siteuserinfo import SITE_BASE_ORDER, SiteSchema
|
||||||
|
from app.plugins.sitestatistic.siteuserinfo.nexus_php import NexusPhpSiteUserInfo
|
||||||
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
|
|
||||||
|
class NexusHhanclubSiteUserInfo(NexusPhpSiteUserInfo):
|
||||||
|
schema = SiteSchema.NexusHhanclub
|
||||||
|
order = SITE_BASE_ORDER + 20
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def match(cls, html_text: str) -> bool:
|
||||||
|
return 'hhanclub.top' in html_text
|
||||||
|
|
||||||
|
def _parse_user_traffic_info(self, html_text):
|
||||||
|
super()._parse_user_traffic_info(html_text)
|
||||||
|
|
||||||
|
html_text = self._prepare_html_text(html_text)
|
||||||
|
html = etree.HTML(html_text)
|
||||||
|
|
||||||
|
# 上传、下载、分享率
|
||||||
|
upload_match = re.search(r"[_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+[KMGTPI]*B)",
|
||||||
|
html.xpath('//*[@id="user-info-panel"]/div[2]/div[2]/div[4]/text()')[0])
|
||||||
|
download_match = re.search(r"[_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+[KMGTPI]*B)",
|
||||||
|
html.xpath('//*[@id="user-info-panel"]/div[2]/div[2]/div[5]/text()')[0])
|
||||||
|
ratio_match = re.search(r"分享率][::_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+)",
|
||||||
|
html.xpath('//*[@id="user-info-panel"]/div[2]/div[1]/div[1]/div/text()')[0])
|
||||||
|
|
||||||
|
# 计算分享率
|
||||||
|
self.upload = StringUtils.num_filesize(upload_match.group(1).strip()) if upload_match else 0
|
||||||
|
self.download = StringUtils.num_filesize(download_match.group(1).strip()) if download_match else 0
|
||||||
|
# 优先使用页面上的分享率
|
||||||
|
calc_ratio = 0.0 if self.download <= 0.0 else round(self.upload / self.download, 3)
|
||||||
|
self.ratio = StringUtils.str_float(ratio_match.group(1)) if (
|
||||||
|
ratio_match and ratio_match.group(1).strip()) else calc_ratio
|
||||||
|
|
||||||
|
def _parse_user_detail_info(self, html_text: str):
|
||||||
|
"""
|
||||||
|
解析用户额外信息,加入时间,等级
|
||||||
|
:param html_text:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
super()._parse_user_detail_info(html_text)
|
||||||
|
|
||||||
|
html = etree.HTML(html_text)
|
||||||
|
if not html:
|
||||||
|
return
|
||||||
|
# 加入时间
|
||||||
|
join_at_text = html.xpath('//*[@id="mainContent"]/div/div[2]/div[4]/div[3]/span[2]/text()[1]')
|
||||||
|
if join_at_text:
|
||||||
|
self.join_at = StringUtils.unify_datetime_str(join_at_text[0].split(' (')[0].strip())
|
||||||
|
|
||||||
|
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]
|
@ -62,7 +62,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
|
|
||||||
def _parse_user_base_info(self, html_text: str):
|
def _parse_user_base_info(self, html_text: str):
|
||||||
# 合并解析,减少额外请求调用
|
# 合并解析,减少额外请求调用
|
||||||
self.__parse_user_traffic_info(html_text)
|
self._parse_user_traffic_info(html_text)
|
||||||
self._user_traffic_page = None
|
self._user_traffic_page = None
|
||||||
|
|
||||||
self._parse_message_unread(html_text)
|
self._parse_message_unread(html_text)
|
||||||
@ -84,7 +84,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
self.username = str(ret[0])
|
self.username = str(ret[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
def __parse_user_traffic_info(self, html_text):
|
def _parse_user_traffic_info(self, html_text):
|
||||||
html_text = self._prepare_html_text(html_text)
|
html_text = self._prepare_html_text(html_text)
|
||||||
upload_match = re.search(r"[^总]上[传傳]量?[::_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+[KMGTPI]*B)", html_text,
|
upload_match = re.search(r"[^总]上[传傳]量?[::_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+[KMGTPI]*B)", html_text,
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
@ -102,7 +102,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
self.leeching = StringUtils.str_int(leeching_match.group(2)) if leeching_match and leeching_match.group(
|
self.leeching = StringUtils.str_int(leeching_match.group(2)) if leeching_match and leeching_match.group(
|
||||||
2).strip() else 0
|
2).strip() else 0
|
||||||
html = etree.HTML(html_text)
|
html = etree.HTML(html_text)
|
||||||
has_ucoin, self.bonus = self.__parse_ucoin(html)
|
has_ucoin, self.bonus = self._parse_ucoin(html)
|
||||||
if has_ucoin:
|
if has_ucoin:
|
||||||
return
|
return
|
||||||
tmps = html.xpath('//a[contains(@href,"mybonus")]/text()') if html else None
|
tmps = html.xpath('//a[contains(@href,"mybonus")]/text()') if html else None
|
||||||
@ -126,7 +126,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
logger.error(f"{self.site_name} 解析魔力值出错, 错误信息: {err}")
|
logger.error(f"{self.site_name} 解析魔力值出错, 错误信息: {err}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __parse_ucoin(html):
|
def _parse_ucoin(html):
|
||||||
"""
|
"""
|
||||||
解析ucoin, 统一转换为铜币
|
解析ucoin, 统一转换为铜币
|
||||||
:param html:
|
:param html:
|
||||||
@ -151,14 +151,6 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
return True, gold * 100 * 100 + silver * 100 + copper
|
return True, gold * 100 * 100 + silver * 100 + copper
|
||||||
return False, 0.0
|
return False, 0.0
|
||||||
|
|
||||||
def _parse_user_traffic_info(self, html_text: str):
|
|
||||||
"""
|
|
||||||
上传/下载/分享率 [做种数/魔力值]
|
|
||||||
:param html_text:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _parse_user_torrent_seeding_info(self, html_text: str, multi_page: bool = False) -> Optional[str]:
|
def _parse_user_torrent_seeding_info(self, html_text: str, multi_page: bool = False) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
做种相关信息
|
做种相关信息
|
||||||
@ -238,9 +230,9 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
if not html:
|
if not html:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.__get_user_level(html)
|
self._get_user_level(html)
|
||||||
|
|
||||||
self.__fixup_traffic_info(html)
|
self._fixup_traffic_info(html)
|
||||||
|
|
||||||
# 加入日期
|
# 加入日期
|
||||||
join_at_text = html.xpath(
|
join_at_text = html.xpath(
|
||||||
@ -285,9 +277,9 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
if not self.seeding:
|
if not self.seeding:
|
||||||
self.seeding = tmp_seeding
|
self.seeding = tmp_seeding
|
||||||
|
|
||||||
self.__fixup_torrent_seeding_page(html)
|
self._fixup_torrent_seeding_page(html)
|
||||||
|
|
||||||
def __fixup_torrent_seeding_page(self, html):
|
def _fixup_torrent_seeding_page(self, html):
|
||||||
"""
|
"""
|
||||||
修正种子页面链接
|
修正种子页面链接
|
||||||
:param html:
|
:param html:
|
||||||
@ -320,7 +312,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
# if seeding_url_text:
|
# if seeding_url_text:
|
||||||
# self._torrent_seeding_page = seeding_url_text
|
# self._torrent_seeding_page = seeding_url_text
|
||||||
|
|
||||||
def __get_user_level(self, html):
|
def _get_user_level(self, html):
|
||||||
# 等级 获取同一行等级数据,图片格式等级,取title信息,否则取文本信息
|
# 等级 获取同一行等级数据,图片格式等级,取title信息,否则取文本信息
|
||||||
user_levels_text = html.xpath('//tr/td[text()="等級" or text()="等级" or *[text()="等级"]]/'
|
user_levels_text = html.xpath('//tr/td[text()="等級" or text()="等级" or *[text()="等级"]]/'
|
||||||
'following-sibling::td[1]/img[1]/@title')
|
'following-sibling::td[1]/img[1]/@title')
|
||||||
@ -392,7 +384,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo):
|
|||||||
|
|
||||||
return message_head_text, message_date_text, message_content_text
|
return message_head_text, message_date_text, message_content_text
|
||||||
|
|
||||||
def __fixup_traffic_info(self, html):
|
def _fixup_traffic_info(self, html):
|
||||||
# fixup bonus
|
# fixup bonus
|
||||||
if not self.bonus:
|
if not self.bonus:
|
||||||
bonus_text = html.xpath('//tr/td[text()="魔力值" or text()="猫粮"]/following-sibling::td[1]/text()')
|
bonus_text = html.xpath('//tr/td[text()="魔力值" or text()="猫粮"]/following-sibling::td[1]/text()')
|
||||||
|
Reference in New Issue
Block a user