+ for _ in range(2):
+ try:
+ self.initialize()
+ return self._real_extract(url)
+ except GeoRestrictedError as e:
+ if (not self._downloader.params.get('bypass_geo_restriction_as_country', None) and
+ self._BYPASS_GEO and
+ self._downloader.params.get('bypass_geo_restriction', True) and
+ not self._x_forwarded_for_ip and
+ e.countries):
+ self._x_forwarded_for_ip = GeoUtils.random_ipv4(random.choice(e.countries))
+ if self._x_forwarded_for_ip:
+ self.report_warning(
+ 'Video is geo restricted. Retrying extraction with fake %s IP as X-Forwarded-For.' % self._x_forwarded_for_ip)
+ continue
+ raise