Remove legacy proxy code (#4570)
Also fixes the build on nightly as the offending code was removed. Related to https://github.com/iv-org/invidious/pull/4270#issuecomment-1858876952
This commit is contained in:
commit
c94c6f4b83
|
@ -398,17 +398,6 @@ def fetch_video(id, region)
|
|||
.dig?("microformat", "playerMicroformatRenderer", "availableCountries")
|
||||
.try &.as_a.map &.as_s || [] of String
|
||||
|
||||
# Check for region-blocks
|
||||
if info["reason"]?.try &.as_s.includes?("your country")
|
||||
bypass_regions = PROXY_LIST.keys & allowed_regions
|
||||
if !bypass_regions.empty?
|
||||
region = bypass_regions[rand(bypass_regions.size)]
|
||||
region_info = extract_video_info(video_id: id, proxy_region: region)
|
||||
region_info["region"] = JSON::Any.new(region) if region
|
||||
info = region_info if !region_info["reason"]?
|
||||
end
|
||||
end
|
||||
|
||||
if reason = info["reason"]?
|
||||
if reason == "Video unavailable"
|
||||
raise NotFoundException.new(reason.as_s || "")
|
||||
|
|
|
@ -50,9 +50,9 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
|
|||
}
|
||||
end
|
||||
|
||||
def extract_video_info(video_id : String, proxy_region : String? = nil)
|
||||
def extract_video_info(video_id : String)
|
||||
# Init client config for the API
|
||||
client_config = YoutubeAPI::ClientConfig.new(proxy_region: proxy_region)
|
||||
client_config = YoutubeAPI::ClientConfig.new
|
||||
|
||||
# Fetch data from the player endpoint
|
||||
player_response = YoutubeAPI.player(video_id: video_id, params: "", client_config: client_config)
|
||||
|
|
|
@ -24,25 +24,20 @@ struct YoutubeConnectionPool
|
|||
@pool = build_pool()
|
||||
end
|
||||
|
||||
def client(region = nil, &block)
|
||||
if region
|
||||
conn = make_client(url, region, force_resolve = true)
|
||||
def client(&block)
|
||||
conn = pool.checkout
|
||||
begin
|
||||
response = yield conn
|
||||
else
|
||||
conn = pool.checkout
|
||||
begin
|
||||
response = yield conn
|
||||
rescue ex
|
||||
conn.close
|
||||
conn = HTTP::Client.new(url)
|
||||
rescue ex
|
||||
conn.close
|
||||
conn = HTTP::Client.new(url)
|
||||
|
||||
conn.family = CONFIG.force_resolve
|
||||
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
|
||||
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
||||
response = yield conn
|
||||
ensure
|
||||
pool.release(conn)
|
||||
end
|
||||
conn.family = CONFIG.force_resolve
|
||||
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
|
||||
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
||||
response = yield conn
|
||||
ensure
|
||||
pool.release(conn)
|
||||
end
|
||||
|
||||
response
|
||||
|
@ -60,9 +55,9 @@ struct YoutubeConnectionPool
|
|||
end
|
||||
|
||||
def make_client(url : URI, region = nil, force_resolve : Bool = false)
|
||||
client = HTTPClient.new(url, OpenSSL::SSL::Context::Client.insecure)
|
||||
client = HTTP::Client.new(url)
|
||||
|
||||
# Some services do not support IPv6.
|
||||
# Force the usage of a specific configured IP Family
|
||||
if force_resolve
|
||||
client.family = CONFIG.force_resolve
|
||||
end
|
||||
|
@ -71,17 +66,6 @@ def make_client(url : URI, region = nil, force_resolve : Bool = false)
|
|||
client.read_timeout = 10.seconds
|
||||
client.connect_timeout = 10.seconds
|
||||
|
||||
if region
|
||||
PROXY_LIST[region]?.try &.sample(40).each do |proxy|
|
||||
begin
|
||||
proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port])
|
||||
client.set_proxy(proxy)
|
||||
break
|
||||
rescue ex
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return client
|
||||
end
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -188,10 +188,6 @@ module YoutubeAPI
|
|||
# conf_2 = ClientConfig.new(client_type: ClientType::Android)
|
||||
# YoutubeAPI::player(video_id: "dQw4w9WgXcQ", client_config: conf_2)
|
||||
#
|
||||
# # Proxy request through russian proxies
|
||||
# conf_3 = ClientConfig.new(proxy_region: "RU")
|
||||
# YoutubeAPI::next({video_id: "dQw4w9WgXcQ"}, client_config: conf_3)
|
||||
# ```
|
||||
#
|
||||
struct ClientConfig
|
||||
# Type of client to emulate.
|
||||
|
@ -202,16 +198,11 @@ module YoutubeAPI
|
|||
# (this is passed as the `gl` parameter).
|
||||
property region : String | Nil
|
||||
|
||||
# ISO code of country where the proxy is located.
|
||||
# Used in case of geo-restricted videos.
|
||||
property proxy_region : String | Nil
|
||||
|
||||
# Initialization function
|
||||
def initialize(
|
||||
*,
|
||||
@client_type = ClientType::Web,
|
||||
@region = "US",
|
||||
@proxy_region = nil
|
||||
@region = "US"
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -271,9 +262,8 @@ module YoutubeAPI
|
|||
# Convert to string, for logging purposes
|
||||
def to_s
|
||||
return {
|
||||
client_type: self.name,
|
||||
region: @region,
|
||||
proxy_region: @proxy_region,
|
||||
client_type: self.name,
|
||||
region: @region,
|
||||
}.to_s
|
||||
end
|
||||
end
|
||||
|
@ -620,7 +610,7 @@ module YoutubeAPI
|
|||
LOGGER.trace("YoutubeAPI: POST data: #{data}")
|
||||
|
||||
# Send the POST request
|
||||
body = YT_POOL.client(client_config.proxy_region) do |client|
|
||||
body = YT_POOL.client() do |client|
|
||||
client.post(url, headers: headers, body: data.to_json) do |response|
|
||||
self._decompress(response.body_io, response.headers["Content-Encoding"]?)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue