diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2023-04-28 17:30:01 +0200 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2023-04-28 20:29:49 +0200 |
| commit | 3cfbc19ccc031ec4640f5e06568d2a52ebf90627 (patch) | |
| tree | 651c9e16054d139653024d3f31fb8609dd52494c /src | |
| parent | 7afa03d821365673e955468eff58009b5fb5c4c8 (diff) | |
| download | invidious-3cfbc19ccc031ec4640f5e06568d2a52ebf90627.tar.gz invidious-3cfbc19ccc031ec4640f5e06568d2a52ebf90627.tar.bz2 invidious-3cfbc19ccc031ec4640f5e06568d2a52ebf90627.zip | |
Extractors: Add utility function to extract items from categories
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/yt_backend/extractors_utils.cr | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index 0cb3c079..b247dca8 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -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) |
