Add faked X-Forwarded-For to formats' HTTP headers
This commit is contained in:
parent
18a0defab0
commit
0016b84e16
|
@ -864,8 +864,14 @@ class YoutubeDL(object):
|
||||||
if self.params.get('playlistrandom', False):
|
if self.params.get('playlistrandom', False):
|
||||||
random.shuffle(entries)
|
random.shuffle(entries)
|
||||||
|
|
||||||
|
x_forwarded_for = ie_result.get('__x_forwarded_for_ip')
|
||||||
|
|
||||||
for i, entry in enumerate(entries, 1):
|
for i, entry in enumerate(entries, 1):
|
||||||
self.to_screen('[download] Downloading video %s of %s' % (i, n_entries))
|
self.to_screen('[download] Downloading video %s of %s' % (i, n_entries))
|
||||||
|
# This __x_forwarded_for_ip thing is a bit ugly but requires
|
||||||
|
# minimal changes
|
||||||
|
if x_forwarded_for:
|
||||||
|
entry['__x_forwarded_for_ip'] = x_forwarded_for
|
||||||
extra = {
|
extra = {
|
||||||
'n_entries': n_entries,
|
'n_entries': n_entries,
|
||||||
'playlist': playlist,
|
'playlist': playlist,
|
||||||
|
@ -1250,6 +1256,11 @@ class YoutubeDL(object):
|
||||||
if cookies:
|
if cookies:
|
||||||
res['Cookie'] = cookies
|
res['Cookie'] = cookies
|
||||||
|
|
||||||
|
if 'X-Forwarded-For' not in res:
|
||||||
|
x_forwarded_for_ip = info_dict.get('__x_forwarded_for_ip')
|
||||||
|
if x_forwarded_for_ip:
|
||||||
|
res['X-Forwarded-For'] = x_forwarded_for_ip
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _calc_cookies(self, info_dict):
|
def _calc_cookies(self, info_dict):
|
||||||
|
@ -1392,6 +1403,9 @@ class YoutubeDL(object):
|
||||||
full_format_info = info_dict.copy()
|
full_format_info = info_dict.copy()
|
||||||
full_format_info.update(format)
|
full_format_info.update(format)
|
||||||
format['http_headers'] = self._calc_headers(full_format_info)
|
format['http_headers'] = self._calc_headers(full_format_info)
|
||||||
|
# Remove private housekeeping stuff
|
||||||
|
if '__x_forwarded_for_ip' in info_dict:
|
||||||
|
del info_dict['__x_forwarded_for_ip']
|
||||||
|
|
||||||
# TODO Central sorting goes here
|
# TODO Central sorting goes here
|
||||||
|
|
||||||
|
|
|
@ -384,7 +384,10 @@ class InfoExtractor(object):
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
try:
|
try:
|
||||||
self.initialize()
|
self.initialize()
|
||||||
return self._real_extract(url)
|
ie_result = self._real_extract(url)
|
||||||
|
if self._x_forwarded_for_ip:
|
||||||
|
ie_result['__x_forwarded_for_ip'] = self._x_forwarded_for_ip
|
||||||
|
return ie_result
|
||||||
except GeoRestrictedError as e:
|
except GeoRestrictedError as e:
|
||||||
if (not self._downloader.params.get('bypass_geo_restriction_as_country', None) and
|
if (not self._downloader.params.get('bypass_geo_restriction_as_country', None) and
|
||||||
self._BYPASS_GEO and
|
self._BYPASS_GEO and
|
||||||
|
|
Loading…
Reference in New Issue