Skip to content

Commit 1bba88e

Browse files
committed
[ivi] sign content request only when pycryptodome is available
1 parent 656c200 commit 1bba88e

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

youtube_dl/extractor/ivi.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,42 @@ class IviIE(InfoExtractor):
8080
'MP4-SHQ', 'MP4-HD720', 'MP4-HD1080')
8181

8282
def _real_extract(self, url):
83-
try:
84-
from Crypto.Cipher import Blowfish
85-
from Crypto.Hash import CMAC
86-
except ImportError:
87-
raise ExtractorError('pycrypto not found. Please install it.', expected=True)
88-
8983
video_id = self._match_id(url)
9084

91-
timestamp = self._download_json(
92-
self._LIGHT_URL, video_id,
93-
'Downloading timestamp JSON', data=json.dumps({
94-
'method': 'da.timestamp.get',
95-
'params': []
96-
}).encode())['result']
97-
9885
data = json.dumps({
9986
'method': 'da.content.get',
10087
'params': [
10188
video_id, {
102-
'site': 's353',
89+
'site': 's%d',
10390
'referrer': 'http://www.ivi.ru/watch/%s' % video_id,
10491
'contentid': video_id
10592
}
10693
]
10794
}).encode()
10895

109-
video_json = self._download_json(
110-
self._LIGHT_URL, video_id,
111-
'Downloading video JSON', data=data, query={
96+
try:
97+
from Crypto.Cipher import Blowfish
98+
from Crypto.Hash import CMAC
99+
100+
timestamp = self._download_json(
101+
self._LIGHT_URL, video_id,
102+
'Downloading timestamp JSON', data=json.dumps({
103+
'method': 'da.timestamp.get',
104+
'params': []
105+
}).encode())['result']
106+
107+
data = data % 353
108+
query = {
112109
'ts': timestamp,
113110
'sign': CMAC.new(self._LIGHT_KEY, timestamp.encode() + data, Blowfish).hexdigest(),
114-
})
111+
}
112+
except ImportError:
113+
data = data % 183
114+
query = {}
115+
116+
video_json = self._download_json(
117+
self._LIGHT_URL, video_id,
118+
'Downloading video JSON', data=data, query=query)
115119

116120
error = video_json.get('error')
117121
if error:
@@ -121,6 +125,8 @@ def _real_extract(self, url):
121125
msg=error['message'], countries=self._GEO_COUNTRIES)
122126
elif origin == 'NoRedisValidData':
123127
raise ExtractorError('Video %s does not exist' % video_id, expected=True)
128+
elif origin == 'NotAllowedError':
129+
raise ExtractorError('pycryptodome not found. Please install it.', expected=True)
124130
raise ExtractorError(
125131
'Unable to download video %s: %s' % (video_id, error['message']),
126132
expected=True)

0 commit comments

Comments
 (0)