aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2017-02-04 18:49:58 +0700
committerSergey M <dstftw@gmail.com>2017-02-19 05:10:08 +0800
commit773f291dcbce486fefe24e1abd29735d374d0a9e (patch)
tree0485bd4536891278d6928c66dc59cfda21664ee1 /youtube_dl/YoutubeDL.py
parentbf5b9d859a1f2a68fda0dc57eb839448c7571dfa (diff)
downloadyoutube-dl-773f291dcbce486fefe24e1abd29735d374d0a9e.tar.xz
Add experimental geo restriction bypass mechanism
Based on faking X-Forwarded-For HTTP header
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rwxr-xr-xyoutube_dl/YoutubeDL.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index a7bf5a1b0..ebace6b57 100755
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -56,6 +56,8 @@ from .utils import (
ExtractorError,
format_bytes,
formatSeconds,
+ GeoRestrictedError,
+ ISO3166Utils,
locked_file,
make_HTTPS_handler,
MaxDownloadsReached,
@@ -272,6 +274,13 @@ class YoutubeDL(object):
If it returns None, the video is downloaded.
match_filter_func in utils.py is one example for this.
no_color: Do not emit color codes in output.
+ bypass_geo_restriction:
+ Bypass geographic restriction via faking X-Forwarded-For
+ HTTP header (experimental)
+ bypass_geo_restriction_as_country:
+ Two-letter ISO 3166-2 country code that will be used for
+ explicit geographic restriction bypassing via faking
+ X-Forwarded-For HTTP header (experimental)
The following options determine which downloader is picked:
external_downloader: Executable of the external downloader to call.
@@ -707,6 +716,14 @@ class YoutubeDL(object):
return self.process_ie_result(ie_result, download, extra_info)
else:
return ie_result
+ except GeoRestrictedError as e:
+ msg = e.msg
+ if e.countries:
+ msg += '\nThis video is available in %s.' % ', '.join(
+ map(ISO3166Utils.short2full, e.countries))
+ msg += '\nYou might want to use a VPN or a proxy server (with --proxy) to workaround.'
+ self.report_error(msg)
+ break
except ExtractorError as e: # An error we somewhat expected
self.report_error(compat_str(e), e.format_traceback())
break