Skip to content

Commit bec1859

Browse files
Minor fixes
1 parent 00458f9 commit bec1859

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

lib/inputstreamhelper.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ def __init__(self, protocol, drm=None):
2222
self._log('Platform information: {0}'.format(platform.uname()))
2323

2424
self.protocol = protocol
25+
self.drm = drm
2526
if self.protocol not in config.INPUTSTREAM_PROTOCOLS:
2627
raise self.InputStreamException('UnsupportedProtocol')
2728
else:
2829
self._inputstream_addon = config.INPUTSTREAM_PROTOCOLS[self.protocol]
29-
if not drm or drm not in config.DRM_SCHEMES:
30-
raise self.InputStreamException('UnsupportedDRMScheme')
31-
else:
32-
self.drm = config.DRM_SCHEMES[drm]
30+
if self.drm:
31+
if self.drm not in config.DRM_SCHEMES:
32+
raise self.InputStreamException('UnsupportedDRMScheme')
33+
else:
34+
self.drm = config.DRM_SCHEMES[drm]
3335

3436
class InputStreamException(Exception):
3537
pass
@@ -103,7 +105,7 @@ def _http_request(self, url, download=False, download_path=None):
103105
for chunk in req.iter_content(chunk_size=1024):
104106
f.write(chunk)
105107
dl += len(chunk)
106-
percent = int(dl * 100/ total_length)
108+
percent = int(dl * 100 / total_length)
107109
if progress_dialog.iscanceled():
108110
progress_dialog.close()
109111
req.close()
@@ -114,7 +116,6 @@ def _http_request(self, url, download=False, download_path=None):
114116
else:
115117
return req.content
116118

117-
118119
def _has_inputstream(self):
119120
"""Checks if selected InputStream add-on is installed."""
120121
payload = {
@@ -191,7 +192,8 @@ def _install_widevine_cdm(self):
191192
dialog = xbmcgui.Dialog()
192193
download_path = os.path.join(xbmc.translatePath('special://temp'), 'widevine_cdm.zip')
193194
cdm_platform = config.WIDEVINE_DOWNLOAD_MAP[self._arch][self._os]
194-
cdm_source = json.loads(self._http_request(config.WIDEVINE_CDM_SOURCE))['vendors']['gmp-widevinecdm']['platforms']
195+
cdm_source = json.loads(self._http_request(config.WIDEVINE_CDM_SOURCE))['vendors']['gmp-widevinecdm'][
196+
'platforms']
195197
cdm_zip_url = cdm_source[cdm_platform]['fileUrl']
196198

197199
downloaded = self._http_request(cdm_zip_url, download=True, download_path=download_path)
@@ -218,36 +220,46 @@ def _unzip_widevine_cdm(self, zip_path):
218220
dialog.ok(self._language(30004), self._language(30016))
219221
return False
220222

221-
def check_for_widevine(self):
222-
if not self._supports_widevine():
223-
return False
224-
if not self._has_widevine_cdm():
225-
dialog = xbmcgui.Dialog()
226-
ok = dialog.yesno(self._language(30001), self._language(30002))
227-
if ok:
228-
return self._install_widevine_cdm()
229-
else:
230-
return False
223+
def check_for_drm(self):
224+
if self.drm:
225+
if self.drm == 'widevine':
226+
if not self._supports_widevine():
227+
return False
228+
if not self._has_widevine_cdm():
229+
dialog = xbmcgui.Dialog()
230+
ok = dialog.yesno(self._language(30001), self._language(30002))
231+
if ok:
232+
return self._install_widevine_cdm()
233+
else:
234+
return False
235+
else:
236+
return True
231237
else:
238+
self._log('No DRM has been specified.')
232239
return True
233240

234241
def check_for_inputstream(self):
235-
"""Ensures that selected InputStream add-on is installed and enabled.
236-
Displays a select dialog if add-on is installed but not enabled."""
242+
"""Ensures that selected InputStream add-on is installed, enabled and
243+
that specified DRM system is installed."""
237244
dialog = xbmcgui.Dialog()
238245
if not self._has_inputstream():
239246
self._log('{0} is not installed.'.format(self._inputstream_addon))
240247
dialog.ok(self._language(30004), self._language(30008).format(self._inputstream_addon))
248+
return False
241249
elif not self._inputstream_enabled():
242250
self._log('{0} is not enabled.'.format(self._inputstream_addon))
243-
ok = dialog.yesno(self._language(30001), self._language(30009).format(self._inputstream_addon, self._inputstream_addon))
251+
ok = dialog.yesno(self._language(30001),
252+
self._language(30009).format(self._inputstream_addon, self._inputstream_addon))
244253
if ok:
245-
return self._enable_inputstream()
254+
if not self._enable_inputstream():
255+
return False
246256
else:
247257
return False
258+
elif self.protocol == 'hls':
259+
return self.supports_hls()
248260
else:
249261
self._log('{0} is installed and enabled.'.format(self._inputstream_addon))
250-
return True
262+
return self.check_for_drm()
251263

252264
def supports_hls(self):
253265
if self.protocol == 'hls' and LooseVersion(self._inputstream_version()) >= LooseVersion(config.HLS_MINIMUM_IA_VERSION):

0 commit comments

Comments
 (0)