summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-09-30 20:26:28 -0500
committerOmar Roth <omarroth@hotmail.com>2018-09-30 20:26:28 -0500
commit8c04768ef8a5429f176deb7983879e2c5bb17132 (patch)
tree62d67f5f1f48c81408a97d66e6e8ddf7f9eddb26 /src
parenta718d5543d918f956e3339df1260d9620f902270 (diff)
downloadinvidious-8c04768ef8a5429f176deb7983879e2c5bb17132.tar.gz
invidious-8c04768ef8a5429f176deb7983879e2c5bb17132.tar.bz2
invidious-8c04768ef8a5429f176deb7983879e2c5bb17132.zip
Add support for geo-bypass in '/videoplayback'
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index a52eb311..073ed354 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -3230,6 +3230,33 @@ get "/videoplayback" do |env|
client = make_client(URI.parse(host))
response = client.head(url)
+ if response.status_code == 403
+ ip = query_params["ip"]
+ proxy = proxies.values.flatten.select { |proxy| proxy[:ip] == ip }
+ if proxy.empty?
+ halt env, status_code: 403
+ end
+
+ proxy = proxy[0]
+ # Try to find proxy in same region
+ proxy = proxies.select { |region, list| list.includes? proxy }.values[0].sample(1)[0]
+ if proxy.empty?
+ halt env, status_code: 403
+ end
+
+ client = HTTPClient.new(URI.parse(host))
+ client.read_timeout = 10.seconds
+ client.connect_timeout = 10.seconds
+
+ proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port])
+ client.set_proxy(proxy)
+
+ response = client.head(url)
+
+ # For whatever reason the proxy needs to be set again
+ client.set_proxy(proxy)
+ end
+
if response.headers["Location"]?
url = URI.parse(response.headers["Location"])
env.response.headers["Access-Control-Allow-Origin"] = "*"