summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2023-10-08 12:58:04 +0200
committerSamantaz Fox <coding@samantaz.fr>2024-08-16 10:02:52 +0200
commit6878822c4d621bc2a2ba65c117efc65246e9a1ca (patch)
tree62e3e057cf9a519f9fa9d84d1aa4bf063d370aa0 /src
parente319c35f097e08590e705378c7e5b479720deabc (diff)
downloadinvidious-6878822c4d621bc2a2ba65c117efc65246e9a1ca.tar.gz
invidious-6878822c4d621bc2a2ba65c117efc65246e9a1ca.tar.bz2
invidious-6878822c4d621bc2a2ba65c117efc65246e9a1ca.zip
Storyboards: Move parser to its own file
Diffstat (limited to 'src')
-rw-r--r--src/invidious/videos.cr61
-rw-r--r--src/invidious/videos/storyboard.cr69
2 files changed, 71 insertions, 59 deletions
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 6d0cf9ba..73321909 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -177,65 +177,8 @@ struct Video
# Misc. methods
def storyboards
- storyboards = info.dig?("storyboards", "playerStoryboardSpecRenderer", "spec")
- .try &.as_s.split("|")
-
- if !storyboards
- if storyboard = info.dig?("storyboards", "playerLiveStoryboardSpecRenderer", "spec").try &.as_s
- return [{
- url: storyboard.split("#")[0],
- width: 106,
- height: 60,
- count: -1,
- interval: 5000,
- 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)
-
- return items if !storyboards
-
- url = URI.parse(storyboards.shift)
- params = HTTP::Params.parse(url.query || "")
-
- storyboards.each_with_index do |sb, i|
- width, height, count, storyboard_width, storyboard_height, interval, _, sigh = sb.split("#")
- params["sigh"] = sigh
- url.query = params.to_s
-
- width = width.to_i
- height = height.to_i
- count = count.to_i
- interval = interval.to_i
- storyboard_width = storyboard_width.to_i
- storyboard_height = storyboard_height.to_i
- storyboard_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,
- storyboard_height: storyboard_height,
- storyboard_count: storyboard_count,
- }
- end
-
- items
+ container = info.dig?("storyboards") || JSON::Any.new("{}")
+ return IV::Videos::Storyboard.from_yt_json(container)
end
def paid
diff --git a/src/invidious/videos/storyboard.cr b/src/invidious/videos/storyboard.cr
new file mode 100644
index 00000000..b4302d88
--- /dev/null
+++ b/src/invidious/videos/storyboard.cr
@@ -0,0 +1,69 @@
+require "uri"
+require "http/params"
+
+module Invidious::Videos
+ struct Storyboard
+ # Parse the JSON structure from Youtube
+ def self.from_yt_json(container : JSON::Any)
+ storyboards = container.dig?("playerStoryboardSpecRenderer", "spec")
+ .try &.as_s.split("|")
+
+ if !storyboards
+ if storyboard = container.dig?("playerLiveStoryboardSpecRenderer", "spec").try &.as_s
+ return [{
+ url: storyboard.split("#")[0],
+ width: 106,
+ height: 60,
+ count: -1,
+ interval: 5000,
+ 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)
+
+ return items if !storyboards
+
+ url = URI.parse(storyboards.shift)
+ params = HTTP::Params.parse(url.query || "")
+
+ storyboards.each_with_index do |sb, i|
+ width, height, count, storyboard_width, storyboard_height, interval, _, sigh = sb.split("#")
+ params["sigh"] = sigh
+ url.query = params.to_s
+
+ width = width.to_i
+ height = height.to_i
+ count = count.to_i
+ interval = interval.to_i
+ storyboard_width = storyboard_width.to_i
+ storyboard_height = storyboard_height.to_i
+ storyboard_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,
+ storyboard_height: storyboard_height,
+ storyboard_count: storyboard_count,
+ }
+ end
+
+ items
+ end
+ end
+end