diff options
| author | syeopite <syeopite@syeopite.dev> | 2024-06-13 10:56:18 -0700 |
|---|---|---|
| committer | syeopite <syeopite@syeopite.dev> | 2024-07-11 09:37:18 -0700 |
| commit | b2f5b1eb68382079f4d88792b8f3f79635125254 (patch) | |
| tree | bd2db30da82fb0c73637a24482db9f500ed3dd66 /src | |
| parent | 7693f61e4476e40adf4e505f04f26d98a855ecc3 (diff) | |
| download | invidious-b2f5b1eb68382079f4d88792b8f3f79635125254.tar.gz invidious-b2f5b1eb68382079f4d88792b8f3f79635125254.tar.bz2 invidious-b2f5b1eb68382079f4d88792b8f3f79635125254.zip | |
Add logic to fetch transcripts from label
Although available this method should be discouraged as it requires
an extra request to YouTube to get caption data in order to
map label -> language code and auto-generated status, which are needed
to fetch transcripts.
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/routes/api/v1/videos.cr | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index 03fdc49b..85a208c7 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -421,10 +421,11 @@ module Invidious::Routes::API::V1::Videos id = env.params.url["id"] lang = env.params.query["lang"]? + label = env.params.query["label"]? auto_generated = env.params.query["autogen"]? ? true : false # Return all available transcript options when none is given - if !lang + if !label && !lang begin video = get_video(id) rescue ex : NotFoundException @@ -462,6 +463,26 @@ module Invidious::Routes::API::V1::Videos return response end + # If lang is not given then we attempt to fetch + # the transcript through the given label + if lang.nil? + begin + video = get_video(id) + rescue ex : NotFoundException + return error_json(404, ex) + rescue ex + return error_json(500, ex) + end + + target_transcript = video.captions.select(&.name.== label) + if target_transcript.empty? + return error_json(404, NotFoundException.new("Requested transcript does not exist")) + else + target_transcript = target_transcript[0] + lang, auto_generated = target_transcript.language_code, target_transcript.auto_generated + end + end + params = Invidious::Videos::Transcript.generate_param(id, lang, auto_generated) begin |
