mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-10 10:18:24 +00:00
Unpack search items that are embedded in categories
This is a squash of a bunch of commits cherry-picked commits Fix category parse error on search (cherry picked from commitcc02fed4e6
) Fix category items not being extracted in search (cherry picked from commit2605b9c609
) Make search not include category items for now (cherry picked from commitca4afd59f4
) Change behavior of categories in search results (cherry picked from commitcc10675610
) Fix missing search results in extraction (cherry picked from commitabda6840d5
) Fix miscount of search results (cherry picked from commit491e33450e
)
This commit is contained in:
parent
a50f64f6e9
commit
ae30f32c36
@ -253,8 +253,8 @@ private class CategoryParser < ItemParser
|
|||||||
|
|
||||||
# Content could be in three locations.
|
# Content could be in three locations.
|
||||||
if content_container = item_contents["content"]["horizontalListRenderer"]?
|
if content_container = item_contents["content"]["horizontalListRenderer"]?
|
||||||
elsif content_container = item_contents["content"]["expandedShelfContentsRenderer"]
|
elsif content_container = item_contents["content"]["expandedShelfContentsRenderer"]?
|
||||||
elsif content_container = item_contents["content"]["verticalListRenderer"]
|
elsif content_container = item_contents["content"]["verticalListRenderer"]?
|
||||||
else
|
else
|
||||||
content_container = item_contents["contents"]
|
content_container = item_contents["contents"]
|
||||||
end
|
end
|
||||||
@ -332,10 +332,15 @@ private class SearchResultsExtractor < ItemsContainerExtractor
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def extract(target)
|
private def extract(target)
|
||||||
raw_items = [] of JSON::Any
|
raw_items = [] of Array(JSON::Any)
|
||||||
content = target["primaryContents"]
|
content = target["primaryContents"]
|
||||||
renderer = content["sectionListRenderer"]["contents"].as_a[0]["itemSectionRenderer"]
|
renderer = content["sectionListRenderer"]["contents"].as_a.each do |node|
|
||||||
raw_items = renderer["contents"].as_a
|
if node = node["itemSectionRenderer"]?
|
||||||
|
raw_items << node["contents"].as_a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
raw_items = raw_items.flatten
|
||||||
|
|
||||||
return raw_items
|
return raw_items
|
||||||
end
|
end
|
||||||
|
@ -232,5 +232,20 @@ def process_search_query(query, page, user, region)
|
|||||||
count, items = search(search_query, search_params, region).as(Tuple)
|
count, items = search(search_query, search_params, region).as(Tuple)
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user