feat: add docker match live stream crawler
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from match_live_stream import choose_next_fetch_at, parse_match_live_detail_html
|
||||
|
||||
|
||||
class MatchLiveStreamTest(unittest.TestCase):
|
||||
def test_parse_json_ncctrials_detail_extracts_four_urls(self):
|
||||
payload = {
|
||||
"code": 200,
|
||||
"msg": "ok",
|
||||
"data": {
|
||||
"stream": {
|
||||
"flv": "http://a/flv",
|
||||
"hdFlv": "http://a/hdflv",
|
||||
"m3u8": "http://a/m3u8",
|
||||
"hdM3u8": "http://a/hdm3u8",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
parsed = parse_match_live_detail_html(f"detail({json.dumps(payload, ensure_ascii=False)})")
|
||||
|
||||
self.assertEqual(parsed["play_url_m3u8"], "http://a/m3u8")
|
||||
self.assertEqual(parsed["play_url_hd_m3u8"], "http://a/hdm3u8")
|
||||
self.assertEqual(parsed["play_url_flv"], "http://a/flv")
|
||||
self.assertEqual(parsed["play_url_hd_flv"], "http://a/hdflv")
|
||||
|
||||
def test_choose_next_fetch_at_uses_60s_for_empty_streams(self):
|
||||
self.assertEqual(choose_next_fetch_at(now_ts=1000, has_existing_stream=False), 1060)
|
||||
|
||||
def test_choose_next_fetch_at_uses_600s_for_existing_streams(self):
|
||||
self.assertEqual(choose_next_fetch_at(now_ts=1000, has_existing_stream=True), 1600)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user