diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-09-30 10:13:07 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-09-30 10:13:07 -0500 |
| commit | a718d5543d918f956e3339df1260d9620f902270 (patch) | |
| tree | c46d53e07cf0e6591bd94dcaf099caedd4f316bf | |
| parent | 20130db556c575e4434b1ce8a1429bc8b4ddbdf2 (diff) | |
| download | invidious-a718d5543d918f956e3339df1260d9620f902270.tar.gz invidious-a718d5543d918f956e3339df1260d9620f902270.tar.bz2 invidious-a718d5543d918f956e3339df1260d9620f902270.zip | |
Add 'lang' and 'tlang' to '/api/v1/captions'
| -rw-r--r-- | src/invidious.cr | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 383a12d7..a52eb311 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1766,7 +1766,10 @@ get "/api/v1/captions/:id" do |env| captions = video.captions 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| json.object do json.field "captions" do @@ -1786,22 +1789,27 @@ get "/api/v1/captions/:id" do |env| next response end + 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: 404 else caption = caption[0] end - caption_xml = client.get(caption.baseUrl).body + caption_xml = client.get(caption.baseUrl + "&tlang=#{tlang}").body caption_xml = XML.parse(caption_xml) webvtt = <<-END_VTT WEBVTT Kind: captions - Language: #{caption.languageCode} + Language: #{tlang || caption.languageCode} END_VTT |
