From bfd82ae3bb92691576b126ed5ca5edbb9467a557 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 9 Oct 2023 10:24:25 -0400 Subject: [PATCH] Just a cleanup --- src/invidious/routes/api/manifest.cr | 43 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/invidious/routes/api/manifest.cr b/src/invidious/routes/api/manifest.cr index 692b845a..30f6cb41 100644 --- a/src/invidious/routes/api/manifest.cr +++ b/src/invidious/routes/api/manifest.cr @@ -139,43 +139,42 @@ module Invidious::Routes::API::Manifest # interval can be 0 https://github.com/iv-org/invidious/issues/3441 next if interval == 0 - storyboard_height = storyboard[:storyboard_height] + template_url = storyboard[:url] + # If the template changed from known format, abort. + next if !template_url.includes? "$M" - # BUG: storyboardHeight can be wrong https://github.com/iv-org/invidious/issues/3440 - # this fix/assumption is only if we have storyboard[:storyboard_count] = 1 - if storyboard[:storyboard_count] == 1 - storyboard_height = storyboard[:count] // storyboard[:storyboard_width] - if storyboard[:count] % storyboard[:storyboard_width] > 0 + storyboard_width = storyboard[:storyboard_width] + storyboard_height = storyboard[:storyboard_height] + storyboard_count = storyboard[:storyboard_count] + tile_width_pixels = storyboard[:width] + tile_height_pixels = storyboard[:height] + total_tile_count = storyboard[:count] + + # For the last page, the image height might be smaller than the storyboard height + if storyboard_count = 1 + storyboard_height = total_tile_count // storyboard_width + if total_tile_count % storyboard_width > 0 storyboard_height += 1 end end - - tiles_per_page = storyboard[:storyboard_width] * storyboard_height interval_seconds = interval // 1000 - template_url = storyboard[:url] - - # If the template changed from known format, abort. - next if !template_url.includes? "$M" - # Youtube template uses the var $M for tile pages # DASH-IF uses $Number$ in the SegmentTemplate url = template_url.gsub("$M", "$Number$") - storyboard_width = storyboard[:storyboard_width] + tiles_per_page = storyboard_width * storyboard_height + duration = tiles_per_page * interval_seconds - tile_count = tiles_per_page - duration = tile_count * interval_seconds - - width = storyboard[:width] * storyboard[:storyboard_width] - height = storyboard[:height] * storyboard_height + storyboard_width_pixels = tile_width_pixels * storyboard_width + storyboard_height_pixels = tile_height_pixels * storyboard_height # Bandwidth is kind of a guess... - bandwidth = ((width * height * 0.5) / duration).to_i - + bandwidth = ((storyboard_width_pixels * storyboard_height_pixels * 0.5) / duration).to_i + xml.element("AdaptationSet", id: i, mimeType: mime_type, contentType: "image") do xml.element("SegmentTemplate", media: url, duration: duration, startNumber: "0") - xml.element("Representation", id: "thumbnails_#{i}", bandwidth: bandwidth, width: width, height: height) do + xml.element("Representation", id: "thumbnails_#{i}", bandwidth: bandwidth, width: storyboard_width_pixels, height: storyboard_height_pixels) do xml.element("EssentialProperty", schemeIdUri: "http://dashif.org/guidelines/thumbnail_tile", value: "#{storyboard_width}x#{storyboard_height}") end end