From 246955b68a16aefc4e682e8f704f551f4a72b1bf Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Sat, 6 Aug 2022 18:41:59 +0200 Subject: [PATCH] if case for sectionListRenderer --- src/invidious/yt_backend/extractors.cr | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index b9609eb9..dc65cc52 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -435,20 +435,22 @@ private module Extractors raw_items = [] of JSON::Any content = extract_selected_tab(target["tabs"])["content"] - content["sectionListRenderer"]["contents"].as_a.each do |renderer_container| - renderer_container_contents = renderer_container["itemSectionRenderer"]["contents"][0] - - # Category extraction - if items_container = renderer_container_contents["shelfRenderer"]? - raw_items << renderer_container_contents - next - elsif items_container = renderer_container_contents["gridRenderer"]? - else - items_container = renderer_container_contents - end + if section_list_contents = content.dig?("sectionListRenderer", "contents") + section_list_contents.as_a.each do |renderer_container| + renderer_container_contents = renderer_container["itemSectionRenderer"]["contents"][0] + + # Category extraction + if items_container = renderer_container_contents["shelfRenderer"]? + raw_items << renderer_container_contents + next + elsif items_container = renderer_container_contents["gridRenderer"]? + else + items_container = renderer_container_contents + end - items_container["items"]?.try &.as_a.each do |item| - raw_items << item + items_container["items"]?.try &.as_a.each do |item| + raw_items << item + end end end