[ivi] fix format extraction(closes #21991)
parent
8b1a30c993
commit
656c20010f
|
@ -18,6 +18,8 @@ class IviIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?ivi\.(?:ru|tv)/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www\.)?ivi\.(?:ru|tv)/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
|
||||||
_GEO_BYPASS = False
|
_GEO_BYPASS = False
|
||||||
_GEO_COUNTRIES = ['RU']
|
_GEO_COUNTRIES = ['RU']
|
||||||
|
_LIGHT_KEY = b'\xf1\x02\x32\xb7\xbc\x5c\x7a\xe8\xf7\x96\xc1\x33\x2b\x27\xa1\x8c'
|
||||||
|
_LIGHT_URL = 'https://api.ivi.ru/light/'
|
||||||
|
|
||||||
_TESTS = [
|
_TESTS = [
|
||||||
# Single movie
|
# Single movie
|
||||||
|
@ -78,25 +80,41 @@ class IviIE(InfoExtractor):
|
||||||
'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
|
'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
|
try:
|
||||||
|
from Crypto.Cipher import Blowfish
|
||||||
|
from Crypto.Hash import CMAC
|
||||||
|
except ImportError:
|
||||||
|
raise ExtractorError('pycrypto not found. Please install it.', expected=True)
|
||||||
|
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
data = {
|
timestamp = self._download_json(
|
||||||
|
self._LIGHT_URL, video_id,
|
||||||
|
'Downloading timestamp JSON', data=json.dumps({
|
||||||
|
'method': 'da.timestamp.get',
|
||||||
|
'params': []
|
||||||
|
}).encode())['result']
|
||||||
|
|
||||||
|
data = json.dumps({
|
||||||
'method': 'da.content.get',
|
'method': 'da.content.get',
|
||||||
'params': [
|
'params': [
|
||||||
video_id, {
|
video_id, {
|
||||||
'site': 's183',
|
'site': 's353',
|
||||||
'referrer': 'http://www.ivi.ru/watch/%s' % video_id,
|
'referrer': 'http://www.ivi.ru/watch/%s' % video_id,
|
||||||
'contentid': video_id
|
'contentid': video_id
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}).encode()
|
||||||
|
|
||||||
video_json = self._download_json(
|
video_json = self._download_json(
|
||||||
'http://api.digitalaccess.ru/api/json/', video_id,
|
self._LIGHT_URL, video_id,
|
||||||
'Downloading video JSON', data=json.dumps(data))
|
'Downloading video JSON', data=data, query={
|
||||||
|
'ts': timestamp,
|
||||||
|
'sign': CMAC.new(self._LIGHT_KEY, timestamp.encode() + data, Blowfish).hexdigest(),
|
||||||
|
})
|
||||||
|
|
||||||
if 'error' in video_json:
|
error = video_json.get('error')
|
||||||
error = video_json['error']
|
if error:
|
||||||
origin = error['origin']
|
origin = error['origin']
|
||||||
if origin == 'NotAllowedForLocation':
|
if origin == 'NotAllowedForLocation':
|
||||||
self.raise_geo_restricted(
|
self.raise_geo_restricted(
|
||||||
|
@ -108,20 +126,24 @@ class IviIE(InfoExtractor):
|
||||||
expected=True)
|
expected=True)
|
||||||
|
|
||||||
result = video_json['result']
|
result = video_json['result']
|
||||||
|
title = result['title']
|
||||||
|
|
||||||
quality = qualities(self._KNOWN_FORMATS)
|
quality = qualities(self._KNOWN_FORMATS)
|
||||||
|
|
||||||
formats = [{
|
formats = []
|
||||||
'url': x['url'],
|
for f in result.get('files', []):
|
||||||
'format_id': x.get('content_format'),
|
f_url = f.get('url')
|
||||||
'quality': quality(x.get('content_format')),
|
content_format = f.get('content_format')
|
||||||
} for x in result['files'] if x.get('url')]
|
if not f_url or '-MDRM-' in content_format or '-FPS-' in content_format:
|
||||||
|
continue
|
||||||
|
formats.append({
|
||||||
|
'url': f_url,
|
||||||
|
'format_id': content_format,
|
||||||
|
'quality': quality(content_format),
|
||||||
|
'filesize': int_or_none(f.get('size_in_bytes')),
|
||||||
|
})
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
title = result['title']
|
|
||||||
|
|
||||||
duration = int_or_none(result.get('duration'))
|
|
||||||
compilation = result.get('compilation')
|
compilation = result.get('compilation')
|
||||||
episode = title if compilation else None
|
episode = title if compilation else None
|
||||||
|
|
||||||
|
@ -158,7 +180,7 @@ class IviIE(InfoExtractor):
|
||||||
'episode_number': episode_number,
|
'episode_number': episode_number,
|
||||||
'thumbnails': thumbnails,
|
'thumbnails': thumbnails,
|
||||||
'description': description,
|
'description': description,
|
||||||
'duration': duration,
|
'duration': int_or_none(result.get('duration')),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue