fix: compress ddys detail ids
This commit is contained in:
@@ -53,7 +53,7 @@ class TestDDYSSpider(unittest.TestCase):
|
|||||||
cards,
|
cards,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"vod_id": "https://ddys.io/movie/test-title/",
|
"vod_id": "movie/test-title",
|
||||||
"vod_name": "测试电影",
|
"vod_name": "测试电影",
|
||||||
"vod_pic": "https://ddys.io/poster.jpg",
|
"vod_pic": "https://ddys.io/poster.jpg",
|
||||||
"vod_remarks": "HD",
|
"vod_remarks": "HD",
|
||||||
@@ -137,7 +137,7 @@ class TestDDYSSpider(unittest.TestCase):
|
|||||||
kwargs = mock_request_html.call_args.kwargs
|
kwargs = mock_request_html.call_args.kwargs
|
||||||
self.assertEqual(kwargs["method"], "POST")
|
self.assertEqual(kwargs["method"], "POST")
|
||||||
self.assertEqual(kwargs["data"], "q=%E7%B9%81%E8%8A%B1")
|
self.assertEqual(kwargs["data"], "q=%E7%B9%81%E8%8A%B1")
|
||||||
self.assertEqual(result["list"][0]["vod_id"], "https://ddys.io/anime/result/")
|
self.assertEqual(result["list"][0]["vod_id"], "anime/result")
|
||||||
self.assertEqual(result["pagecount"], 2)
|
self.assertEqual(result["pagecount"], 2)
|
||||||
|
|
||||||
def test_parse_detail_page_merges_direct_and_pan_sources(self):
|
def test_parse_detail_page_merges_direct_and_pan_sources(self):
|
||||||
@@ -158,7 +158,7 @@ class TestDDYSSpider(unittest.TestCase):
|
|||||||
</div>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
vod = self.spider._parse_detail_page(html, "https://ddys.io/anime/demo/")
|
vod = self.spider._parse_detail_page(html, "anime/demo")
|
||||||
self.assertEqual(vod["vod_name"], "低端示例")
|
self.assertEqual(vod["vod_name"], "低端示例")
|
||||||
self.assertEqual(vod["vod_pic"], "https://ddys.io/poster-detail.jpg")
|
self.assertEqual(vod["vod_pic"], "https://ddys.io/poster-detail.jpg")
|
||||||
self.assertEqual(vod["vod_year"], "2025")
|
self.assertEqual(vod["vod_year"], "2025")
|
||||||
@@ -188,9 +188,9 @@ class TestDDYSSpider(unittest.TestCase):
|
|||||||
<h1 class="text-xl md:text-3xl">详情标题</h1>
|
<h1 class="text-xl md:text-3xl">详情标题</h1>
|
||||||
<button onclick="switchSource(1, '/play/detail-demo', 'mp4')">直连</button>
|
<button onclick="switchSource(1, '/play/detail-demo', 'mp4')">直连</button>
|
||||||
"""
|
"""
|
||||||
result = self.spider.detailContent(["https://ddys.io/movie/demo/"])
|
result = self.spider.detailContent(["movie/demo"])
|
||||||
self.assertEqual(mock_request_html.call_args.args[0], "https://ddys.io/movie/demo/")
|
self.assertEqual(mock_request_html.call_args.args[0], "https://ddys.io/movie/demo/")
|
||||||
self.assertEqual(result["list"][0]["vod_id"], "https://ddys.io/movie/demo/")
|
self.assertEqual(result["list"][0]["vod_id"], "movie/demo")
|
||||||
self.assertEqual(result["list"][0]["vod_name"], "详情标题")
|
self.assertEqual(result["list"][0]["vod_name"], "详情标题")
|
||||||
self.assertEqual(result["list"][0]["vod_play_from"], "直连")
|
self.assertEqual(result["list"][0]["vod_play_from"], "直连")
|
||||||
self.assertEqual(result["list"][0]["vod_play_url"], "全集$/play/detail-demo")
|
self.assertEqual(result["list"][0]["vod_play_url"], "全集$/play/detail-demo")
|
||||||
|
|||||||
+16
-2
@@ -157,6 +157,17 @@ class Spider(BaseSpider):
|
|||||||
return self.host + raw
|
return self.host + raw
|
||||||
return self.host + "/" + raw
|
return self.host + "/" + raw
|
||||||
|
|
||||||
|
def _extract_site_path_id(self, href):
|
||||||
|
full = self._build_url(href)
|
||||||
|
matched = re.search(r"https?://[^/]+/(movie|series|variety|anime)/([^/?#]+)/?$", full)
|
||||||
|
if not matched:
|
||||||
|
return ""
|
||||||
|
return f"{matched.group(1)}/{matched.group(2)}"
|
||||||
|
|
||||||
|
def _build_detail_request_url(self, vod_id):
|
||||||
|
value = self._stringify(vod_id).strip().strip("/")
|
||||||
|
return self._build_url(value + "/") if value else ""
|
||||||
|
|
||||||
def _build_category_url(self, tid, pg, extend):
|
def _build_category_url(self, tid, pg, extend):
|
||||||
values = dict(self.filter_def.get(str(tid), {"cateId": str(tid)}))
|
values = dict(self.filter_def.get(str(tid), {"cateId": str(tid)}))
|
||||||
values.update(self._normalize_ext(extend))
|
values.update(self._normalize_ext(extend))
|
||||||
@@ -201,7 +212,7 @@ class Spider(BaseSpider):
|
|||||||
or ((node.xpath(".//img[1]/@data-src") or [""])[0]).strip()
|
or ((node.xpath(".//img[1]/@data-src") or [""])[0]).strip()
|
||||||
)
|
)
|
||||||
remarks = self._clean_text("".join(node.xpath(".//*[contains(@class,'poster-badge')][1]//text()")))
|
remarks = self._clean_text("".join(node.xpath(".//*[contains(@class,'poster-badge')][1]//text()")))
|
||||||
vod_id = self._build_url(href)
|
vod_id = self._extract_site_path_id(href)
|
||||||
if not vod_id or not title or vod_id in seen:
|
if not vod_id or not title or vod_id in seen:
|
||||||
continue
|
continue
|
||||||
seen.add(vod_id)
|
seen.add(vod_id)
|
||||||
@@ -332,7 +343,10 @@ class Spider(BaseSpider):
|
|||||||
vod_id = self._stringify(raw_id).strip()
|
vod_id = self._stringify(raw_id).strip()
|
||||||
if not vod_id:
|
if not vod_id:
|
||||||
continue
|
continue
|
||||||
vod = self._parse_detail_page(self._request_html(vod_id), vod_id)
|
request_url = self._build_detail_request_url(vod_id)
|
||||||
|
if not request_url:
|
||||||
|
continue
|
||||||
|
vod = self._parse_detail_page(self._request_html(request_url), vod_id)
|
||||||
result["list"].append(vod)
|
result["list"].append(vod)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user