mirror of
https://github.com/iv-org/invidious.git
synced 2025-07-20 12:28:29 +00:00
Add separate method for constructing chapters json
This commit is contained in:
parent
4c47ff7463
commit
9601de6a24
@ -457,34 +457,7 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
if format == "json"
|
if format == "json"
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
response = JSON.build do |json|
|
response = Invidious::Videos::Chapters.to_json(chapters, video.automatically_generated_chapters?.as(Bool))
|
||||||
json.object do
|
|
||||||
json.field "chapters" do
|
|
||||||
json.field "autoGenerated", video.automatically_generated_chapters?
|
|
||||||
json.array do
|
|
||||||
chapters.each do |chapter|
|
|
||||||
json.object do
|
|
||||||
json.field "title", chapter.title
|
|
||||||
json.field "startMs", chapter.start_ms
|
|
||||||
json.field "endMs", chapter.end_ms
|
|
||||||
|
|
||||||
json.field "thumbnails" do
|
|
||||||
json.array do
|
|
||||||
chapter.thumbnails.each do |thumbnail|
|
|
||||||
json.object do
|
|
||||||
json.field "url", thumbnail["url"]
|
|
||||||
json.field "width", thumbnail["width"]
|
|
||||||
json.field "height", thumbnail["height"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
else
|
else
|
||||||
|
@ -83,4 +83,43 @@ module Invidious::Videos::Chapters
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.to_json(json : JSON::Builder, chapters : Array(Chapter), auto_generated? : Bool)
|
||||||
|
json.field "autoGenerated", auto_generated?.to_s
|
||||||
|
json.field "chapters" do
|
||||||
|
json.array do
|
||||||
|
chapters.each do |chapter|
|
||||||
|
json.object do
|
||||||
|
json.field "title", chapter.title
|
||||||
|
json.field "startMs", chapter.start_ms
|
||||||
|
json.field "endMs", chapter.end_ms
|
||||||
|
|
||||||
|
json.field "thumbnails" do
|
||||||
|
json.array do
|
||||||
|
chapter.thumbnails.each do |thumbnail|
|
||||||
|
json.object do
|
||||||
|
json.field "url", thumbnail["url"]
|
||||||
|
json.field "width", thumbnail["width"]
|
||||||
|
json.field "height", thumbnail["height"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.to_json(chapters : Array(Chapter), auto_generated? : Bool)
|
||||||
|
JSON.build do |json|
|
||||||
|
json.object do
|
||||||
|
json.field "chapters" do
|
||||||
|
json.object do
|
||||||
|
to_json(json, chapters, auto_generated?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user