mirror of
https://github.com/iv-org/invidious.git
synced 2025-07-27 07:48:29 +00:00
Add logic to search nextContinuationData for token
This commit is contained in:
parent
8e3966fa86
commit
74cab85fd4
@ -102,24 +102,37 @@ def extract_video_info(video_id : String, proxy_region : String? = nil)
|
|||||||
|
|
||||||
# Workaround for #4415
|
# Workaround for #4415
|
||||||
if params["relatedVideos"].as_a.empty?
|
if params["relatedVideos"].as_a.empty?
|
||||||
continuation = player_response.dig?("contents", "twoColumnWatchNextResults", "secondaryResults",
|
secondary_results = player_response.dig?("contents", "twoColumnWatchNextResults", "secondaryResults", "secondaryResults")
|
||||||
"secondaryResults", "results", 0, "continuationItemRenderer",
|
|
||||||
"continuationEndpoint", "continuationCommand", "token")
|
|
||||||
|
|
||||||
if continuation
|
if secondary_results
|
||||||
raw_related_videos = YoutubeAPI.next(continuation: continuation.as_s)
|
# The continuation token can be in either continuationItemRenderer or a nextContinuationData object
|
||||||
raw_related_videos = raw_related_videos.dig?("onResponseReceivedEndpoints", 0, "appendContinuationItemsAction", "continuationItems")
|
continuation_renderer = secondary_results["results"].as_a.find(&.dig?("continuationItemRenderer"))
|
||||||
|
|
||||||
related = [] of JSON::Any
|
continuation = continuation_renderer.try &.["continuationItemRenderer"].dig?(
|
||||||
|
"onResponseReceivedEndpoints", 0, "appendContinuationItemsAction", "continuationItems"
|
||||||
|
)
|
||||||
|
|
||||||
raw_related_videos.try &.as_a.each do |element|
|
# Try to parse the continuation token from the nextContinuationData object
|
||||||
if item = element["compactVideoRenderer"]?
|
if !continuation
|
||||||
related_video = parse_related_video(item)
|
next_continuation_data_container = secondary_results.dig?("continuations").try &.as_a.find(&.["nextContinuationData"]?)
|
||||||
related << JSON::Any.new(related_video) if related_video
|
continuation = next_continuation_data_container.try &.dig?("nextContinuationData", "continuation")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
params["relatedVideos"] = JSON::Any.new(related)
|
if continuation
|
||||||
|
raw_related_videos = YoutubeAPI.next(continuation: continuation.as_s)
|
||||||
|
raw_related_videos = raw_related_videos.dig?("onResponseReceivedEndpoints", 0, "appendContinuationItemsAction", "continuationItems")
|
||||||
|
|
||||||
|
related = [] of JSON::Any
|
||||||
|
|
||||||
|
raw_related_videos.try &.as_a.each do |element|
|
||||||
|
if item = element["compactVideoRenderer"]?
|
||||||
|
related_video = parse_related_video(item)
|
||||||
|
related << JSON::Any.new(related_video) if related_video
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
params["relatedVideos"] = JSON::Any.new(related)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user