feat: 播放地址优先使用 playlist 并补充接口清单

This commit is contained in:
Nixevol
2026-09-25 23:49:19 +08:00
parent 1a26efd994
commit 00bf1361d3
2 changed files with 505 additions and 7 deletions
+35 -7
View File
@@ -268,7 +268,23 @@ def list_chapters(token, vid):
return chapters
def list_playlist(token, vid):
def _playlist_items(data):
if isinstance(data, list):
return data, len(data)
items = (data or {}).get("list") or []
total = (data or {}).get("count")
return items, total
def _playlist_complete(items, total):
if not items:
return False
if total is None:
return True
return len(items) >= int(total)
def list_playlist_v2(token, vid):
episodes = []
page = 1
total = None
@@ -278,12 +294,9 @@ def list_playlist(token, vid):
"page": page,
"before": 1 if page == 1 else 0,
})
if isinstance(data, list):
items = data
total = len(items)
else:
items = (data or {}).get("list") or []
total = (data or {}).get("count", total)
items, page_total = _playlist_items(data)
if page_total is not None:
total = page_total
if not items:
break
episodes.extend(items)
@@ -294,6 +307,21 @@ def list_playlist(token, vid):
return episodes
def list_playlist(token, vid):
try:
data = api("/app/video/playlist", token, "POST", {
"vid": vid, "page": 1, "before": 1,
})
items, total = _playlist_items(data)
if _playlist_complete(items, total):
return items
except Exception as exc:
print(f" playlist 失败,改用 playlistv2:{exc}", flush=True)
return list_playlist_v2(token, vid)
print(f" playlist 结果不完整,改用 playlistv2", flush=True)
return list_playlist_v2(token, vid)
def expand_hls(master_url):
"""把主 m3u8 展开成子播放列表和 ts 绝对地址。失败时只保留主地址。"""
if not master_url: