mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-09 15:02:14 +05:30
Add logic to parse video chapters
This commit is contained in:
parent
eda7444ca4
commit
371dbd73fe
@ -15,7 +15,7 @@ struct Video
|
|||||||
# NOTE: don't forget to bump this number if any change is made to
|
# NOTE: don't forget to bump this number if any change is made to
|
||||||
# the `params` structure in videos/parser.cr!!!
|
# the `params` structure in videos/parser.cr!!!
|
||||||
#
|
#
|
||||||
SCHEMA_VERSION = 2
|
SCHEMA_VERSION = 3
|
||||||
|
|
||||||
property id : String
|
property id : String
|
||||||
|
|
||||||
|
@ -243,11 +243,12 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
player_overlays = player_response.dig?("playerOverlays", "playerOverlayRenderer")
|
||||||
|
|
||||||
# If nothing was found previously, fall back to end screen renderer
|
# If nothing was found previously, fall back to end screen renderer
|
||||||
if related.empty?
|
if related.empty?
|
||||||
# Container for "endScreenVideoRenderer" items
|
# Container for "endScreenVideoRenderer" items
|
||||||
player_overlays = player_response.dig?(
|
end_screen_watch_next_array = player_overlays.try &.dig?(
|
||||||
"playerOverlays", "playerOverlayRenderer",
|
|
||||||
"endScreen", "watchNextEndScreenRenderer", "results"
|
"endScreen", "watchNextEndScreenRenderer", "results"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -389,6 +390,20 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
.try &.as_s.split(" ", 2)[0]
|
.try &.as_s.split(" ", 2)[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Chapters
|
||||||
|
chapters_array = [] of JSON::Any
|
||||||
|
|
||||||
|
# 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" }
|
||||||
|
|
||||||
|
if potential_chapters_array
|
||||||
|
chapters_array = potential_chapters_array.as_a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return data
|
# Return data
|
||||||
|
|
||||||
if live_now
|
if live_now
|
||||||
@ -434,6 +449,8 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
"authorThumbnail" => JSON::Any.new(author_thumbnail.try &.as_s || ""),
|
"authorThumbnail" => JSON::Any.new(author_thumbnail.try &.as_s || ""),
|
||||||
"authorVerified" => JSON::Any.new(author_verified || false),
|
"authorVerified" => JSON::Any.new(author_verified || false),
|
||||||
"subCountText" => JSON::Any.new(subs_text || "-"),
|
"subCountText" => JSON::Any.new(subs_text || "-"),
|
||||||
|
|
||||||
|
"chapters" => JSON::Any.new(chapters_array),
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
Loading…
Reference in New Issue
Block a user