diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-08-27 15:23:25 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-08-27 15:23:25 -0500 |
| commit | 2ba0063dc0833efe25a25dea7b3f8d95b599f0d6 (patch) | |
| tree | 454826402c8093b61e93b774cb2733c832266309 /src/invidious.cr | |
| parent | b57176d7ef5fe5230bfedf3428e54df70ef4ff56 (diff) | |
| download | invidious-2ba0063dc0833efe25a25dea7b3f8d95b599f0d6.tar.gz invidious-2ba0063dc0833efe25a25dea7b3f8d95b599f0d6.tar.bz2 invidious-2ba0063dc0833efe25a25dea7b3f8d95b599f0d6.zip | |
Add search filters
Diffstat (limited to 'src/invidious.cr')
| -rw-r--r-- | src/invidious.cr | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index bcbdcc6d..65846303 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -429,7 +429,31 @@ get "/search" do |env| page = env.params.query["page"]?.try &.to_i? page ||= 1 - search_params = build_search_params(sort_by: "relevance", content_type: "video") + sort = "relevance" + date = "" + duration = "" + features = [] of String + + operators = query.split(" ").select { |a| a.match(/\w+:[\w,]+/) } + operators.each do |operator| + key, value = operator.split(":") + + case key + when "sort" + sort = value + when "date" + date = value + when "duration" + duration = value + when "features" + features = value.split(",") + end + end + + query = (query.split(" ") - operators).join(" ") + + search_params = build_search_params(sort: sort, date: date, content_type: "video", + duration: duration, features: features) count, videos = search(query, page, search_params).as(Tuple) templated "search" |
