diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index 46e31a98..266f7ba4 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -191,8 +191,6 @@ module Invidious::Routes::Embed thumbnail = "/vi/#{video.id}/maxres.jpg" - chapters = video.chapters - if params.raw url = fmt_stream[0]["url"].as_s diff --git a/src/invidious/routes/images.cr b/src/invidious/routes/images.cr index b26e37d9..458a5307 100644 --- a/src/invidious/routes/images.cr +++ b/src/invidious/routes/images.cr @@ -160,14 +160,10 @@ module Invidious::Routes::Images id = env.params.url["id"] name = env.params.url["name"] - # Sometimes required to fetch image. IE for chapter thumbnails + # Some thumbnails such as the ones for chapters requires some additional queries. query_params = HTTP::Params.new - if sqp = env.params.query["sqp"]? - query_params["sqp"] = sqp - end - - if rs = env.params.query["rs"]? - query_params["rs"] = rs + {"sqp", "rs"}.each do |name| + query_params[name] = env.params.query[name] if env.params.query[name]? end headers = HTTP::Headers.new diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 144f24e0..aabe8dfc 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -158,8 +158,6 @@ module Invidious::Routes::Watch thumbnail = "/vi/#{video.id}/maxres.jpg" - chapters = video.chapters - if params.raw if params.listen url = audio_streams[0]["url"].as_s diff --git a/src/invidious/videos/chapters.cr b/src/invidious/videos/chapters.cr index 446056d9..4d18299f 100644 --- a/src/invidious/videos/chapters.cr +++ b/src/invidious/videos/chapters.cr @@ -10,8 +10,8 @@ module Invidious::Videos # Constructs a chapters object from InnerTube's JSON object for chapters # # Requires the length of the video the chapters are associated to in order to construct correct ending time - def Chapters.from_raw_chapters(raw_chapters : Array(JSON::Any), video_length_seconds : Int32, is_auto_generated : Bool = false) - video_length_milliseconds = video_length_seconds.seconds.total_milliseconds + def Chapters.from_raw_chapters(raw_chapters : Array(JSON::Any), video_length : Int32, is_auto_generated : Bool = false) + video_length_milliseconds = video_length.seconds.total_milliseconds parsed_chapters = [] of Chapter @@ -21,10 +21,8 @@ module Invidious::Videos title = chapter["title"]["simpleText"].as_s raw_thumbnails = chapter["thumbnail"]["thumbnails"].as_a - thumbnails = [] of Hash(String, Int32 | String) - - raw_thumbnails.each do |thumbnail| - thumbnails << { + thumbnails = raw_thumbnails.map do |thumbnail| + { "url" => thumbnail["url"].as_s, "width" => thumbnail["width"].as_i, "height" => thumbnail["height"].as_i, diff --git a/src/invidious/views/components/description_chapters_widget.ecr b/src/invidious/views/components/description_chapters_widget.ecr index f6251f2a..8ff5aa3c 100644 --- a/src/invidious/views/components/description_chapters_widget.ecr +++ b/src/invidious/views/components/description_chapters_widget.ecr @@ -1,4 +1,4 @@ -<% if !chapters.nil? %> +<% if chapters = video.chapters %>