From 55fc6e7bbe6c1ea58ea8aea3faeebbf31fea0fa9 Mon Sep 17 00:00:00 2001 From: 0x24d Date: Sat, 20 Nov 2021 00:32:25 +0000 Subject: [PATCH] Handle when there are no continuations returned due to being on the last page. Also tidy up the return statements --- src/invidious/yt_backend/extractors_utils.cr | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index 400bc62e..be992ecd 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -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