Skip to content

Commit

Permalink
[ivi] fix format extraction(closes #21991)
Browse files Browse the repository at this point in the history
  • Loading branch information
remitamine committed Nov 15, 2019
1 parent 8b1a30c commit 656c200
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions youtube_dl/extractor/ivi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class IviIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?ivi\.(?:ru|tv)/(?:watch/(?:[^/]+/)?|video/player\?.*?videoId=)(?P<id>\d+)'
_GEO_BYPASS = False
_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 = [
# Single movie
Expand Down Expand Up @@ -78,25 +80,41 @@ class IviIE(InfoExtractor):
'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')

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)

This comment has been minimized.

Copy link
@dstftw

dstftw Nov 15, 2019

Collaborator
  1. Latest pycrypto release on pip does not contain CMAC so this is impossible to use with regular flow.
  2. Videos from tests work fine with old approach thus pycrypto should not be a hard dependency here.

This comment has been minimized.

Copy link
@remitamine

remitamine Nov 15, 2019

Author Collaborator

fixed in 1bba88e.


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',
'params': [
video_id, {
'site': 's183',
'site': 's353',
'referrer': 'http://www.ivi.ru/watch/%s' % video_id,
'contentid': video_id
}
]
}
}).encode()

video_json = self._download_json(
'http://api.digitalaccess.ru/api/json/', video_id,
'Downloading video JSON', data=json.dumps(data))

if 'error' in video_json:
error = video_json['error']
self._LIGHT_URL, video_id,
'Downloading video JSON', data=data, query={
'ts': timestamp,
'sign': CMAC.new(self._LIGHT_KEY, timestamp.encode() + data, Blowfish).hexdigest(),
})

error = video_json.get('error')
if error:
origin = error['origin']
if origin == 'NotAllowedForLocation':
self.raise_geo_restricted(
Expand All @@ -108,20 +126,24 @@ def _real_extract(self, url):
expected=True)

result = video_json['result']
title = result['title']

quality = qualities(self._KNOWN_FORMATS)

formats = [{
'url': x['url'],
'format_id': x.get('content_format'),
'quality': quality(x.get('content_format')),
} for x in result['files'] if x.get('url')]

formats = []
for f in result.get('files', []):
f_url = f.get('url')
content_format = f.get('content_format')
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)

title = result['title']

duration = int_or_none(result.get('duration'))
compilation = result.get('compilation')
episode = title if compilation else None

Expand Down Expand Up @@ -158,7 +180,7 @@ def _real_extract(self, url):
'episode_number': episode_number,
'thumbnails': thumbnails,
'description': description,
'duration': duration,
'duration': int_or_none(result.get('duration')),
'formats': formats,
}

Expand Down

0 comments on commit 656c200

Please sign in to comment.