aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2018-05-02 07:18:01 +0700
committerSergey M․ <dstftw@gmail.com>2018-05-02 07:20:59 +0700
commit5f95927a62a533b9e616abb5f1481cedeaa16a4a (patch)
tree13e1cbddf07dd4259211ede5df0d2705604ca5b1 /youtube_dl/utils.py
parenta93ce61bd5cbe7779e4eff0f8ab74a8a02211285 (diff)
Improve geo bypass mechanism
* Introduce geo bypass context * Add ability to bypass based on IP blocks in CIDR notation * Introduce --geo-bypass-ip-block
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index b460393bf..f9ca63c58 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -3534,10 +3534,13 @@ class GeoUtils(object):
}
@classmethod
- def random_ipv4(cls, code):
- block = cls._country_ip_map.get(code.upper())
- if not block:
- return None
+ def random_ipv4(cls, code_or_block):
+ if len(code_or_block) == 2:
+ block = cls._country_ip_map.get(code_or_block.upper())
+ if not block:
+ return None
+ else:
+ block = code_or_block
addr, preflen = block.split('/')
addr_min = compat_struct_unpack('!L', socket.inet_aton(addr))[0]
addr_max = addr_min | (0xffffffff >> int(preflen))