修复网盘排序
This commit is contained in:
@@ -143,6 +143,33 @@ class TestDidaSpider(unittest.TestCase):
|
|||||||
self.assertEqual(result["list"][0]["vod_play_from"], "uc")
|
self.assertEqual(result["list"][0]["vod_play_from"], "uc")
|
||||||
self.assertEqual(result["list"][0]["vod_play_url"], "合集$https://drive.uc.cn/s/u1")
|
self.assertEqual(result["list"][0]["vod_play_url"], "合集$https://drive.uc.cn/s/u1")
|
||||||
|
|
||||||
|
def test_extract_netdisk_groups_ignores_non_netdisk_external_links(self):
|
||||||
|
html = """
|
||||||
|
<div class="download-panel">
|
||||||
|
<p class="text-muted col-pd"><b>豆瓣:</b><a href="https://movie.douban.com/subject/37147970/">豆瓣详情</a></p>
|
||||||
|
<p class="text-muted col-pd"><b>夸克:</b><a href="https://pan.quark.cn/s/q1">查看</a></p>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
self.assertEqual(
|
||||||
|
self.spider._extract_netdisk_groups(html),
|
||||||
|
[{"from": "quark", "urls": "查看$https://pan.quark.cn/s/q1"}],
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_extract_netdisk_groups_prioritizes_domain_over_generic_label(self):
|
||||||
|
html = """
|
||||||
|
<div class="download-panel">
|
||||||
|
<p class="text-muted col-pd"><b>UC 网盘:</b><a href="https://drive.uc.cn/s/u1">UC合集</a></p>
|
||||||
|
<p class="text-muted col-pd"><b>资源链接:</b><a href="https://pan.baidu.com/s/b1">百度合集</a></p>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
self.assertEqual(
|
||||||
|
self.spider._extract_netdisk_groups(html),
|
||||||
|
[
|
||||||
|
{"from": "baidu", "urls": "百度合集$https://pan.baidu.com/s/b1"},
|
||||||
|
{"from": "uc", "urls": "UC合集$https://drive.uc.cn/s/u1"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def test_player_content_returns_direct_netdisk_link(self):
|
def test_player_content_returns_direct_netdisk_link(self):
|
||||||
result = self.spider.playerContent("quark", "https://pan.quark.cn/s/demo", {})
|
result = self.spider.playerContent("quark", "https://pan.quark.cn/s/demo", {})
|
||||||
self.assertEqual(result, {"parse": 0, "playUrl": "", "url": "https://pan.quark.cn/s/demo"})
|
self.assertEqual(result, {"parse": 0, "playUrl": "", "url": "https://pan.quark.cn/s/demo"})
|
||||||
|
|||||||
+18
-5
@@ -170,9 +170,8 @@ class Spider(BaseSpider):
|
|||||||
return {
|
return {
|
||||||
"list": items,
|
"list": items,
|
||||||
"page": page,
|
"page": page,
|
||||||
"pagecount": page + 1 if items else page,
|
|
||||||
"limit": 12,
|
"limit": 12,
|
||||||
"total": page * 12 + len(items),
|
"total": page * 30 + len(items),
|
||||||
}
|
}
|
||||||
|
|
||||||
def searchContent(self, key, quick, pg="1"):
|
def searchContent(self, key, quick, pg="1"):
|
||||||
@@ -210,6 +209,20 @@ class Spider(BaseSpider):
|
|||||||
return "xunlei"
|
return "xunlei"
|
||||||
return value or "netdisk"
|
return value or "netdisk"
|
||||||
|
|
||||||
|
def _normalize_disk_name_from_url(self, value):
|
||||||
|
text = self._stringify(value).strip().lower()
|
||||||
|
if "pan.baidu.com" in text:
|
||||||
|
return "baidu"
|
||||||
|
if "pan.quark.cn" in text:
|
||||||
|
return "quark"
|
||||||
|
if "drive.uc.cn" in text:
|
||||||
|
return "uc"
|
||||||
|
if "alipan.com" in text or "aliyundrive.com" in text:
|
||||||
|
return "aliyun"
|
||||||
|
if "pan.xunlei.com" in text:
|
||||||
|
return "xunlei"
|
||||||
|
return ""
|
||||||
|
|
||||||
def _disk_priority(self, name):
|
def _disk_priority(self, name):
|
||||||
order = {"baidu": 1, "quark": 2, "uc": 3, "aliyun": 4, "xunlei": 5}
|
order = {"baidu": 1, "quark": 2, "uc": 3, "aliyun": 4, "xunlei": 5}
|
||||||
return order.get(name, 999)
|
return order.get(name, 999)
|
||||||
@@ -222,11 +235,11 @@ class Spider(BaseSpider):
|
|||||||
order_seen = []
|
order_seen = []
|
||||||
for row in root.xpath("//*[contains(@class,'text-muted') and contains(@class,'col-pd')]"):
|
for row in root.xpath("//*[contains(@class,'text-muted') and contains(@class,'col-pd')]"):
|
||||||
raw_name = self._clean_text("".join(row.xpath(".//b[1]//text()"))).replace(":", "")
|
raw_name = self._clean_text("".join(row.xpath(".//b[1]//text()"))).replace(":", "")
|
||||||
disk_name = self._normalize_disk_name(raw_name)
|
|
||||||
href = ((row.xpath(".//a[@href][1]/@href") or [""])[0]).strip()
|
href = ((row.xpath(".//a[@href][1]/@href") or [""])[0]).strip()
|
||||||
title = self._clean_text("".join(row.xpath(".//a[1]//text()"))) or disk_name
|
if not href or not self._is_netdisk_url(href):
|
||||||
if not href:
|
|
||||||
continue
|
continue
|
||||||
|
disk_name = self._normalize_disk_name_from_url(href) or self._normalize_disk_name(raw_name)
|
||||||
|
title = self._clean_text("".join(row.xpath(".//a[1]//text()"))) or disk_name
|
||||||
if disk_name not in grouped:
|
if disk_name not in grouped:
|
||||||
grouped[disk_name] = []
|
grouped[disk_name] = []
|
||||||
order_seen.append(disk_name)
|
order_seen.append(disk_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user