diff --git a/locales/en-US.json b/locales/en-US.json index 12663915..1f4cd8d6 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -162,6 +162,7 @@ "Show less": "Show less", "Watch on YouTube": "Watch on YouTube", "Switch Invidious Instance": "Switch Invidious Instance", + "Broken?": "Broken?", "Hide annotations": "Hide annotations", "Show annotations": "Show annotations", "Genre: ": "Genre: ", diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 8c893310..cb94b44a 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -410,18 +410,18 @@ def convert_theme(theme) end end -def fetch_random_instance() - instance_list = HTTP::Client.get "https://api.invidious.io/instances.json" - instance_list = JSON.parse(instance_list.body) +def fetch_random_instance + instance_list = HTTP::Client.get "https://api.invidious.io/instances.json" + instance_list = JSON.parse(instance_list.body) - filtered_instance_list = [] of String - instance_list.as_a.each do |data| - if data[1]["type"] == "https" - if data[1]["monitor"] - 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 - end - end + filtered_instance_list = [] of String + instance_list.as_a.each do |data| + if data[1]["type"] == "https" + if data[1]["monitor"] + 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 + end end - return filtered_instance_list.sample(1)[0] + end + return filtered_instance_list.sample(1)[0] end diff --git a/src/invidious/routes/misc.cr b/src/invidious/routes/misc.cr index 857d0596..c14e0e54 100644 --- a/src/invidious/routes/misc.cr +++ b/src/invidious/routes/misc.cr @@ -37,8 +37,13 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute end def cross_instance_redirect(env) + instance_url = fetch_random_instance + if env.params.query["id"]? id = env.params.query["id"] - instance_url = fetch_random_instance 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 diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr index fefc9fbb..fdb9205c 100644 --- a/src/invidious/views/search.ecr +++ b/src/invidious/views/search.ecr @@ -2,92 +2,99 @@