Add logic to search nextContinuationData for token

This commit is contained in:
syeopite 2024-02-01 16:55:17 -08:00
parent 8e3966fa86
commit 74cab85fd4
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A

View File

@ -102,9 +102,21 @@ def extract_video_info(video_id : String, proxy_region : String? = nil)
# Workaround for #4415
if params["relatedVideos"].as_a.empty?
continuation = player_response.dig?("contents", "twoColumnWatchNextResults", "secondaryResults",
"secondaryResults", "results", 0, "continuationItemRenderer",
"continuationEndpoint", "continuationCommand", "token")
secondary_results = player_response.dig?("contents", "twoColumnWatchNextResults", "secondaryResults", "secondaryResults")
if secondary_results
# The continuation token can be in either continuationItemRenderer or a nextContinuationData object
continuation_renderer = secondary_results["results"].as_a.find(&.dig?("continuationItemRenderer"))
continuation = continuation_renderer.try &.["continuationItemRenderer"].dig?(
"onResponseReceivedEndpoints", 0, "appendContinuationItemsAction", "continuationItems"
)
# Try to parse the continuation token from the nextContinuationData object
if !continuation
next_continuation_data_container = secondary_results.dig?("continuations").try &.as_a.find(&.["nextContinuationData"]?)
continuation = next_continuation_data_container.try &.dig?("nextContinuationData", "continuation")
end
if continuation
raw_related_videos = YoutubeAPI.next(continuation: continuation.as_s)
@ -122,6 +134,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil)
params["relatedVideos"] = JSON::Any.new(related)
end
end
end
new_player_response = nil