Merge 0c604ef4a88a918f2b9fcef11970c0469d6c7072 into 3b21f78e99c1416f65dd3e64f1aa43b2f4dcad7a

This commit is contained in:
volcanic001 2026-10-24 04:03:16 +07:00 committed by GitHub
commit 261e9d1b3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -105,12 +105,21 @@ module Invidious::Routes::API::V1::Videos
webvtt = transcript.to_vtt
else
# Timedtext API handling
url = URI.parse("#{caption.base_url}&tlang=#{tlang}").request_target
url = URI.parse(caption.base_url).request_target
# Youtube turns down anything that asks for a translation, and an empty
# tlang still counts as asking: it answers with its block page instead
# of the subtitle, whatever the rest of the request says. So it only
# goes on when a translation was actually asked for.
url += "&tlang=#{tlang}" if tlang && !tlang.empty?
# Auto-generated captions often have cues that aren't aligned properly with the video,
# as well as some other markup that makes it cumbersome, so we try to fix that here
if caption.name.includes? "auto-generated"
caption_xml = YT_POOL.client &.get(url).body
# The parser below reads timedtext format 3. Left to itself youtube
# now answers in the older <transcript> dialect, which comes out as a
# WebVTT file with no cues in it.
caption_xml = YT_POOL.client &.get("#{url}&fmt=srv3").body
settings_field = {
"Kind" => "captions",