Invidious is an alternative front-end to YouTube
Add 'lang' and 'tlang' to '/api/v1/captions'
Omar Rotha718d5543d91
diff --git a/src/invidious.cr b/src/invidious.crindex 383a12d7..a52eb311 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -1766,7 +1766,10 @@ get "/api/v1/captions/:id" do |env|captions = video.captionslabel = env.params.query["label"]?- if !label+ lang = env.params.query["lang"]?+ tlang = env.params.query["tlang"]?++ if !label && !langresponse = JSON.build do |json|json.object dojson.field "captions" do@@ -1786,22 +1789,27 @@ get "/api/v1/captions/:id" do |env|next responseend+ env.response.content_type = "text/vtt"+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?- halt env, status_code: 403+ halt env, status_code: 404elsecaption = caption[0]end- caption_xml = client.get(caption.baseUrl).body+ caption_xml = client.get(caption.baseUrl + "&tlang=#{tlang}").bodycaption_xml = XML.parse(caption_xml)webvtt = <<-END_VTTWEBVTTKind: captions- Language: #{caption.languageCode}+ Language: #{tlang || caption.languageCode}END_VTT