Invidious is an alternative front-end to YouTube
Storyboards: Use replace the NamedTuple by a struct
Samantaz Fox832786269777
diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.crindex 59714828..44a34b18 100644--- a/src/invidious/jsonify/api_v1/video_json.cr+++ b/src/invidious/jsonify/api_v1/video_json.cr@@ -273,15 +273,15 @@ module Invidious::JSONify::APIv1json.array dostoryboards.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_countendendenddiff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.crindex 42282f44..78f91a2e 100644--- a/src/invidious/routes/api/v1/videos.cr+++ b/src/invidious/routes/api/v1/videos.cr@@ -205,7 +205,7 @@ module Invidious::Routes::API::V1::Videosenv.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::VideosWebVTT.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.urlauthority = /(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.millisecondsendendenddiff --git a/src/invidious/videos/storyboard.cr b/src/invidious/videos/storyboard.crindex b4302d88..797fba12 100644--- a/src/invidious/videos/storyboard.cr+++ b/src/invidious/videos/storyboard.cr@@ -3,6 +3,21 @@ require "http/params"module Invidious::Videosstruct 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 Youtubedef self.from_yt_json(container : JSON::Any)storyboards = container.dig?("playerStoryboardSpecRenderer", "spec")@@ -10,28 +25,20 @@ module Invidious::Videosif !storyboardsif storyboard = container.dig?("playerLiveStoryboardSpecRenderer", "spec").try &.as_s- return [{- url: storyboard.split("#")[0],- width: 106,- height: 60,- count: -1,- interval: 5000,- storyboard_width: 3,+ return [Storyboard.new(+ url: storyboard.split("#")[0],+ width: 106,+ height: 60,+ count: -1,+ interval: 5000,+ storyboard_width: 3,storyboard_height: 3,- storyboard_count: -1,- }]+ storyboard_count: -1,+ )]endend- items = [] of NamedTuple(- url: String,- width: Int32,- height: Int32,- count: Int32,- interval: Int32,- storyboard_width: Int32,- storyboard_height: Int32,- storyboard_count: Int32)+ items = [] of Storyboardreturn items if !storyboards@@ -51,16 +58,16 @@ module Invidious::Videosstoryboard_height = storyboard_height.to_istoryboard_count = (count / (storyboard_width * storyboard_height)).ceil.to_i- items << {- url: url.to_s.sub("$L", i).sub("$N", "M$M"),- width: width,- height: height,- count: count,- interval: interval,- storyboard_width: storyboard_width,+ items << Storyboard.new(+ url: url.to_s.sub("$L", i).sub("$N", "M$M"),+ width: width,+ height: height,+ count: count,+ interval: interval,+ storyboard_width: storyboard_width,storyboard_height: storyboard_height,- storyboard_count: storyboard_count,- }+ storyboard_count: storyboard_count+ )enditems