feat: support YouTube VTT subtitle selection

This commit is contained in:
2026-10-27 13:05:56 +01:00
parent a2c8cc8e4d
commit 0641859d95
12 changed files with 449 additions and 25 deletions
+6 -1
View File
@@ -70,7 +70,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
captions = path.startswith("/captions/")
if alternate or captions:
path = "/" + path.split("/", 2)[2]
expected = "alternate-private" if alternate else "subtitle-private" if captions or path == "/english.jpeg" else "stream-private"
expected = "alternate-private" if alternate else "subtitle-private" if captions or path in ("/english.jpeg", "/denied.vtt") else "stream-private"
if self.headers.get("X-Resource") != expected:
errors.append("wrong resource headers: " + path)
self.send_error(403)
@@ -90,6 +90,11 @@ class Handler(http.server.BaseHTTPRequestHandler):
elif path == "/english.jpeg":
data = (b'WEBVTT\n\n00:00.000 --> 00:10.000\nAlternate English cue\n' if alternate else
b'WEBVTT\n\n00:00.000 --> 00:02.000\nFirst English cue\n\n00:02.000 --> 00:04.000\nSecond English cue\n')
if parse_qs(urlsplit(self.path).query).get("auto") == ["1"]:
data = data.replace(b"First English cue", b"First automatic cue").replace(b"Second English cue", b"Second automatic cue")
elif path == "/denied.vtt":
self.send_error(403)
return
elif path.startswith("/resolved-vod-") and path.endswith(".ts"):
data = (fixtures / path[1:]).read_bytes()
else: