mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Add 'lang' and 'tlang' to '/api/v1/captions'
This commit is contained in:
parent
20130db556
commit
a718d5543d
1 changed files with 13 additions and 5 deletions
|
@ -1766,7 +1766,10 @@ get "/api/v1/captions/:id" do |env|
|
||||||
captions = video.captions
|
captions = video.captions
|
||||||
|
|
||||||
label = env.params.query["label"]?
|
label = env.params.query["label"]?
|
||||||
if !label
|
lang = env.params.query["lang"]?
|
||||||
|
tlang = env.params.query["tlang"]?
|
||||||
|
|
||||||
|
if !label && !lang
|
||||||
response = JSON.build do |json|
|
response = JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
json.field "captions" do
|
json.field "captions" do
|
||||||
|
@ -1786,22 +1789,27 @@ get "/api/v1/captions/:id" do |env|
|
||||||
next response
|
next response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
env.response.content_type = "text/vtt"
|
||||||
|
|
||||||
caption = captions.select { |caption| caption.name.simpleText == label }
|
caption = captions.select { |caption| caption.name.simpleText == label }
|
||||||
|
|
||||||
env.response.content_type = "text/vtt"
|
if lang
|
||||||
|
caption = captions.select { |caption| caption.languageCode == lang }
|
||||||
|
end
|
||||||
|
|
||||||
if caption.empty?
|
if caption.empty?
|
||||||
halt env, status_code: 403
|
halt env, status_code: 404
|
||||||
else
|
else
|
||||||
caption = caption[0]
|
caption = caption[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
caption_xml = client.get(caption.baseUrl).body
|
caption_xml = client.get(caption.baseUrl + "&tlang=#{tlang}").body
|
||||||
caption_xml = XML.parse(caption_xml)
|
caption_xml = XML.parse(caption_xml)
|
||||||
|
|
||||||
webvtt = <<-END_VTT
|
webvtt = <<-END_VTT
|
||||||
WEBVTT
|
WEBVTT
|
||||||
Kind: captions
|
Kind: captions
|
||||||
Language: #{caption.languageCode}
|
Language: #{tlang || caption.languageCode}
|
||||||
|
|
||||||
|
|
||||||
END_VTT
|
END_VTT
|
||||||
|
|
Loading…
Reference in a new issue