diff --git a/py/tests/test_飞快TV.py b/py/tests/test_飞快TV.py index c5b3929..6fc2869 100644 --- a/py/tests/test_飞快TV.py +++ b/py/tests/test_飞快TV.py @@ -136,6 +136,23 @@ class TestFeikuaiSpider(unittest.TestCase): self.assertEqual(encoded["parse"], 0) self.assertEqual(encoded["url"], "https://cdn.example.com/v2.m3u8") + @patch.object(Spider, "_request_html") + def test_player_content_handles_live_nested_player_payload(self, mock_request_html): + mock_request_html.return_value = """ + + """ + result = self.spider.playerContent("feikuai", "/vodplay/236443-1-1.html", {}) + self.assertEqual(result["parse"], 0) + self.assertEqual(result["jx"], 0) + self.assertEqual(result["url"], "https://cdn.yzzyvip-29.com/20260425/23291_45967c73/index.m3u8") + @patch.object(Spider, "_request_html") def test_player_content_falls_back_when_script_missing(self, mock_request_html): mock_request_html.return_value = "empty" diff --git a/py/飞快TV.py b/py/飞快TV.py index 38d2585..7f68790 100644 --- a/py/飞快TV.py +++ b/py/飞快TV.py @@ -143,11 +143,40 @@ class Spider(BaseSpider): return "" def _extract_player_data(self, html): - matched = re.search(r"player_aaaa\s*=\s*(\{[\s\S]*?\})", str(html or "")) + body = str(html or "") + matched = re.search(r"player_aaaa\s*=\s*\{", body) if not matched: return {} + start = matched.end() - 1 + depth = 0 + in_string = False + escape = False + end = -1 + for index in range(start, len(body)): + char = body[index] + if in_string: + if escape: + escape = False + elif char == "\\": + escape = True + elif char == '"': + in_string = False + continue + if char == '"': + in_string = True + continue + if char == "{": + depth += 1 + continue + if char == "}": + depth -= 1 + if depth == 0: + end = index + 1 + break + if end < 0: + return {} try: - return json.loads(matched.group(1)) + return json.loads(body[start:end]) except Exception: return {}