@@ -552,8 +552,8 @@ def fetch_video(id, proxies)
552
552
proxy = HTTPProxy .new(proxy_host: proxy[:ip ], proxy_port: proxy[:port ])
553
553
client.set_proxy(proxy)
554
554
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 " ]?
557
557
bypass_channel.send(proxy)
558
558
else
559
559
bypass_channel.send(nil )
@@ -569,26 +569,26 @@ def fetch_video(id, proxies)
569
569
proxies.size.times do
570
570
proxy = bypass_channel.receive
571
571
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)
576
577
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)
579
580
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
585
584
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
589
591
end
590
-
591
- info[" region" ] = region
592
592
end
593
593
end
594
594
end
0 commit comments