From 2851d993ad0079433ee9028c4f2e7854096ed9f0 Mon Sep 17 00:00:00 2001 From: 11tuvork28 Date: Sun, 3 Jul 2022 14:03:30 +0200 Subject: [PATCH 1/4] updated comment to represent current structure --- src/invidious/yt_backend/extractors.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index c4326cab5..b9609eb9c 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -417,7 +417,7 @@ private module Extractors # {"tabRenderer": { # "endpoint": {...} # "title": "Playlists", - # "selected": true, + # "selected": true, # Is nil unless tab is selected # "content": {...}, # ... # }} From 15d2cfba90428f8c1bb3e7ce88599078dc0ae6f0 Mon Sep 17 00:00:00 2001 From: 11tuvork28 Date: Sun, 3 Jul 2022 14:03:42 +0200 Subject: [PATCH 2/4] Fix `Missing hash key: "selected" (KeyError)` --- src/invidious/yt_backend/extractors_utils.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index 3d5e57876..f82451607 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -84,7 +84,7 @@ end def extract_selected_tab(tabs) # Extract the selected tab from the array of tabs Youtube returns - return selected_target = tabs.as_a.select(&.["tabRenderer"]?.try &.["selected"].as_bool)[0]["tabRenderer"] + return selected_target = tabs.as_a.select(&.["tabRenderer"]?.try &.["selected"]?.try &.as_bool)[0]["tabRenderer"] end def fetch_continuation_token(items : Array(JSON::Any)) From a8b72d834231a6b353d7dda31e93b2e4907800fd Mon Sep 17 00:00:00 2001 From: 11tuvork28 Date: Sun, 3 Jul 2022 14:23:34 +0200 Subject: [PATCH 3/4] Fixed community tab --- src/invidious/channels/community.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr index 4701ecbd6..4c32ea20b 100644 --- a/src/invidious/channels/community.cr +++ b/src/invidious/channels/community.cr @@ -13,7 +13,7 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode) if !continuation || continuation.empty? initial_data = extract_initial_data(response.body) - body = initial_data["contents"]?.try &.["twoColumnBrowseResultsRenderer"]["tabs"].as_a.select { |tab| tab["tabRenderer"]?.try &.["selected"].as_bool.== true }[0]? + body = initial_data["contents"]?.try &.["twoColumnBrowseResultsRenderer"]["tabs"].as_a.select { |tab| tab["tabRenderer"]?.try &.["selected"]?.try &.as_bool == true }[0]? if !body raise InfoException.new("Could not extract community tab.") From 864f27ef72b084461e327640f80aa45a8f250b0f Mon Sep 17 00:00:00 2001 From: 11tuvork28 Date: Sun, 3 Jul 2022 14:59:33 +0200 Subject: [PATCH 4/4] switched to extract_selected_tab for the community tab --- src/invidious/channels/community.cr | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr index 4c32ea20b..aaed9567c 100644 --- a/src/invidious/channels/community.cr +++ b/src/invidious/channels/community.cr @@ -13,13 +13,11 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode) if !continuation || continuation.empty? initial_data = extract_initial_data(response.body) - body = initial_data["contents"]?.try &.["twoColumnBrowseResultsRenderer"]["tabs"].as_a.select { |tab| tab["tabRenderer"]?.try &.["selected"]?.try &.as_bool == true }[0]? + body = extract_selected_tab(initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"])["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"] if !body raise InfoException.new("Could not extract community tab.") end - - body = body["tabRenderer"]["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"] else continuation = produce_channel_community_continuation(ucid, continuation)