Extractors: Add utility function to extract items from categories

このコミットが含まれているのは:
Samantaz Fox 2023-04-28 17:30:01 +02:00
コミット 3cfbc19ccc
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: F42821059186176E
1個のファイルの変更7行の追加10行の削除

ファイルの表示

@ -68,19 +68,16 @@ rescue ex
return false
end
def extract_videos(initial_data : Hash(String, JSON::Any), author_fallback : String? = nil, author_id_fallback : String? = nil) : Array(SearchVideo)
extracted, _ = extract_items(initial_data, author_fallback, author_id_fallback)
# This function extracts the SearchItems from a Category.
# Categories are commonly returned in search results and trending pages.
def extract_category(category : Category) : Array(SearchVideo)
items = [] of SearchItem
target = [] of (SearchItem | Continuation)
extracted.each do |i|
if i.is_a?(Category)
i.contents.each { |cate_i| target << cate_i if !cate_i.is_a? Video }
else
target << i
end
category.contents.each do |item|
target << cate_i if item.is_a?(SearchItem)
end
return target.select(SearchVideo)
return items
end
def extract_selected_tab(tabs)