Skip to content

Commit 4ac3eca

Browse files
committed
fix: m-team刷流
1 parent f40361f commit 4ac3eca

File tree

10 files changed

+396
-93
lines changed

10 files changed

+396
-93
lines changed

app/helper/site_helper.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from datetime import datetime
33
import os
44
import re
5+
import json
56

67
from lxml import etree
78

8-
from app.utils import SystemUtils
9+
from app.utils import SystemUtils, JsonUtils
910
from config import RMT_SUBEXT
1011

1112

@@ -18,6 +19,13 @@ def is_logged_in(cls, html_text):
1819
:param html_text:
1920
:return:
2021
"""
22+
if JsonUtils.is_valid_json(html_text):
23+
json_data = json.loads(html_text)
24+
if 'message' in json_data and json_data['message'] == 'SUCCESS':
25+
return True
26+
else:
27+
return False
28+
2129
html = etree.HTML(html_text)
2230
if not html:
2331
return False

app/sites/site_userinfo.py

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,56 +79,70 @@ def build(self, url, site_id, site_name,
7979
html_text = chrome.get_html()
8080
else:
8181
proxies = Config().get_proxies() if proxy else None
82-
res = RequestUtils(cookies=site_cookie,
83-
session=session,
84-
headers=ua,
85-
proxies=proxies
86-
).get_res(url=url)
82+
if 'm-team' in url:
83+
profile_url = url + '/api/member/profile'
84+
res = RequestUtils(cookies=site_cookie,
85+
session=session,
86+
headers=ua,
87+
proxies=proxies
88+
).post_res(url=profile_url, data={})
89+
else:
90+
res = RequestUtils(cookies=site_cookie,
91+
session=session,
92+
headers=ua,
93+
proxies=proxies
94+
).get_res(url=url)
8795
if res and res.status_code == 200:
8896
if "charset=utf-8" in res.text or "charset=UTF-8" in res.text:
8997
res.encoding = "UTF-8"
9098
else:
9199
res.encoding = res.apparent_encoding
92100
html_text = res.text
93-
# 第一次登录反爬
94-
if html_text.find("title") == -1:
95-
i = html_text.find("window.location")
96-
if i == -1:
101+
# 单独处理m-team
102+
if 'm-team' in url:
103+
json_data = json.loads(html_text)
104+
if 'message' in json_data and json_data['message'] != "SUCCESS":
97105
return None
98-
tmp_url = url + html_text[i:html_text.find(";")] \
99-
.replace("\"", "").replace("+", "").replace(" ", "").replace("window.location=", "")
100-
res = RequestUtils(cookies=site_cookie,
101-
session=session,
102-
headers=ua,
103-
proxies=proxies
104-
).get_res(url=tmp_url)
105-
if res and res.status_code == 200:
106-
if "charset=utf-8" in res.text or "charset=UTF-8" in res.text:
107-
res.encoding = "UTF-8"
108-
else:
109-
res.encoding = res.apparent_encoding
110-
html_text = res.text
111-
if not html_text:
106+
else:
107+
# 第一次登录反爬
108+
if html_text.find("title") == -1:
109+
i = html_text.find("window.location")
110+
if i == -1:
112111
return None
113-
else:
114-
log.error("【Sites】站点 %s 被反爬限制:%s, 状态码:%s" % (site_name, url, res.status_code))
115-
return None
116-
117-
# 兼容假首页情况,假首页通常没有 <link rel="search" 属性
118-
if '"search"' not in html_text and '"csrf-token"' not in html_text:
119-
res = RequestUtils(cookies=site_cookie,
120-
session=session,
121-
headers=ua,
122-
proxies=proxies
123-
).get_res(url=url + "/index.php")
124-
if res and res.status_code == 200:
125-
if "charset=utf-8" in res.text or "charset=UTF-8" in res.text:
126-
res.encoding = "UTF-8"
112+
tmp_url = url + html_text[i:html_text.find(";")] \
113+
.replace("\"", "").replace("+", "").replace(" ", "").replace("window.location=", "")
114+
res = RequestUtils(cookies=site_cookie,
115+
session=session,
116+
headers=ua,
117+
proxies=proxies
118+
).get_res(url=tmp_url)
119+
if res and res.status_code == 200:
120+
if "charset=utf-8" in res.text or "charset=UTF-8" in res.text:
121+
res.encoding = "UTF-8"
122+
else:
123+
res.encoding = res.apparent_encoding
124+
html_text = res.text
125+
if not html_text:
126+
return None
127127
else:
128-
res.encoding = res.apparent_encoding
129-
html_text = res.text
130-
if not html_text:
128+
log.error("【Sites】站点 %s 被反爬限制:%s, 状态码:%s" % (site_name, url, res.status_code))
131129
return None
130+
131+
# 兼容假首页情况,假首页通常没有 <link rel="search" 属性
132+
if '"search"' not in html_text and '"csrf-token"' not in html_text:
133+
res = RequestUtils(cookies=site_cookie,
134+
session=session,
135+
headers=ua,
136+
proxies=proxies
137+
).get_res(url=url + "/index.php")
138+
if res and res.status_code == 200:
139+
if "charset=utf-8" in res.text or "charset=UTF-8" in res.text:
140+
res.encoding = "UTF-8"
141+
else:
142+
res.encoding = res.apparent_encoding
143+
html_text = res.text
144+
if not html_text:
145+
return None
132146
elif res is not None:
133147
log.error(f"【Sites】站点 {site_name} 连接失败,状态码:{res.status_code}")
134148
return None

app/sites/siteconf.py

Lines changed: 88 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import pickle
33
import random
44
import time
5+
import re
6+
import json
57
from functools import lru_cache
68

79
from lxml import etree
10+
from urllib.parse import urlsplit
811

912
from app.helper import ChromeHelper
1013
from app.utils import ExceptionUtils, StringUtils, RequestUtils
@@ -115,66 +118,104 @@ def check_torrent_attr(self, torrent_url, cookie, ua=None, proxy=False):
115118
:return: 种子属性,包含FREE 2XFREE HR PEER_COUNT等属性
116119
"""
117120
ret_attr = {
118-
"free": False,
119-
"2xfree": False,
120-
"hr": False,
121-
"peer_count": 0
122-
}
123-
if not torrent_url:
124-
return ret_attr
125-
xpath_strs = self.get_grap_conf(torrent_url)
126-
if not xpath_strs:
127-
return ret_attr
128-
html_text = self.__get_site_page_html(url=torrent_url,
129-
cookie=cookie,
130-
ua=ua,
131-
render=xpath_strs.get('RENDER'),
132-
proxy=proxy)
133-
if not html_text:
134-
return ret_attr
135-
try:
136-
html = etree.HTML(html_text)
137-
# 检测2XFREE
138-
for xpath_str in xpath_strs.get("2XFREE"):
139-
if html.xpath(xpath_str):
140-
ret_attr["free"] = True
141-
ret_attr["2xfree"] = True
142-
# 检测FREE
143-
for xpath_str in xpath_strs.get("FREE"):
144-
if html.xpath(xpath_str):
145-
ret_attr["free"] = True
146-
# 检测HR
147-
for xpath_str in xpath_strs.get("HR"):
148-
if html.xpath(xpath_str):
149-
ret_attr["hr"] = True
150-
# 检测PEER_COUNT当前做种人数
151-
for xpath_str in xpath_strs.get("PEER_COUNT"):
152-
peer_count_dom = html.xpath(xpath_str)
153-
if peer_count_dom:
154-
peer_count_str = ''.join(peer_count_dom[0].itertext())
155-
peer_count_digit_str = ""
156-
for m in peer_count_str:
157-
if m.isdigit():
158-
peer_count_digit_str = peer_count_digit_str + m
159-
if m == " ":
160-
break
161-
ret_attr["peer_count"] = int(peer_count_digit_str) if len(peer_count_digit_str) > 0 else 0
162-
except Exception as err:
163-
ExceptionUtils.exception_traceback(err)
121+
"free": False,
122+
"2xfree": False,
123+
"hr": False,
124+
"peer_count": 0
125+
}
126+
if 'm-team' in torrent_url:
127+
split_url = urlsplit(torrent_url)
128+
base_url = f"{split_url.scheme}://{split_url.netloc}"
129+
detail_url = f"{base_url}/api/torrent/detail"
130+
res = re.findall(r'\d+', torrent_url)
131+
param = res[0]
132+
json_text = self.__get_site_page_html(url=detail_url,
133+
cookie=cookie,
134+
ua=ua,
135+
proxy=proxy,
136+
param=param)
137+
json_data = json.loads(json_text)
138+
if json_data['message'] != "SUCCESS":
139+
return ret_attr
140+
discount = json_data['data']['status']['discount']
141+
seeders = json_data['data']['status']['seeders']
142+
if discount == 'FREE':
143+
ret_attr["free"] = True
144+
ret_attr['peer_count'] = int(seeders)
145+
146+
else:
147+
if not torrent_url:
148+
return ret_attr
149+
xpath_strs = self.get_grap_conf(torrent_url)
150+
if not xpath_strs:
151+
return ret_attr
152+
html_text = self.__get_site_page_html(url=torrent_url,
153+
cookie=cookie,
154+
ua=ua,
155+
render=xpath_strs.get('RENDER'),
156+
proxy=proxy)
157+
if not html_text:
158+
return ret_attr
159+
try:
160+
html = etree.HTML(html_text)
161+
# 检测2XFREE
162+
for xpath_str in xpath_strs.get("2XFREE"):
163+
if html.xpath(xpath_str):
164+
ret_attr["free"] = True
165+
ret_attr["2xfree"] = True
166+
# 检测FREE
167+
for xpath_str in xpath_strs.get("FREE"):
168+
if html.xpath(xpath_str):
169+
ret_attr["free"] = True
170+
# 检测HR
171+
for xpath_str in xpath_strs.get("HR"):
172+
if html.xpath(xpath_str):
173+
ret_attr["hr"] = True
174+
# 检测PEER_COUNT当前做种人数
175+
for xpath_str in xpath_strs.get("PEER_COUNT"):
176+
peer_count_dom = html.xpath(xpath_str)
177+
if peer_count_dom:
178+
peer_count_str = ''.join(peer_count_dom[0].itertext())
179+
peer_count_digit_str = ""
180+
for m in peer_count_str:
181+
if m.isdigit():
182+
peer_count_digit_str = peer_count_digit_str + m
183+
if m == " ":
184+
break
185+
ret_attr["peer_count"] = int(peer_count_digit_str) if len(peer_count_digit_str) > 0 else 0
186+
except Exception as err:
187+
ExceptionUtils.exception_traceback(err)
164188
# 随机休眼后再返回
165189
time.sleep(round(random.uniform(1, 5), 1))
166190
return ret_attr
167191

168192
@staticmethod
169193
@lru_cache(maxsize=128)
170-
def __get_site_page_html(url, cookie, ua, render=False, proxy=False):
194+
def __get_site_page_html(url, cookie, ua, render=False, proxy=False, param=None):
171195
chrome = ChromeHelper(headless=True)
172196
if render and chrome.get_status():
173197
# 开渲染
174198
if chrome.visit(url=url, cookie=cookie, ua=ua, proxy=proxy):
175199
# 等待页面加载完成
176200
time.sleep(10)
177201
return chrome.get_html()
202+
elif 'm-team' in url:
203+
param = {'id': param}
204+
headers = {}
205+
headers.update({
206+
"User-Agent": f"{ua}"
207+
})
208+
headers.update({
209+
"contentType": 'application/json;charset=UTF-8'
210+
})
211+
res = RequestUtils(
212+
cookies=cookie,
213+
headers=headers,
214+
proxies=Config().get_proxies() if proxy else None
215+
).post_res(url=url, data=param)
216+
if res and res.status_code == 200:
217+
res.encoding = res.apparent_encoding
218+
return res.text
178219
else:
179220
res = RequestUtils(
180221
cookies=cookie,

app/sites/sites.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,18 @@ def test_connection(self, site_id):
288288
else:
289289
# 计时
290290
start_time = datetime.now()
291-
res = RequestUtils(cookies=site_cookie,
292-
headers=ua,
293-
proxies=Config().get_proxies() if site_info.get("proxy") else None
294-
).get_res(url=site_url)
291+
# m-team处理
292+
if 'm-team' in site_url:
293+
url = site_url + '/api/member/profile'
294+
res = RequestUtils(cookies=site_cookie,
295+
headers=ua,
296+
proxies=Config().get_proxies() if site_info.get("proxy") else None
297+
).post_res(url=url, data={})
298+
else:
299+
res = RequestUtils(cookies=site_cookie,
300+
headers=ua,
301+
proxies=Config().get_proxies() if site_info.get("proxy") else None
302+
).get_res(url=site_url)
295303
seconds = int((datetime.now() - start_time).microseconds / 1000)
296304
if res and res.status_code == 200:
297305
if not SiteHelper.is_logged_in(res.text):

0 commit comments

Comments
 (0)