mirror of
https://github.com/iv-org/invidious.git
synced 2024-09-08 04:45:36 +05:30
Misc: Add an utility function to for 'region' URL parameter
This commit is contained in:
parent
8caa317c63
commit
3a4ca20309
@ -6,7 +6,7 @@ module Invidious::Routes::API::Manifest
|
||||
|
||||
local = env.params.query["local"]?.try &.== "true"
|
||||
id = env.params.url["id"]
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
|
||||
# Since some implementations create playlists based on resolution regardless of different codecs,
|
||||
# we can opt to only add a source to a representation if it has a unique height within that representation
|
||||
|
@ -431,7 +431,7 @@ module Invidious::Routes::API::V1::Channels
|
||||
|
||||
def self.search(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
|
@ -4,7 +4,7 @@ module Invidious::Routes::API::V1::Feeds
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
trending_type = env.params.query["type"]?
|
||||
|
||||
begin
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Invidious::Routes::API::V1::Search
|
||||
def self.search(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
@ -24,7 +24,7 @@ module Invidious::Routes::API::V1::Search
|
||||
|
||||
def self.search_suggestions(env)
|
||||
preferences = env.get("preferences").as(Preferences)
|
||||
region = env.params.query["region"]? || preferences.region
|
||||
region = find_region(env.params.query["region"]?) || preferences.region
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
@ -65,7 +65,7 @@ module Invidious::Routes::API::V1::Search
|
||||
page = env.params.query["page"]?.try &.to_i? || 1
|
||||
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
begin
|
||||
|
@ -5,7 +5,7 @@ module Invidious::Routes::API::V1::Videos
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
id = env.params.url["id"]
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
proxy = {"1", "true"}.any? &.== env.params.query["local"]?
|
||||
|
||||
begin
|
||||
@ -25,7 +25,7 @@ module Invidious::Routes::API::V1::Videos
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
id = env.params.url["id"]
|
||||
region = env.params.query["region"]? || env.params.body["region"]?
|
||||
region = find_region(env.params.query["region"]? || env.params.body["region"]?)
|
||||
|
||||
if id.nil? || id.size != 11 || !id.matches?(/^[\w-]+$/)
|
||||
return error_json(400, "Invalid video ID")
|
||||
@ -177,7 +177,7 @@ module Invidious::Routes::API::V1::Videos
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
id = env.params.url["id"]
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
|
||||
begin
|
||||
video = get_video(id, region: region)
|
||||
@ -306,7 +306,7 @@ module Invidious::Routes::API::V1::Videos
|
||||
|
||||
def self.comments(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
|
@ -48,7 +48,7 @@ module Invidious::Routes::Feeds
|
||||
trending_type = env.params.query["type"]?
|
||||
trending_type ||= "Default"
|
||||
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
region ||= env.get("preferences").as(Preferences).region
|
||||
|
||||
begin
|
||||
|
@ -228,7 +228,7 @@ module Invidious::Routes::Playlists
|
||||
prefs = env.get("preferences").as(Preferences)
|
||||
locale = prefs.locale
|
||||
|
||||
region = env.params.query["region"]? || prefs.region
|
||||
region = find_region(env.params.query["region"]?) || prefs.region
|
||||
|
||||
user = env.get? "user"
|
||||
sid = env.get? "sid"
|
||||
|
@ -110,7 +110,7 @@ module Invidious::Routes::PreferencesRoute
|
||||
automatic_instance_redirect ||= "off"
|
||||
automatic_instance_redirect = automatic_instance_redirect == "on"
|
||||
|
||||
region = env.params.body["region"]?.try &.as(String)
|
||||
region = find_region(env.params.body["region"]?)
|
||||
|
||||
locale = env.params.body["locale"]?.try &.as(String)
|
||||
locale ||= CONFIG.default_user_preferences.locale
|
||||
|
@ -40,7 +40,7 @@ module Invidious::Routes::Search
|
||||
prefs = env.get("preferences").as(Preferences)
|
||||
locale = prefs.locale
|
||||
|
||||
region = env.params.query["region"]? || prefs.region
|
||||
region = find_region(env.params.query["region"]?) || prefs.region
|
||||
|
||||
query = Invidious::Search::Query.new(env.params.query, :regular, region)
|
||||
|
||||
|
@ -9,7 +9,7 @@ module Invidious::Routes::VideoPlayback
|
||||
mns ||= [] of String
|
||||
|
||||
if query_params["region"]?
|
||||
region = query_params["region"]
|
||||
region = find_region(query_params["region"])
|
||||
query_params.delete("region")
|
||||
end
|
||||
|
||||
@ -265,7 +265,7 @@ module Invidious::Routes::VideoPlayback
|
||||
return error_template(400, "Invalid itag")
|
||||
end
|
||||
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
local = (env.params.query["local"]? == "true")
|
||||
|
||||
title = env.params.query["title"]?
|
||||
|
@ -3,7 +3,7 @@
|
||||
module Invidious::Routes::Watch
|
||||
def self.handle(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
region = env.params.query["region"]?
|
||||
region = find_region(env.params.query["region"]?)
|
||||
|
||||
if env.params.query.to_s.includes?("%20") || env.params.query.to_s.includes?("+")
|
||||
url = "/watch?" + env.params.query.to_s.gsub("%20", "").delete("+")
|
||||
|
@ -25,3 +25,13 @@ REGIONS = {
|
||||
"TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI",
|
||||
"VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW",
|
||||
}
|
||||
|
||||
# Utility function that searches in the array above for a given input.
|
||||
def find_region(reg : String?) : String?
|
||||
return nil if reg.nil?
|
||||
|
||||
# Normalize input
|
||||
region = (reg || "").upcase[0..1]
|
||||
|
||||
return REGIONS.find(&.== region)
|
||||
end
|
||||
|
@ -38,7 +38,9 @@ def process_video_params(query, preferences)
|
||||
preferred_captions = query["subtitles"]?.try &.split(",").map(&.downcase)
|
||||
quality = query["quality"]?
|
||||
quality_dash = query["quality_dash"]?
|
||||
region = query["region"]?
|
||||
|
||||
region = find_region(query["region"]?)
|
||||
|
||||
related_videos = query["related_videos"]?.try { |q| (q == "true" || q == "1").to_unsafe }
|
||||
speed = query["speed"]?.try &.rchop("x").to_f?
|
||||
video_loop = query["loop"]?.try { |q| (q == "true" || q == "1").to_unsafe }
|
||||
|
Loading…
Reference in New Issue
Block a user