diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2023-10-08 20:36:32 +0200 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2024-08-16 10:05:48 +0200 |
| commit | 7b50388eafcd458221f3deec03bf5a0829244529 (patch) | |
| tree | 261c593fcccc70207e07a9517cdfc2c0de0b1bd2 | |
| parent | da3d58f03c9b1617f96f4caf1e348a35105dd79c (diff) | |
| download | invidious-7b50388eafcd458221f3deec03bf5a0829244529.tar.gz invidious-7b50388eafcd458221f3deec03bf5a0829244529.tar.bz2 invidious-7b50388eafcd458221f3deec03bf5a0829244529.zip | |
Storyboards: Fix broken first storyboard
| -rw-r--r-- | src/invidious/videos.cr | 2 | ||||
| -rw-r--r-- | src/invidious/videos/storyboard.cr | 13 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 73321909..28cbb311 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -178,7 +178,7 @@ struct Video def storyboards container = info.dig?("storyboards") || JSON::Any.new("{}") - return IV::Videos::Storyboard.from_yt_json(container) + return IV::Videos::Storyboard.from_yt_json(container, self.length_seconds) end def paid diff --git a/src/invidious/videos/storyboard.cr b/src/invidious/videos/storyboard.cr index f6df187f..61aafe37 100644 --- a/src/invidious/videos/storyboard.cr +++ b/src/invidious/videos/storyboard.cr @@ -30,7 +30,7 @@ module Invidious::Videos end # Parse the JSON structure from Youtube - def self.from_yt_json(container : JSON::Any) : Array(Storyboard) + def self.from_yt_json(container : JSON::Any, length_seconds : Int32) : Array(Storyboard) # Livestream storyboards are a bit different # TODO: document exactly how if storyboard = container.dig?("playerLiveStoryboardSpecRenderer", "spec").try &.as_s @@ -70,8 +70,9 @@ module Invidious::Videos # columns/rows: maximum amount of thumbnails that can be stuffed in a # single image, horizontally and vertically. # interval: interval between two thumbnails, in milliseconds + # name: storyboard filename. Usually "M$M" or "default" # sigh: URL cryptographic signature - width, height, count, columns, rows, interval, _, sigh = sb.split("#") + width, height, count, columns, rows, interval, name, sigh = sb.split("#") width = width.to_i height = height.to_i @@ -85,7 +86,7 @@ module Invidious::Videos url.query = params.to_s # Replace the template parts with what we have - url.path = url.path.sub("$L", i).sub("$N", "M$M") + url.path = url.path.sub("$L", i).sub("$N", name) # This value represents the maximum amount of thumbnails that can fit # in a single image. The last image (or the only one for short videos) @@ -96,6 +97,12 @@ module Invidious::Videos # hold all of the thumbnails. It can't be less than 1. images_count = (count / thumbnails_per_image).ceil.to_i + # Compute the interval when needed (in general, that's only required + # for the first "default" storyboard). + if interval == 0 + interval = ((length_seconds / count) * 1_000).to_i + end + Storyboard.new( url: url, width: width, |
