fix: 黄豆按站点方式保持登录并自动切换播放线路

This commit is contained in:
Nixevol
2026-10-25 05:40:19 +08:00
parent 3fe936fe70
commit f53498f6e6
11 changed files with 444 additions and 197 deletions
+33 -17
View File
@@ -1,5 +1,6 @@
from server.services.downloads import _local_master
from server.services.huangdou.playlist import _choose_src
from server.services.huangdou.client import present_token
from server.services.huangdou.playlist import _choose_src, _ordered_line_urls, pick_line
from server.services.playlist import expand_variant, is_direct_media, is_media_playlist
@@ -21,27 +22,15 @@ def test_direct_media_and_hls_choice() -> None:
assert kind == "hls"
assert src.endswith("play.m3u8?x=1")
from server.services.huangdou.client import client
client.play_line = "line2"
src, kind = _choose_src({
"m3u8": "https://host.example/play.m3u8?line=free",
"m3u8": "https://host.example/chapters/3/preview.mp4",
"lines": [
{"name": "free", "url": "https://host.example/play.m3u8?line=free"},
{"name": "line2", "url": "https://host.example/play.m3u8?line=line2"},
{"name": "free", "url": "https://host.example/chapters/3/preview.mp4"},
{"name": "line2", "url": "https://host.example/chapters/3/play.m3u8"},
],
})
assert kind == "hls"
assert "line=line2" in src
client.play_line = ""
src, kind = _choose_src({
"m3u8": "https://host.example/play.m3u8?line=free",
"lines": [
{"name": "free", "url": "https://host.example/play.m3u8?line=free"},
{"name": "line2", "url": "https://host.example/play.m3u8?line=line2"},
],
})
assert "line=free" in src
assert src.endswith("play.m3u8")
src, kind = _choose_src({
"m3u8": "",
@@ -51,6 +40,24 @@ def test_direct_media_and_hls_choice() -> None:
assert kind == "file"
assert src.endswith(".mp4")
played = {
"m3u8": "https://host.example/api/drama/hls/id/3/play.m3u8?line=free",
"preview_m3u8": "https://cdn.example/chapters/3/preview.mp4",
"lines": [
{"name": "free", "url": "https://host.example/api/drama/hls/id/3/play.m3u8?line=free"},
{"name": "line2", "url": "https://host.example/api/drama/hls/id/3/play.m3u8?line=line2"},
{"name": "line3", "url": "https://host.example/api/drama/hls/id/3/play.m3u8?line=line3"},
],
}
ordered = _ordered_line_urls(played, played["lines"][1]["url"])
assert [item.split("line=")[1] for item in ordered] == ["line2", "free", "line3"]
row = {"src": ordered[0], "line_urls": ordered}
assert pick_line(row, 0).endswith("line=line2")
assert pick_line(row, 1).endswith("line=free")
assert pick_line(row, 3) == ""
assert pick_line({"src": "https://cdn.example/chapters/3/preview.mp4", "line_urls": []}, 0).endswith("preview.mp4")
assert pick_line({"src": "https://cdn.example/chapters/3/preview.mp4", "line_urls": []}, 1) == ""
try:
expand_variant("https://cdn.example/preview-r10.mp4")
except RuntimeError as exc:
@@ -59,6 +66,14 @@ def test_direct_media_and_hls_choice() -> None:
raise AssertionError("mp4 不应走播放列表")
def test_request_token_includes_user_id() -> None:
assert present_token("abc", "12345678") == "abc_12345678"
assert present_token("a_bc", "12345678") == "a_bc_12345678"
assert present_token("abc_12345678", "12345678") == "abc_12345678"
assert present_token("abc", "") == "abc"
assert present_token("", "12345678") == ""
def test_catalog_follows_pages_until_the_api_stops() -> None:
from server.services.huangdou.catalog import _take_new
@@ -81,5 +96,6 @@ def test_catalog_follows_pages_until_the_api_stops() -> None:
if __name__ == "__main__":
test_direct_media_and_hls_choice()
test_request_token_includes_user_id()
test_catalog_follows_pages_until_the_api_stops()
print("ok")