mirror of
				https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
				synced 2024-08-15 00:53:38 +00:00 
			
		
		
		
	Fix allowed_regions for globally blocked videos
This commit is contained in:
		
							parent
							
								
									acaf7b969a
								
							
						
					
					
						commit
						e768e1e277
					
				
					 1 changed files with 15 additions and 36 deletions
				
			
		| 
						 | 
				
			
			@ -109,32 +109,6 @@ 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 = {
 | 
			
		||||
  "GB",
 | 
			
		||||
  "DE",
 | 
			
		||||
  "FR",
 | 
			
		||||
  "IN",
 | 
			
		||||
  "CN",
 | 
			
		||||
  "RU",
 | 
			
		||||
  "CA",
 | 
			
		||||
  "JP",
 | 
			
		||||
  "IT",
 | 
			
		||||
  "TH",
 | 
			
		||||
  "ES",
 | 
			
		||||
  "AE",
 | 
			
		||||
  "KR",
 | 
			
		||||
  "IR",
 | 
			
		||||
  "BR",
 | 
			
		||||
  "PK",
 | 
			
		||||
  "ID",
 | 
			
		||||
  "BD",
 | 
			
		||||
  "MX",
 | 
			
		||||
  "PH",
 | 
			
		||||
  "EG",
 | 
			
		||||
  "VN",
 | 
			
		||||
  "CD",
 | 
			
		||||
  "TR",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L380-#L476
 | 
			
		||||
VIDEO_FORMATS = {
 | 
			
		||||
| 
						 | 
				
			
			@ -1133,11 +1107,15 @@ def fetch_video(id, region)
 | 
			
		|||
  info["cookie"] = response.cookies.to_h.map { |name, cookie| "#{name}=#{cookie.value}" }.join("; ")
 | 
			
		||||
 | 
			
		||||
  allowed_regions = html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).try &.["content"].split(",")
 | 
			
		||||
  allowed_regions ||= [] of String
 | 
			
		||||
  if !allowed_regions || allowed_regions == [""]
 | 
			
		||||
    allowed_regions = [] of String
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Check for region-blocks
 | 
			
		||||
  if info["reason"]? && info["reason"].includes? "your country"
 | 
			
		||||
    region = allowed_regions.sample(1)[0]?
 | 
			
		||||
  if info["reason"]? && info["reason"].includes?("your country")
 | 
			
		||||
    bypass_regions = PROXY_LIST.keys & allowed_regions
 | 
			
		||||
    if !bypass_regions.empty?
 | 
			
		||||
      region = bypass_regions[rand(bypass_regions.size)]
 | 
			
		||||
      client = make_client(YT_URL, region)
 | 
			
		||||
      response = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1147,6 +1125,7 @@ def fetch_video(id, region)
 | 
			
		|||
      info["region"] = region if region
 | 
			
		||||
      info["cookie"] = response.cookies.to_h.map { |name, cookie| "#{name}=#{cookie.value}" }.join("; ")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Try to pull streams from embed URL
 | 
			
		||||
  if info["reason"]?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue