Add API endpoint to fetch YouTube transcripts

This commit is contained in:
syeopite
2024-06-11 18:31:41 -07:00
parent bad92093bf
commit 7693f61e44
3 changed files with 101 additions and 0 deletions

View File

@@ -122,5 +122,40 @@ module Invidious::Videos
return vtt
end
def to_json(json : JSON::Builder)
json.field "languageCode", @language_code
json.field "autoGenerated", @auto_generated
json.field "label", @label
json.field "body" do
json.array do
@lines.each do |line|
json.object do
if line.is_a? HeadingLine
json.field "type", "heading"
else
json.field "type", "regular"
end
json.field "startMs", line.start_ms.total_milliseconds
json.field "endMs", line.end_ms.total_milliseconds
json.field "line", line.line
end
end
end
end
end
def to_json
JSON.build do |json|
json.object do
json.field "transcript" do
json.object do
to_json(json)
end
end
end
end
end
end
end