diff --git a/src/invidious/helpers/extractors.cr b/src/invidious/helpers/extractors.cr index 1fa06c91d..ea9411d73 100644 --- a/src/invidious/helpers/extractors.cr +++ b/src/invidious/helpers/extractors.cr @@ -253,8 +253,8 @@ private class CategoryParser < ItemParser # Content could be in three locations. if content_container = item_contents["content"]["horizontalListRenderer"]? - elsif content_container = item_contents["content"]["expandedShelfContentsRenderer"] - elsif content_container = item_contents["content"]["verticalListRenderer"] + elsif content_container = item_contents["content"]["expandedShelfContentsRenderer"]? + elsif content_container = item_contents["content"]["verticalListRenderer"]? else content_container = item_contents["contents"] end @@ -332,10 +332,15 @@ private class SearchResultsExtractor < ItemsContainerExtractor end private def extract(target) - raw_items = [] of JSON::Any + raw_items = [] of Array(JSON::Any) content = target["primaryContents"] - renderer = content["sectionListRenderer"]["contents"].as_a[0]["itemSectionRenderer"] - raw_items = renderer["contents"].as_a + renderer = content["sectionListRenderer"]["contents"].as_a.each do |node| + if node = node["itemSectionRenderer"]? + raw_items << node["contents"].as_a + end + end + + raw_items = raw_items.flatten return raw_items end diff --git a/src/invidious/search.cr b/src/invidious/search.cr index eb9c37c56..3873b2dd9 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -232,5 +232,20 @@ def process_search_query(query, page, user, region) count, items = search(search_query, search_params, region).as(Tuple) end - {search_query, count, items, operators} + # Light processing to flatten search results out of Categories. + # They should ideally be supported in the future. + items_without_cate_items = [] of SearchItem | ChannelVideo + items.each do |i| + if i.is_a? Category + i.contents.each do |nest_i| + if !nest_i.is_a? Video + items_without_cate_items << nest_i + end + end + else + items_without_cate_items << i + end + end + + {search_query, items_without_cate_items.size, items_without_cate_items, url_params} end