mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:25:56 -04:00
Add separate method for constructing chapters json
This commit is contained in:
parent
3860c69a52
commit
6bddcea178
@ -434,34 +434,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