douyinWEB/backend/tests/test_prefer_non_uhd_stream.py
2026-09-13 22:10:49 -05:00

47 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
from app.douyin import pick_stream_candidates, _is_uhd_stream_url
def test_prefer_non_uhd_over_origin():
room = {
"stream_url": {
"flv_pull_url": {
"ORIGIN": "http://cdn.example/stream_uhd.flv?unique_id=x_flv_uhd",
"FULL_HD1": "http://cdn.example/stream_full.flv?unique_id=x_flv",
"HD1": "http://cdn.example/stream_hd.flv?unique_id=x_hd_flv",
"SD1": "http://cdn.example/stream_sd.flv",
}
}
}
cands = pick_stream_candidates(room)
assert cands[0] == "http://cdn.example/stream_hd.flv?unique_id=x_hd_flv"
assert cands[1] == "http://cdn.example/stream_full.flv?unique_id=x_flv"
assert cands[-1].endswith("_uhd") or "_uhd" in cands[-1]
def test_demote_uhd_even_if_only_labeled_hd():
room = {
"stream_url": {
"flv_pull_url": {
"HD1": "http://cdn.example/foo_uhd.flv",
"SD1": "http://cdn.example/foo_sd.flv",
}
}
}
cands = pick_stream_candidates(room)
assert cands[0] == "http://cdn.example/foo_sd.flv"
assert _is_uhd_stream_url(cands[-1])
def test_uhd_only_still_usable():
room = {
"stream_url": {
"flv_pull_url": {
"ORIGIN": "http://cdn.example/only_uhd.flv",
}
}
}
cands = pick_stream_candidates(room)
assert len(cands) == 1
assert "uhd" in cands[0]