Skip to content

Commit ae28502

Browse files
committed
Fix method for detecting valid info resposne
1 parent d418f50 commit ae28502

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/invidious/videos.cr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ def fetch_video(id, proxies)
552552
proxy = HTTPProxy.new(proxy_host: proxy[:ip], proxy_port: proxy[:port])
553553
client.set_proxy(proxy)
554554

555-
response = client.head("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1")
556-
if response.status_code == 200
555+
info = HTTP::Params.parse(client.get("/get_video_info?video_id=#{id}&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body)
556+
if !info["reason"]?
557557
bypass_channel.send(proxy)
558558
else
559559
bypass_channel.send(nil)
@@ -569,26 +569,26 @@ def fetch_video(id, proxies)
569569
proxies.size.times do
570570
proxy = bypass_channel.receive
571571
if proxy
572-
client = HTTPClient.new(YT_URL)
573-
client.read_timeout = 10.seconds
574-
client.connect_timeout = 10.seconds
575-
client.set_proxy(proxy)
572+
begin
573+
client = HTTPClient.new(YT_URL)
574+
client.read_timeout = 10.seconds
575+
client.connect_timeout = 10.seconds
576+
client.set_proxy(proxy)
576577

577-
proxy = {ip: proxy.proxy_host, port: proxy.proxy_port}
578-
region = proxies.select { |region, list| list.includes? proxy }.keys[0]
578+
html = XML.parse_html(client.get("/watch?v=#{id}&bpctr=#{Time.new.epoch + 2000}&gl=US&hl=en&disable_polymer=1").body)
579+
info = HTTP::Params.parse(client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body)
579580

580-
html = client.get("/watch?v=#{id}&bpctr=#{Time.new.epoch + 2000}&gl=US&hl=en&disable_polymer=1")
581-
html = XML.parse_html(html.body)
582-
583-
info = client.get("/get_video_info?video_id=#{id}&el=detailpage&ps=default&eurl=&gl=US&hl=en&disable_polymer=1")
584-
info = HTTP::Params.parse(info.body)
581+
if info["reason"]?
582+
info = HTTP::Params.parse(client.get("/get_video_info?video_id=#{id}&ps=default&eurl=&gl=US&hl=en&disable_polymer=1").body)
583+
end
585584

586-
if info["reason"]?
587-
info = client.get("/get_video_info?video_id=#{id}&ps=default&eurl=&gl=US&hl=en&disable_polymer=1")
588-
info = HTTP::Params.parse(info.body)
585+
proxy = {ip: proxy.proxy_host, port: proxy.proxy_port}
586+
region = proxies.select { |region, list| list.includes? proxy }
587+
if !region.empty?
588+
info["region"] = region.keys[0]
589+
end
590+
rescue ex
589591
end
590-
591-
info["region"] = region
592592
end
593593
end
594594
end

0 commit comments

Comments
 (0)