mirror of https://github.com/yt-dlp/yt-dlp.git
[npo] Adapt to app.php API (closes #12311)
This commit is contained in:
parent
1dc24093f8
commit
aa9cc2ecbf
|
@ -17,27 +17,9 @@ from ..utils import (
|
||||||
|
|
||||||
class NPOBaseIE(InfoExtractor):
|
class NPOBaseIE(InfoExtractor):
|
||||||
def _get_token(self, video_id):
|
def _get_token(self, video_id):
|
||||||
token_page = self._download_webpage(
|
return self._download_json(
|
||||||
'http://ida.omroep.nl/npoplayer/i.js',
|
'http://ida.omroep.nl/app.php/auth', video_id,
|
||||||
video_id, note='Downloading token')
|
note='Downloading token')['token']
|
||||||
token = self._search_regex(
|
|
||||||
r'npoplayer\.token = "(.+?)"', token_page, 'token')
|
|
||||||
# Decryption algorithm extracted from http://npoplayer.omroep.nl/csjs/npoplayer-min.js
|
|
||||||
token_l = list(token)
|
|
||||||
first = second = None
|
|
||||||
for i in range(5, len(token_l) - 4):
|
|
||||||
if token_l[i].isdigit():
|
|
||||||
if first is None:
|
|
||||||
first = i
|
|
||||||
elif second is None:
|
|
||||||
second = i
|
|
||||||
if first is None or second is None:
|
|
||||||
first = 12
|
|
||||||
second = 13
|
|
||||||
|
|
||||||
token_l[first], token_l[second] = token_l[second], token_l[first]
|
|
||||||
|
|
||||||
return ''.join(token_l)
|
|
||||||
|
|
||||||
|
|
||||||
class NPOIE(NPOBaseIE):
|
class NPOIE(NPOBaseIE):
|
||||||
|
@ -187,32 +169,41 @@ class NPOIE(NPOBaseIE):
|
||||||
pubopties = metadata.get('pubopties')
|
pubopties = metadata.get('pubopties')
|
||||||
if pubopties:
|
if pubopties:
|
||||||
quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
|
quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
|
||||||
for format_id in pubopties:
|
items = self._download_json(
|
||||||
format_info = self._download_json(
|
'http://ida.omroep.nl/app.php/%s' % video_id,
|
||||||
'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
|
'Downloading formats JSON', query={
|
||||||
% (video_id, format_id, token),
|
'adaptive': 'yes',
|
||||||
video_id, 'Downloading %s JSON' % format_id)
|
'token': token,
|
||||||
if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
|
})['items'][0]
|
||||||
|
for num, item in enumerate(items):
|
||||||
|
item_url = item.get('url')
|
||||||
|
if not item_url:
|
||||||
continue
|
continue
|
||||||
streams = format_info.get('streams')
|
format_id = self._search_regex(
|
||||||
if streams:
|
r'video/ida/([^/]+)', item_url, 'format id',
|
||||||
try:
|
default=None)
|
||||||
video_info = self._download_json(
|
try:
|
||||||
streams[0] + '&type=json',
|
stream_info = self._download_json(
|
||||||
video_id, 'Downloading %s stream JSON' % format_id)
|
item_url + '&type=json', video_id,
|
||||||
except ExtractorError as ee:
|
'Downloading %s stream JSON' % item.get('label') or format_id or num)
|
||||||
if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404:
|
except ExtractorError as ee:
|
||||||
error = (self._parse_json(ee.cause.read().decode(), video_id, fatal=False) or {}).get('errorstring')
|
if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404:
|
||||||
if error:
|
error = (self._parse_json(
|
||||||
raise ExtractorError(error, expected=True)
|
ee.cause.read().decode(), video_id,
|
||||||
raise
|
fatal=False) or {}).get('errorstring')
|
||||||
else:
|
if error:
|
||||||
video_info = format_info
|
raise ExtractorError(error, expected=True)
|
||||||
video_url = video_info.get('url')
|
raise
|
||||||
|
if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
|
||||||
|
continue
|
||||||
|
video_url = stream_info.get('url')
|
||||||
if not video_url:
|
if not video_url:
|
||||||
continue
|
continue
|
||||||
if format_id == 'adaptive':
|
if stream_info.get('family') == 'adaptive':
|
||||||
formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4'))
|
formats.extend(self._extract_m3u8_formats(
|
||||||
|
video_url, video_id, ext='mp4',
|
||||||
|
entry_protocol='m3u8_native', m3u8_id='hls',
|
||||||
|
fatal=False))
|
||||||
else:
|
else:
|
||||||
formats.append({
|
formats.append({
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
|
|
Loading…
Reference in New Issue