mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-22 10:11:52 +00:00
[nrk] Add X-Forwarded-For HTTP header in info dict
This commit is contained in:
parent
690355551c
commit
7e08e2cab0
1 changed files with 7 additions and 3 deletions
|
@ -17,14 +17,15 @@ from ..utils import (
|
||||||
class NRKBaseIE(InfoExtractor):
|
class NRKBaseIE(InfoExtractor):
|
||||||
_faked_ip = None
|
_faked_ip = None
|
||||||
|
|
||||||
def _download_webpage(self, *args, **kwargs):
|
def _download_webpage_handle(self, *args, **kwargs):
|
||||||
# NRK checks X-Forwarded-For HTTP header in order to figure out the
|
# NRK checks X-Forwarded-For HTTP header in order to figure out the
|
||||||
# origin of the client behind proxy. This allows to bypass geo
|
# origin of the client behind proxy. This allows to bypass geo
|
||||||
# restriction by faking this header's value to some Norway IP.
|
# restriction by faking this header's value to some Norway IP.
|
||||||
# We will do so once we encounter any geo restriction error.
|
# We will do so once we encounter any geo restriction error.
|
||||||
if self._faked_ip:
|
if self._faked_ip:
|
||||||
kwargs.setdefault('headers', {})['X-Forwarded-For'] = self._faked_ip
|
# NB: str is intentional
|
||||||
return super(NRKBaseIE, self)._download_webpage(*args, **kwargs)
|
kwargs.setdefault(str('headers'), {})['X-Forwarded-For'] = self._faked_ip
|
||||||
|
return super(NRKBaseIE, self)._download_webpage_handle(*args, **kwargs)
|
||||||
|
|
||||||
def _fake_ip(self):
|
def _fake_ip(self):
|
||||||
# Use fake IP from 37.191.128.0/17 in order to workaround geo
|
# Use fake IP from 37.191.128.0/17 in order to workaround geo
|
||||||
|
@ -43,6 +44,8 @@ class NRKBaseIE(InfoExtractor):
|
||||||
title = data.get('fullTitle') or data.get('mainTitle') or data['title']
|
title = data.get('fullTitle') or data.get('mainTitle') or data['title']
|
||||||
video_id = data.get('id') or video_id
|
video_id = data.get('id') or video_id
|
||||||
|
|
||||||
|
http_headers = {'X-Forwarded-For': self._faked_ip} if self._faked_ip else {}
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
media_assets = data.get('mediaAssets')
|
media_assets = data.get('mediaAssets')
|
||||||
|
@ -73,6 +76,7 @@ class NRKBaseIE(InfoExtractor):
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
|
'http_headers': http_headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
if not entries:
|
if not entries:
|
||||||
|
|
Loading…
Reference in a new issue