- def _extract_formats(self, manifest_url, video_id, fatal=True):
- formats = []
- formats.extend(self._extract_f4m_formats(
- manifest_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81',
- video_id, f4m_id='hds', fatal=fatal))
- formats.extend(self._extract_m3u8_formats(manifest_url.replace(
- 'akamaihd.net/z/', 'akamaihd.net/i/').replace('/manifest.f4m', '/master.m3u8'),
- video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=fatal))
- return formats
+ _faked_ip = None
+
+ def _download_webpage_handle(self, *args, **kwargs):
+ # NRK checks X-Forwarded-For HTTP header in order to figure out the
+ # origin of the client behind proxy. This allows to bypass geo
+ # restriction by faking this header's value to some Norway IP.
+ # We will do so once we encounter any geo restriction error.
+ if self._faked_ip:
+ # NB: str is intentional
+ kwargs.setdefault(str('headers'), {})['X-Forwarded-For'] = self._faked_ip
+ return super(NRKBaseIE, self)._download_webpage_handle(*args, **kwargs)
+
+ def _fake_ip(self):
+ # Use fake IP from 37.191.128.0/17 in order to workaround geo
+ # restriction
+ def octet(lb=0, ub=255):
+ return random.randint(lb, ub)
+ self._faked_ip = '37.191.%d.%d' % (octet(128), octet())