Just a cleanup

This commit is contained in:
Brahim Hadriche 2023-10-09 10:24:25 -04:00
parent 96e5b4c760
commit bfd82ae3bb

View File

@ -139,43 +139,42 @@ module Invidious::Routes::API::Manifest
# interval can be 0 https://github.com/iv-org/invidious/issues/3441 # interval can be 0 https://github.com/iv-org/invidious/issues/3441
next if interval == 0 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 storyboard_width = storyboard[:storyboard_width]
# this fix/assumption is only if we have storyboard[:storyboard_count] = 1 storyboard_height = storyboard[:storyboard_height]
if storyboard[:storyboard_count] == 1 storyboard_count = storyboard[:storyboard_count]
storyboard_height = storyboard[:count] // storyboard[:storyboard_width] tile_width_pixels = storyboard[:width]
if storyboard[:count] % storyboard[:storyboard_width] > 0 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 storyboard_height += 1
end end
end end
tiles_per_page = storyboard[:storyboard_width] * storyboard_height
interval_seconds = interval // 1000 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 # Youtube template uses the var $M for tile pages
# DASH-IF uses $Number$ in the SegmentTemplate # DASH-IF uses $Number$ in the SegmentTemplate
url = template_url.gsub("$M", "$Number$") 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 storyboard_width_pixels = tile_width_pixels * storyboard_width
duration = tile_count * interval_seconds storyboard_height_pixels = tile_height_pixels * storyboard_height
width = storyboard[:width] * storyboard[:storyboard_width]
height = storyboard[:height] * storyboard_height
# Bandwidth is kind of a guess... # 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("AdaptationSet", id: i, mimeType: mime_type, contentType: "image") do
xml.element("SegmentTemplate", media: url, duration: duration, startNumber: "0") 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}") xml.element("EssentialProperty", schemeIdUri: "http://dashif.org/guidelines/thumbnail_tile", value: "#{storyboard_width}x#{storyboard_height}")
end end
end end