1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-10 05:47:24 +08:00

update ivi.ru extractor to get list of formats

This commit is contained in:
Vladimir Krylov 2019-12-30 15:20:55 +02:00
parent 75ef77c1b1
commit c65c6fe2ee

View File

@ -78,36 +78,40 @@ class IviIE(InfoExtractor):
# Sorted by quality # Sorted by quality
_KNOWN_FORMATS = ( _KNOWN_FORMATS = (
'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi', 'MP4-low-mobile', 'MP4-mobile', 'FLV-lo', 'MP4-lo', 'FLV-hi', 'MP4-hi',
'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080') 'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080', 'VODDASH-MDRM-HD1080', 'VODHLS-FPS-HD1080',
'DASH-MDRM-HD1080')
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
session = self._get_cookies(url).get('sessivi')
if session:
session = session.value
data = json.dumps({ data = json.dumps({
'method': 'da.content.get', 'method': 'da.content.get',
'params': [ 'params': [
video_id, { video_id, {
'app_version': 5459,
'session': session,
'site': 's%d', 'site': 's%d',
'referrer': 'http://www.ivi.ru/watch/%s' % video_id, '_url': 'https://www.ivi.ru/watch/%s' % video_id,
'contentid': video_id 'contentid': video_id
} }
] ]
}) })
bundled = hasattr(sys, 'frozen') bundled = hasattr(sys, 'frozen')
site = 353
for site in (353, 183):
content_data = (data % site).encode() content_data = (data % site).encode()
if site == 353:
if bundled:
continue
try: try:
from Cryptodome.Cipher import Blowfish from Cryptodome.Cipher import Blowfish
from Cryptodome.Hash import CMAC from Cryptodome.Hash import CMAC
pycryptodomex_found = True
except ImportError: except ImportError:
pycryptodomex_found = False raise ExtractorError(
continue 'pycryptodomex not found. Please install it.',
expected=True)
timestamp = (self._download_json( timestamp = (self._download_json(
self._LIGHT_URL, video_id, self._LIGHT_URL, video_id,
@ -115,15 +119,12 @@ class IviIE(InfoExtractor):
'method': 'da.timestamp.get', 'method': 'da.timestamp.get',
'params': [] 'params': []
}).encode(), fatal=False) or {}).get('result') }).encode(), fatal=False) or {}).get('result')
if not timestamp:
continue
query = { query = {
'app_version': 5459,
'ts': timestamp, 'ts': timestamp,
'sign': CMAC.new(self._LIGHT_KEY, timestamp.encode() + content_data, Blowfish).hexdigest(), 'sign': CMAC.new(self._LIGHT_KEY, timestamp.encode() + content_data, Blowfish).hexdigest(),
} }
else:
query = {}
video_json = self._download_json( video_json = self._download_json(
self._LIGHT_URL, video_id, self._LIGHT_URL, video_id,
@ -138,21 +139,14 @@ class IviIE(InfoExtractor):
self.raise_geo_restricted(message, self._GEO_COUNTRIES) self.raise_geo_restricted(message, self._GEO_COUNTRIES)
elif origin == 'NoRedisValidData': elif origin == 'NoRedisValidData':
extractor_msg = 'Video %s does not exist' extractor_msg = 'Video %s does not exist'
elif site == 353:
continue
elif bundled: elif bundled:
raise ExtractorError( raise ExtractorError(
'This feature does not work from bundled exe. Run youtube-dl from sources.', 'This feature does not work from bundled exe. Run youtube-dl from sources.',
expected=True) expected=True)
elif not pycryptodomex_found:
raise ExtractorError(
'pycryptodomex not found. Please install it.',
expected=True)
elif message: elif message:
extractor_msg += ': ' + message extractor_msg += ': ' + message
raise ExtractorError(extractor_msg % video_id, expected=True) raise ExtractorError(extractor_msg % video_id, expected=True)
else:
break
result = video_json['result'] result = video_json['result']
title = result['title'] title = result['title']
@ -163,8 +157,8 @@ class IviIE(InfoExtractor):
for f in result.get('files', []): for f in result.get('files', []):
f_url = f.get('url') f_url = f.get('url')
content_format = f.get('content_format') content_format = f.get('content_format')
if not f_url or '-MDRM-' in content_format or '-FPS-' in content_format: # if not f_url or '-MDRM-' in content_format or '-FPS-' in content_format:
continue # continue
formats.append({ formats.append({
'url': f_url, 'url': f_url,
'format_id': content_format, 'format_id': content_format,