mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-25 15:07:22 +00:00
Add instance redirect on empty/broken search
This commit is contained in:
parent
37ff2ac2b9
commit
311e7684b2
@ -162,6 +162,7 @@
|
|||||||
"Show less": "Show less",
|
"Show less": "Show less",
|
||||||
"Watch on YouTube": "Watch on YouTube",
|
"Watch on YouTube": "Watch on YouTube",
|
||||||
"Switch Invidious Instance": "Switch Invidious Instance",
|
"Switch Invidious Instance": "Switch Invidious Instance",
|
||||||
|
"Broken?": "Broken?",
|
||||||
"Hide annotations": "Hide annotations",
|
"Hide annotations": "Hide annotations",
|
||||||
"Show annotations": "Show annotations",
|
"Show annotations": "Show annotations",
|
||||||
"Genre: ": "Genre: ",
|
"Genre: ": "Genre: ",
|
||||||
|
@ -410,18 +410,18 @@ def convert_theme(theme)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_random_instance()
|
def fetch_random_instance
|
||||||
instance_list = HTTP::Client.get "https://api.invidious.io/instances.json"
|
instance_list = HTTP::Client.get "https://api.invidious.io/instances.json"
|
||||||
instance_list = JSON.parse(instance_list.body)
|
instance_list = JSON.parse(instance_list.body)
|
||||||
|
|
||||||
filtered_instance_list = [] of String
|
filtered_instance_list = [] of String
|
||||||
instance_list.as_a.each do |data|
|
instance_list.as_a.each do |data|
|
||||||
if data[1]["type"] == "https"
|
if data[1]["type"] == "https"
|
||||||
if data[1]["monitor"]
|
if data[1]["monitor"]
|
||||||
health = data[1]["monitor"].as_h["dailyRatios"][0].as_h["ratio"]
|
health = data[1]["monitor"].as_h["dailyRatios"][0].as_h["ratio"]
|
||||||
filtered_instance_list << data[0].as_s if health.to_s.to_f > 90
|
filtered_instance_list << data[0].as_s if health.to_s.to_f > 90
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return filtered_instance_list.sample(1)[0]
|
end
|
||||||
|
return filtered_instance_list.sample(1)[0]
|
||||||
end
|
end
|
||||||
|
@ -37,8 +37,13 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cross_instance_redirect(env)
|
def cross_instance_redirect(env)
|
||||||
|
instance_url = fetch_random_instance
|
||||||
|
if env.params.query["id"]?
|
||||||
id = env.params.query["id"]
|
id = env.params.query["id"]
|
||||||
instance_url = fetch_random_instance
|
|
||||||
env.redirect "https://#{instance_url}/watch?v=#{id}"
|
env.redirect "https://#{instance_url}/watch?v=#{id}"
|
||||||
|
elsif env.params.query["q"]?
|
||||||
|
query, page = env.params.query["q"], env.params.query["page"]
|
||||||
|
env.redirect "https://#{instance_url}/search?q=#{query}&page=#{page}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,92 +2,99 @@
|
|||||||
<title><%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious</title>
|
<title><%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious</title>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<details id="filters">
|
<!-- Search redirection and filtering UI -->
|
||||||
<summary>
|
<% if count == 0 %>
|
||||||
<h3 style="display:inline"> <%= translate(locale, "filter") %> </h3>
|
<h3 style="text-align: center">
|
||||||
</summary>
|
<%= translate(locale, "Broken?") %> <a href="/redirect?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page + 1 %>"><%= translate(locale, "Switch Invidious Instance") %></a>
|
||||||
<div id="filters" class="pure-g h-box">
|
</h3>
|
||||||
<div class="pure-u-1-3 pure-u-md-1-5">
|
<% else %>
|
||||||
<b><%= translate(locale, "date") %></b>
|
<details id="filters">
|
||||||
<hr/>
|
<summary>
|
||||||
<% ["hour", "today", "week", "month", "year"].each do |date| %>
|
<h3 style="display:inline"> <%= translate(locale, "filter") %> </h3>
|
||||||
<div class="pure-u-1 pure-md-1-5">
|
</summary>
|
||||||
<% if operator_hash.fetch("date", "all") == date %>
|
<div id="filters" class="pure-g h-box">
|
||||||
<b><%= translate(locale, date) %></b>
|
<div class="pure-u-1-3 pure-u-md-1-5">
|
||||||
<% else %>
|
<b><%= translate(locale, "date") %></b>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?date:[a-z]+/, "") + " date:" + date) %>&page=<%= page %>">
|
<hr/>
|
||||||
<%= translate(locale, date) %>
|
<% ["hour", "today", "week", "month", "year"].each do |date| %>
|
||||||
</a>
|
<div class="pure-u-1 pure-md-1-5">
|
||||||
<% end %>
|
<% if operator_hash.fetch("date", "all") == date %>
|
||||||
</div>
|
<b><%= translate(locale, date) %></b>
|
||||||
<% end %>
|
<% else %>
|
||||||
|
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?date:[a-z]+/, "") + " date:" + date) %>&page=<%= page %>">
|
||||||
|
<%= translate(locale, date) %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="pure-u-1-3 pure-u-md-1-5">
|
||||||
|
<b><%= translate(locale, "content_type") %></b>
|
||||||
|
<hr/>
|
||||||
|
<% ["video", "channel", "playlist", "movie", "show"].each do |content_type| %>
|
||||||
|
<div class="pure-u-1 pure-md-1-5">
|
||||||
|
<% if operator_hash.fetch("content_type", "all") == content_type %>
|
||||||
|
<b><%= translate(locale, content_type) %></b>
|
||||||
|
<% else %>
|
||||||
|
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?content_type:[a-z]+/, "") + " content_type:" + content_type) %>&page=<%= page %>">
|
||||||
|
<%= translate(locale, content_type) %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="pure-u-1-3 pure-u-md-1-5">
|
||||||
|
<b><%= translate(locale, "duration") %></b>
|
||||||
|
<hr/>
|
||||||
|
<% ["short", "long"].each do |duration| %>
|
||||||
|
<div class="pure-u-1 pure-md-1-5">
|
||||||
|
<% if operator_hash.fetch("duration", "all") == duration %>
|
||||||
|
<b><%= translate(locale, duration) %></b>
|
||||||
|
<% else %>
|
||||||
|
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?duration:[a-z]+/, "") + " duration:" + duration) %>&page=<%= page %>">
|
||||||
|
<%= translate(locale, duration) %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="pure-u-1-3 pure-u-md-1-5">
|
||||||
|
<b><%= translate(locale, "features") %></b>
|
||||||
|
<hr/>
|
||||||
|
<% ["hd", "subtitles", "creative_commons", "3d", "live", "purchased", "4k", "360", "location", "hdr"].each do |feature| %>
|
||||||
|
<div class="pure-u-1 pure-md-1-5">
|
||||||
|
<% if operator_hash.fetch("features", "all").includes?(feature) %>
|
||||||
|
<b><%= translate(locale, feature) %></b>
|
||||||
|
<% elsif operator_hash.has_key?("features") %>
|
||||||
|
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/features:/, "features:" + feature + ",")) %>&page=<%= page %>">
|
||||||
|
<%= translate(locale, feature) %>
|
||||||
|
</a>
|
||||||
|
<% else %>
|
||||||
|
<a href="/search?q=<%= HTML.escape(query.not_nil! + " features:" + feature) %>&page=<%= page %>">
|
||||||
|
<%= translate(locale, feature) %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="pure-u-1-3 pure-u-md-1-5">
|
||||||
|
<b><%= translate(locale, "sort") %></b>
|
||||||
|
<hr/>
|
||||||
|
<% ["relevance", "rating", "date", "views"].each do |sort| %>
|
||||||
|
<div class="pure-u-1 pure-md-1-5">
|
||||||
|
<% if operator_hash.fetch("sort", "relevance") == sort %>
|
||||||
|
<b><%= translate(locale, sort) %></b>
|
||||||
|
<% else %>
|
||||||
|
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?sort:[a-z]+/, "") + " sort:" + sort) %>&page=<%= page %>">
|
||||||
|
<%= translate(locale, sort) %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1-3 pure-u-md-1-5">
|
</details>
|
||||||
<b><%= translate(locale, "content_type") %></b>
|
<% end %>
|
||||||
<hr/>
|
|
||||||
<% ["video", "channel", "playlist", "movie", "show"].each do |content_type| %>
|
|
||||||
<div class="pure-u-1 pure-md-1-5">
|
|
||||||
<% if operator_hash.fetch("content_type", "all") == content_type %>
|
|
||||||
<b><%= translate(locale, content_type) %></b>
|
|
||||||
<% else %>
|
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?content_type:[a-z]+/, "") + " content_type:" + content_type) %>&page=<%= page %>">
|
|
||||||
<%= translate(locale, content_type) %>
|
|
||||||
</a>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<div class="pure-u-1-3 pure-u-md-1-5">
|
|
||||||
<b><%= translate(locale, "duration") %></b>
|
|
||||||
<hr/>
|
|
||||||
<% ["short", "long"].each do |duration| %>
|
|
||||||
<div class="pure-u-1 pure-md-1-5">
|
|
||||||
<% if operator_hash.fetch("duration", "all") == duration %>
|
|
||||||
<b><%= translate(locale, duration) %></b>
|
|
||||||
<% else %>
|
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?duration:[a-z]+/, "") + " duration:" + duration) %>&page=<%= page %>">
|
|
||||||
<%= translate(locale, duration) %>
|
|
||||||
</a>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<div class="pure-u-1-3 pure-u-md-1-5">
|
|
||||||
<b><%= translate(locale, "features") %></b>
|
|
||||||
<hr/>
|
|
||||||
<% ["hd", "subtitles", "creative_commons", "3d", "live", "purchased", "4k", "360", "location", "hdr"].each do |feature| %>
|
|
||||||
<div class="pure-u-1 pure-md-1-5">
|
|
||||||
<% if operator_hash.fetch("features", "all").includes?(feature) %>
|
|
||||||
<b><%= translate(locale, feature) %></b>
|
|
||||||
<% elsif operator_hash.has_key?("features") %>
|
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/features:/, "features:" + feature + ",")) %>&page=<%= page %>">
|
|
||||||
<%= translate(locale, feature) %>
|
|
||||||
</a>
|
|
||||||
<% else %>
|
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil! + " features:" + feature) %>&page=<%= page %>">
|
|
||||||
<%= translate(locale, feature) %>
|
|
||||||
</a>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<div class="pure-u-1-3 pure-u-md-1-5">
|
|
||||||
<b><%= translate(locale, "sort") %></b>
|
|
||||||
<hr/>
|
|
||||||
<% ["relevance", "rating", "date", "views"].each do |sort| %>
|
|
||||||
<div class="pure-u-1 pure-md-1-5">
|
|
||||||
<% if operator_hash.fetch("sort", "relevance") == sort %>
|
|
||||||
<b><%= translate(locale, sort) %></b>
|
|
||||||
<% else %>
|
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?sort:[a-z]+/, "") + " sort:" + sort) %>&page=<%= page %>">
|
|
||||||
<%= translate(locale, sort) %>
|
|
||||||
</a>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user