From 15ba3325d9eee4e8b30828bf6d239f4999a36e0b Mon Sep 17 00:00:00 2001 From: Andrew Zhao Date: Sat, 2 Jan 2021 19:35:31 -0500 Subject: add ui for searching --- src/invidious/routes/playlists.cr | 2 +- src/invidious/routes/search.cr | 8 +++- src/invidious/search.cr | 2 +- src/invidious/views/search.ecr | 97 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr index 6c899054..c5023c08 100644 --- a/src/invidious/routes/playlists.cr +++ b/src/invidious/routes/playlists.cr @@ -267,7 +267,7 @@ class Invidious::Routes::Playlists < Invidious::Routes::BaseRoute query = env.params.query["q"]? if query begin - search_query, count, items = process_search_query(query, page, user, region: nil) + search_query, count, items, operators = process_search_query(query, page, user, region: nil) videos = items.select { |item| item.is_a? SearchVideo }.map { |item| item.as(SearchVideo) } rescue ex videos = [] of SearchVideo diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr index 48446161..a993a17a 100644 --- a/src/invidious/routes/search.cr +++ b/src/invidious/routes/search.cr @@ -48,11 +48,17 @@ class Invidious::Routes::Search < Invidious::Routes::BaseRoute user = env.get? "user" begin - search_query, count, videos = process_search_query(query, page, user, region: nil) + search_query, count, videos, operators = process_search_query(query, page, user, region: nil) rescue ex return error_template(500, ex) end + operator_hash = {} of String => String + operators.each do |operator| + key, value = operator.downcase.split(":") + operator_hash[key] = value + end + env.set "search", query templated "search" end diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 85fd024a..1c4bc74e 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -445,5 +445,5 @@ def process_search_query(query, page, user, region) count, items = search(search_query, page, search_params, region).as(Tuple) end - {search_query, count, items} + {search_query, count, items, operators} end diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index bc13b7ea..3fa9242b 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -2,6 +2,102 @@ <%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious <% end %> +

+ [ + ] + <%= translate(locale, "filter") %> +

+ + +
+
+ <%= translate(locale, "date") %> +
+ <% ["hour", "today", "week", "month", "year"].each do |date| %> +
+ <% if operator_hash.fetch("date", "all") == date %> + <%= translate(locale, date) %> + <% else %> + &page=<%= page %>"> + <%= translate(locale, date) %> + + <% end %> +
+ <% end %> +
+
+ <%= translate(locale, "content_type") %> +
+ <% ["video", "channel", "playlist", "movie", "show"].each do |content_type| %> +
+ <% if operator_hash.fetch("content_type", "all") == content_type %> + <%= translate(locale, content_type) %> + <% else %> + &page=<%= page %>"> + <%= translate(locale, content_type) %> + + <% end %> +
+ <% end %> +
+
+ <%= translate(locale, "duration") %> +
+ <% ["short", "long"].each do |duration| %> +
+ <% if operator_hash.fetch("duration", "all") == duration %> + <%= translate(locale, duration) %> + <% else %> + &page=<%= page %>"> + <%= translate(locale, duration) %> + + <% end %> +
+ <% end %> +
+
+ <%= translate(locale, "features") %> +
+ <% ["hd", "subtitles", "creative_commons", "3d", "live", "purchased", "4k", "360", "location", "hdr"].each do |feature| %> +
+ <% if operator_hash.fetch("features", "all").includes?(feature) %> + <%= translate(locale, feature) %> + <% elsif operator_hash.has_key?("features") %> + &page=<%= page %>"> + <%= translate(locale, feature) %> + + <% else %> + &page=<%= page %>"> + <%= translate(locale, feature) %> + + <% end %> +
+ <% end %> +
+
+ <%= translate(locale, "sort") %> +
+ <% ["relevance", "rating", "date", "views"].each do |sort| %> +
+ <% if operator_hash.fetch("sort", "relevance") == sort %> + <%= translate(locale, sort) %> + <% else %> + &page=<%= page %>"> + <%= translate(locale, sort) %> + + <% end %> +
+ <% end %> +
+
+ +
+
<% if page > 1 %> @@ -45,3 +141,4 @@ <% end %>
+ \ No newline at end of file -- cgit v1.2.3