From bbdbb0a4711a525525ae2d47e785c0cf4211ad68 Mon Sep 17 00:00:00 2001 From: Harold <8866033@gmail.com> Date: Fri, 24 Apr 2026 19:21:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=A4=E4=B8=AABT=20=E6=96=B0=E9=9F=A9?= =?UTF-8?q?=E5=89=A7=E7=BD=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/tests/test_两个BT.py | 161 ++++++++++++++++--- py/tests/test_新韩剧网.py | 235 ++++++++++++++++++++++++++++ py/两个BT.py | 258 ++++++++++++++++++++++++++++--- py/新韩剧网.py | 316 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 933 insertions(+), 37 deletions(-) create mode 100644 py/tests/test_新韩剧网.py create mode 100644 py/新韩剧网.py diff --git a/py/tests/test_两个BT.py b/py/tests/test_两个BT.py index 0dc9140..fb4fd39 100644 --- a/py/tests/test_两个BT.py +++ b/py/tests/test_两个BT.py @@ -1,7 +1,7 @@ import unittest from importlib.machinery import SourceFileLoader from pathlib import Path -from unittest.mock import patch +from unittest.mock import MagicMock, patch ROOT = Path(__file__).resolve().parents[1] @@ -63,6 +63,31 @@ class TestLiangGeBTSpider(unittest.TestCase): ], ) + def test_extract_cards_supports_current_play_cards(self): + html = """ +
+ """ + cards = self.spider._extract_cards(html) + self.assertEqual( + cards, + [ + { + "vod_id": "/play/ch42nt5hw", + "vod_name": "夜魔侠:重生 第二季", + "vod_pic": "https://img.example/poster.jpg", + "vod_remarks": "更新至6集", + } + ], + ) + @patch.object(Spider, "_request_html") def test_home_video_content_requests_home_page(self, mock_request_html): mock_request_html.return_value = """ @@ -80,53 +105,65 @@ class TestLiangGeBTSpider(unittest.TestCase): @patch.object(Spider, "_request_html") def test_category_content_builds_expected_urls(self, mock_request_html): mock_request_html.return_value = """ -
+
+
+ 夜幕降临,魔影共舞。
+ + + + """ + result = self.spider.detailContent(["/play/ch42nt5hw"]) + vod = result["list"][0] + first_name, first_id = vod["vod_play_url"].split("#")[0].split("$", 1) + self.assertEqual(mock_request_html.call_args.args[0], "https://www.bttwoo.com/play/ch42nt5hw") + self.assertEqual(vod["vod_id"], "/play/ch42nt5hw") + self.assertEqual(vod["vod_name"], "夜魔侠:重生 第二季") + self.assertEqual(vod["vod_pic"], "https://img.example/poster.jpg") + self.assertEqual(vod["vod_content"], "夜幕降临,魔影共舞。") + self.assertEqual(vod["vod_actor"], "查理·考克斯 / 文森特·多诺费奥") + self.assertEqual(vod["vod_director"], "贾斯汀·本森 / 艾伦·穆尔黑德") + self.assertEqual(first_name, "1") + self.assertEqual(self.spider._decode_play_id(first_id)["pid"], "/play/ch42nt5hw") + def test_player_content_passthroughs_direct_media_url(self): result = self.spider.playerContent("两个BT", "https://media.example/direct.m3u8", {}) self.assertEqual(result["parse"], 0) @@ -176,6 +252,53 @@ class TestLiangGeBTSpider(unittest.TestCase): self.assertEqual(result["url"], "https://media.example/direct.m3u8") self.assertEqual(result["header"]["Referer"], "https://www.bttwoo.com/") + @patch.object(Spider, "_request_html") + def test_player_content_supports_current_play_page_ids(self, mock_request_html): + mock_request_html.return_value = "empty" + play_id = self.spider._encode_play_id("/play/ch42nt5hw", "/play/ch42nt5hw", "1") + result = self.spider.playerContent("两个BT", play_id, {}) + self.assertEqual(mock_request_html.call_args.args[0], "https://www.bttwoo.com/play/ch42nt5hw") + self.assertEqual(result["parse"], 1) + self.assertEqual(result["jx"], 1) + self.assertEqual(result["url"], "https://www.bttwoo.com/play/ch42nt5hw") + + @patch.object(Spider, "fetch") + @patch.object(Spider, "_build_wasm_play_api_url") + @patch.object(Spider, "_cache_wasm_assets") + @patch.object(Spider, "_request_html") + def test_player_content_resolves_current_play_page_via_play_api( + self, mock_request_html, mock_cache_wasm_assets, mock_build_wasm_play_api_url, mock_fetch + ): + mock_request_html.return_value = """ + + + + +