Storyboards: Use replace the NamedTuple by a struct
This commit is contained in:
parent
6878822c4d
commit
8327862697
@ -273,15 +273,15 @@ module Invidious::JSONify::APIv1
|
||||
json.array do
|
||||
storyboards.each do |storyboard|
|
||||
json.object do
|
||||
json.field "url", "/api/v1/storyboards/#{id}?width=#{storyboard[:width]}&height=#{storyboard[:height]}"
|
||||
json.field "templateUrl", storyboard[:url]
|
||||
json.field "width", storyboard[:width]
|
||||
json.field "height", storyboard[:height]
|
||||
json.field "count", storyboard[:count]
|
||||
json.field "interval", storyboard[:interval]
|
||||
json.field "storyboardWidth", storyboard[:storyboard_width]
|
||||
json.field "storyboardHeight", storyboard[:storyboard_height]
|
||||
json.field "storyboardCount", storyboard[:storyboard_count]
|
||||
json.field "url", "/api/v1/storyboards/#{id}?width=#{storyboard.width}&height=#{storyboard.height}"
|
||||
json.field "templateUrl", storyboard.url
|
||||
json.field "width", storyboard.width
|
||||
json.field "height", storyboard.height
|
||||
json.field "count", storyboard.count
|
||||
json.field "interval", storyboard.interval
|
||||
json.field "storyboardWidth", storyboard.storyboard_width
|
||||
json.field "storyboardHeight", storyboard.storyboard_height
|
||||
json.field "storyboardCount", storyboard.storyboard_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -205,7 +205,7 @@ module Invidious::Routes::API::V1::Videos
|
||||
|
||||
env.response.content_type = "text/vtt"
|
||||
|
||||
storyboard = storyboards.select { |sb| width == "#{sb[:width]}" || height == "#{sb[:height]}" }
|
||||
storyboard = storyboards.select { |sb| width == "#{sb.width}" || height == "#{sb.height}" }
|
||||
|
||||
if storyboard.empty?
|
||||
haltf env, 404
|
||||
@ -215,21 +215,22 @@ module Invidious::Routes::API::V1::Videos
|
||||
|
||||
WebVTT.build do |vtt|
|
||||
start_time = 0.milliseconds
|
||||
end_time = storyboard[:interval].milliseconds
|
||||
end_time = storyboard.interval.milliseconds
|
||||
|
||||
storyboard[:storyboard_count].times do |i|
|
||||
url = storyboard[:url]
|
||||
storyboard.storyboard_count.times do |i|
|
||||
url = storyboard.url
|
||||
authority = /(i\d?).ytimg.com/.match!(url)[1]?
|
||||
|
||||
url = url.gsub("$M", i).gsub(%r(https://i\d?.ytimg.com/sb/), "")
|
||||
url = "#{HOST_URL}/sb/#{authority}/#{url}"
|
||||
|
||||
storyboard[:storyboard_height].times do |j|
|
||||
storyboard[:storyboard_width].times do |k|
|
||||
current_cue_url = "#{url}#xywh=#{storyboard[:width] * k},#{storyboard[:height] * j},#{storyboard[:width] - 2},#{storyboard[:height]}"
|
||||
storyboard.storyboard_height.times do |j|
|
||||
storyboard.storyboard_width.times do |k|
|
||||
current_cue_url = "#{url}#xywh=#{storyboard.width * k},#{storyboard.height * j},#{storyboard.width - 2},#{storyboard.height}"
|
||||
vtt.cue(start_time, end_time, current_cue_url)
|
||||
|
||||
start_time += storyboard[:interval].milliseconds
|
||||
end_time += storyboard[:interval].milliseconds
|
||||
start_time += storyboard.interval.milliseconds
|
||||
end_time += storyboard.interval.milliseconds
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,6 +3,21 @@ require "http/params"
|
||||
|
||||
module Invidious::Videos
|
||||
struct Storyboard
|
||||
getter url : String
|
||||
getter width : Int32
|
||||
getter height : Int32
|
||||
getter count : Int32
|
||||
getter interval : Int32
|
||||
getter storyboard_width : Int32
|
||||
getter storyboard_height : Int32
|
||||
getter storyboard_count : Int32
|
||||
|
||||
def initialize(
|
||||
*, @url, @width, @height, @count, @interval,
|
||||
@storyboard_width, @storyboard_height, @storyboard_count
|
||||
)
|
||||
end
|
||||
|
||||
# Parse the JSON structure from Youtube
|
||||
def self.from_yt_json(container : JSON::Any)
|
||||
storyboards = container.dig?("playerStoryboardSpecRenderer", "spec")
|
||||
@ -10,7 +25,7 @@ module Invidious::Videos
|
||||
|
||||
if !storyboards
|
||||
if storyboard = container.dig?("playerLiveStoryboardSpecRenderer", "spec").try &.as_s
|
||||
return [{
|
||||
return [Storyboard.new(
|
||||
url: storyboard.split("#")[0],
|
||||
width: 106,
|
||||
height: 60,
|
||||
@ -19,19 +34,11 @@ module Invidious::Videos
|
||||
storyboard_width: 3,
|
||||
storyboard_height: 3,
|
||||
storyboard_count: -1,
|
||||
}]
|
||||
)]
|
||||
end
|
||||
end
|
||||
|
||||
items = [] of NamedTuple(
|
||||
url: String,
|
||||
width: Int32,
|
||||
height: Int32,
|
||||
count: Int32,
|
||||
interval: Int32,
|
||||
storyboard_width: Int32,
|
||||
storyboard_height: Int32,
|
||||
storyboard_count: Int32)
|
||||
items = [] of Storyboard
|
||||
|
||||
return items if !storyboards
|
||||
|
||||
@ -51,7 +58,7 @@ module Invidious::Videos
|
||||
storyboard_height = storyboard_height.to_i
|
||||
storyboard_count = (count / (storyboard_width * storyboard_height)).ceil.to_i
|
||||
|
||||
items << {
|
||||
items << Storyboard.new(
|
||||
url: url.to_s.sub("$L", i).sub("$N", "M$M"),
|
||||
width: width,
|
||||
height: height,
|
||||
@ -59,8 +66,8 @@ module Invidious::Videos
|
||||
interval: interval,
|
||||
storyboard_width: storyboard_width,
|
||||
storyboard_height: storyboard_height,
|
||||
storyboard_count: storyboard_count,
|
||||
}
|
||||
storyboard_count: storyboard_count
|
||||
)
|
||||
end
|
||||
|
||||
items
|
||||
|
Loading…
Reference in New Issue
Block a user