Handle when there are no continuations returned due to being on the last page.

Also tidy up the return statements
This commit is contained in:
0x24d 2021-11-20 00:32:25 +00:00
parent f34f06bca5
commit 55fc6e7bbe

View file

@ -55,19 +55,20 @@ def fetch_continuation_token(items : Array(JSON::Any))
end
def fetch_continuation_token(initial_data : Hash(String, JSON::Any))
continuation = ""
# Fetches the continuation token from initial data
if initial_data["onResponseReceivedActions"]?
continuation_items = initial_data["onResponseReceivedActions"][0]["appendContinuationItemsAction"]["continuationItems"]
elsif initial_data["contents"]?
tab = extract_selected_tab(initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"])
continuation_items = tab["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]["gridRenderer"]["items"]
else
elsif initial_data["continuationContents"]["gridContinuation"]["continuations"]?
continuation = initial_data["continuationContents"]["gridContinuation"]["continuations"][0]["nextContinuationData"]["continuation"].as_s
end
if continuation_items.nil?
return continuation
else
return fetch_continuation_token(continuation_items.as_a)
if !continuation_items.nil?
continuation = fetch_continuation_token(continuation_items.as_a)
end
return continuation
end