diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2021-10-11 18:58:12 +0200 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2021-10-18 16:12:18 +0200 |
| commit | e17c8b1f4deaa56dcdd5d3b9f62bec13f9b71dc7 (patch) | |
| tree | 63af35b4fae42f5ee5cd5eb31879a42540241d3c | |
| parent | 8805ee7c8c5d1023c032b52cc79b1c1048b60afd (diff) | |
| download | invidious-e17c8b1f4deaa56dcdd5d3b9f62bec13f9b71dc7.tar.gz invidious-e17c8b1f4deaa56dcdd5d3b9f62bec13f9b71dc7.tar.bz2 invidious-e17c8b1f4deaa56dcdd5d3b9f62bec13f9b71dc7.zip | |
Move 'extract_videos' and 'extract_selected_tab' too
| -rw-r--r-- | src/invidious/helpers/helpers.cr | 19 | ||||
| -rw-r--r-- | src/invidious/yt_backend/extractors_utils.cr | 19 |
2 files changed, 19 insertions, 19 deletions
diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index baf82740..c01ca11e 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -251,25 +251,6 @@ def html_to_content(description_html : String) return description end -def extract_videos(initial_data : Hash(String, JSON::Any), author_fallback : String? = nil, author_id_fallback : String? = nil) - extracted = extract_items(initial_data, author_fallback, author_id_fallback) - - target = [] of SearchItem - 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 - end - return target.select(&.is_a?(SearchVideo)).map(&.as(SearchVideo)) -end - -def extract_selected_tab(tabs) - # Extract the selected tab from the array of tabs Youtube returns - return selected_target = tabs.as_a.select(&.["tabRenderer"]?.try &.["selected"].as_bool)[0]["tabRenderer"] -end - def check_enum(db, enum_name, struct_type = nil) return # TODO diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index e0a13031..b76fa09a 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -1,3 +1,22 @@ +def extract_videos(initial_data : Hash(String, JSON::Any), author_fallback : String? = nil, author_id_fallback : String? = nil) + extracted = extract_items(initial_data, author_fallback, author_id_fallback) + + target = [] of SearchItem + 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 + end + return target.select(&.is_a?(SearchVideo)).map(&.as(SearchVideo)) +end + +def extract_selected_tab(tabs) + # Extract the selected tab from the array of tabs Youtube returns + return selected_target = tabs.as_a.select(&.["tabRenderer"]?.try &.["selected"].as_bool)[0]["tabRenderer"] +end + def fetch_continuation_token(items : Array(JSON::Any)) # Fetches the continuation token from an array of items return items.last["continuationItemRenderer"]? |
