diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 099beae7..ffc4968f 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -234,6 +234,10 @@ struct Video return @chapters end + def automatically_generated_chapters? : Bool? + return @info["AutoGeneratedChapters"]?.try &.as_bool + end + def hls_manifest_url : String? info.dig?("streamingData", "hlsManifestUrl").try &.as_s end diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr index ae1a0d1d..34085389 100644 --- a/src/invidious/videos/parser.cr +++ b/src/invidious/videos/parser.cr @@ -376,13 +376,25 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any # Chapters chapters_array = [] of JSON::Any + chapters_auto_generated = nil - # Yes, `decoratedPlayerBarRenderer` is repeated twice. + # Yes,`decoratedPlayerBarRenderer` is repeated twice. if player_bar = player_overlays.try &.dig?("decoratedPlayerBarRenderer", "decoratedPlayerBarRenderer", "playerBar") if markers = player_bar.dig?("multiMarkersPlayerBarRenderer", "markersMap") potential_chapters_array = markers.as_a.find { |m| m["key"]? == "DESCRIPTION_CHAPTERS" } + # Let manual chapters have higher precedence than automatically generated ones. + if !potential_chapters_array + potential_chapters_array = markers.as_a.find { |m| m["key"]? == "AUTO_CHAPTERS" } + end + if potential_chapters_array + if potential_chapters_array["key"] == "AUTO_CHAPTERS" + chapters_auto_generated = true + else + chapters_auto_generated = false + end + chapters_array = potential_chapters_array["value"]["chapters"].as_a end end @@ -433,7 +445,8 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any "authorVerified" => JSON::Any.new(author_verified || false), "subCountText" => JSON::Any.new(subs_text || "-"), - "chapters" => JSON::Any.new(chapters_array), + "AutoGeneratedChapters" => JSON::Any.new(chapters_auto_generated), + "chapters" => JSON::Any.new(chapters_array), } return params diff --git a/src/invidious/views/components/description_chapters_widget.ecr b/src/invidious/views/components/description_chapters_widget.ecr index e02f29cf..852798d1 100644 --- a/src/invidious/views/components/description_chapters_widget.ecr +++ b/src/invidious/views/components/description_chapters_widget.ecr @@ -2,6 +2,11 @@