From 16289d86b6351ffe7a3231a100d6980c14ec5da1 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 30 Aug 2023 14:51:55 +0800 Subject: [PATCH] =?UTF-8?q?fix=20hhanclub=E6=95=B0=E6=8D=AE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sitestatistic/siteuserinfo/__init__.py | 1 + .../siteuserinfo/nexus_hhanclub.py | 60 +++++++++++++++++++ .../sitestatistic/siteuserinfo/nexus_php.py | 28 ++++----- 3 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py diff --git a/app/plugins/sitestatistic/siteuserinfo/__init__.py b/app/plugins/sitestatistic/siteuserinfo/__init__.py index 5a63b196..ada4c657 100644 --- a/app/plugins/sitestatistic/siteuserinfo/__init__.py +++ b/app/plugins/sitestatistic/siteuserinfo/__init__.py @@ -26,6 +26,7 @@ class SiteSchema(Enum): NexusPhp = "NexusPhp" NexusProject = "NexusProject" NexusRabbit = "NexusRabbit" + NexusHhanclub = "NexusHhanclub" SmallHorse = "Small Horse" Unit3d = "Unit3d" TorrentLeech = "TorrentLeech" diff --git a/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py b/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py new file mode 100644 index 00000000..14f98e87 --- /dev/null +++ b/app/plugins/sitestatistic/siteuserinfo/nexus_hhanclub.py @@ -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] diff --git a/app/plugins/sitestatistic/siteuserinfo/nexus_php.py b/app/plugins/sitestatistic/siteuserinfo/nexus_php.py index 38bbb10b..23dc3260 100644 --- a/app/plugins/sitestatistic/siteuserinfo/nexus_php.py +++ b/app/plugins/sitestatistic/siteuserinfo/nexus_php.py @@ -62,7 +62,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): 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._parse_message_unread(html_text) @@ -84,7 +84,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): self.username = str(ret[0]) 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) upload_match = re.search(r"[^总]上[传傳]量?[::_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+[KMGTPI]*B)", html_text, 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( 2).strip() else 0 html = etree.HTML(html_text) - has_ucoin, self.bonus = self.__parse_ucoin(html) + has_ucoin, self.bonus = self._parse_ucoin(html) if has_ucoin: return 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}") @staticmethod - def __parse_ucoin(html): + def _parse_ucoin(html): """ 解析ucoin, 统一转换为铜币 :param html: @@ -151,14 +151,6 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): return True, gold * 100 * 100 + silver * 100 + copper 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]: """ 做种相关信息 @@ -238,9 +230,9 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): if not html: 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( @@ -285,9 +277,9 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): if not self.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: @@ -320,7 +312,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): # if seeding_url_text: # self._torrent_seeding_page = seeding_url_text - def __get_user_level(self, html): + def _get_user_level(self, html): # 等级 获取同一行等级数据,图片格式等级,取title信息,否则取文本信息 user_levels_text = html.xpath('//tr/td[text()="等級" or text()="等级" or *[text()="等级"]]/' 'following-sibling::td[1]/img[1]/@title') @@ -392,7 +384,7 @@ class NexusPhpSiteUserInfo(ISiteUserInfo): return message_head_text, message_date_text, message_content_text - def __fixup_traffic_info(self, html): + def _fixup_traffic_info(self, html): # fixup bonus if not self.bonus: bonus_text = html.xpath('//tr/td[text()="魔力值" or text()="猫粮"]/following-sibling::td[1]/text()')