diff --git a/assets/css/default.css b/assets/css/default.css index e403e606..793295d9 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -628,3 +628,6 @@ body.dark-theme { } } +#filters { + display: none; +} \ No newline at end of file diff --git a/assets/js/search.js b/assets/js/search.js new file mode 100644 index 00000000..36edd053 --- /dev/null +++ b/assets/js/search.js @@ -0,0 +1,13 @@ +function toggle_comments(event) { + var target = event.target; + var body = document.getElementById('filters'); + if (body.style.display === 'flex') { + target.innerHTML = '[ + ]'; + body.style.display = 'none'; + } else { + target.innerHTML = '[ - ]'; + body.style.display = 'flex'; + } +} + +document.getElementById('togglefilters').onclick = toggle_comments; \ No newline at end of file diff --git a/locales/en-US.json b/locales/en-US.json index acd2b667..66e71bb6 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -383,5 +383,32 @@ "Videos": "Videos", "Playlists": "Playlists", "Community": "Community", + "relevance": "Relevance", + "rating": "Rating", + "date": "Upload date", + "views": "View count", + "content_type": "Type", + "duration": "Duration", + "features": "Features", + "sort": "Sort By", + "hour": "Last Hour", + "today": "Today", + "week": "This week", + "month": "This month", + "year": "This year", + "video": "Video", + "channel": "Channel", + "playlist": "Playlist", + "movie": "Movie", + "show": "Show", + "hd": "HD", + "subtitles": "Subtitles/CC", + "creative_commons": "Creative Commons", + "3d": "3D", + "live": "Live", + "4k": "4K", + "location": "Location", + "hdr": "HDR", + "filter": "Filter", "Current version: ": "Current version: " } \ No newline at end of file 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