mirror of
				https://github.com/iv-org/invidious.git
				synced 2025-11-03 22:21:55 +00:00 
			
		
		
		
	Use alternate source for proxies
This commit is contained in:
		@@ -89,6 +89,49 @@ class HTTPClient < HTTP::Client
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def get_proxies(country_code = "US")
 | 
			
		||||
  # return get_spys_proxies(country_code)
 | 
			
		||||
  return get_nova_proxies(country_code)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def get_nova_proxies(country_code = "US")
 | 
			
		||||
  country_code = country_code.downcase
 | 
			
		||||
  client = HTTP::Client.new(URI.parse("https://www.proxynova.com"))
 | 
			
		||||
  client.read_timeout = 10.seconds
 | 
			
		||||
  client.connect_timeout = 10.seconds
 | 
			
		||||
 | 
			
		||||
  headers = HTTP::Headers.new
 | 
			
		||||
  headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
 | 
			
		||||
  headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
 | 
			
		||||
  headers["Accept-Language"] = "Accept-Language: en-US,en;q=0.9"
 | 
			
		||||
  headers["Host"] = "www.proxynova.com"
 | 
			
		||||
  headers["Origin"] = "https://www.proxynova.com"
 | 
			
		||||
  headers["Referer"] = "https://www.proxynova.com/proxy-server-list/country-#{country_code}/"
 | 
			
		||||
 | 
			
		||||
  response = client.get("/proxy-server-list/country-#{country_code}/", headers)
 | 
			
		||||
  document = XML.parse_html(response.body)
 | 
			
		||||
 | 
			
		||||
  proxies = [] of {ip: String, port: Int32, score: Float64}
 | 
			
		||||
  document.xpath_nodes(%q(//tr[@data-proxy-id])).each do |node|
 | 
			
		||||
    ip = node.xpath_node(%q(.//td/abbr/script)).not_nil!.content
 | 
			
		||||
    ip = ip.match(/document\.write\('(?<sub1>[^']+)'.substr\(8\) \+ '(?<sub2>[^']+)'/).not_nil!
 | 
			
		||||
    ip = "#{ip["sub1"][8..-1]}#{ip["sub2"]}"
 | 
			
		||||
    port = node.xpath_node(%q(.//td[2])).not_nil!.content.strip.to_i
 | 
			
		||||
 | 
			
		||||
    anchor = node.xpath_node(%q(.//td[4]/div)).not_nil!
 | 
			
		||||
    speed = anchor["data-value"].to_f
 | 
			
		||||
    latency = anchor["title"].to_f
 | 
			
		||||
    uptime = node.xpath_node(%q(.//td[5]/span)).not_nil!.content.rchop("%").to_f
 | 
			
		||||
 | 
			
		||||
    # TODO: Tweak me
 | 
			
		||||
    score = (uptime*4 + speed*2 + latency)/7
 | 
			
		||||
    proxies << {ip: ip, port: port, score: score}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  proxies = proxies.sort_by { |proxy| proxy[:score] }.reverse
 | 
			
		||||
  return proxies
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def get_spys_proxies(country_code = "US")
 | 
			
		||||
  client = HTTP::Client.new(URI.parse("http://spys.one"))
 | 
			
		||||
  client.read_timeout = 10.seconds
 | 
			
		||||
  client.connect_timeout = 10.seconds
 | 
			
		||||
 
 | 
			
		||||
@@ -110,7 +110,7 @@ CAPTION_LANGUAGES = {
 | 
			
		||||
 | 
			
		||||
REGIONS        = {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"}
 | 
			
		||||
BYPASS_REGIONS = {
 | 
			
		||||
  "UK",
 | 
			
		||||
  "GB",
 | 
			
		||||
  "DE",
 | 
			
		||||
  "FR",
 | 
			
		||||
  "IN",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user