Skip to content

Commit 9cbbf46

Browse files
Docstrings, cosmetics
1 parent 1f9ea06 commit 9cbbf46

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lib/inputstreamhelper.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class InputStreamException(Exception):
4848

4949
@staticmethod
5050
def sizeof_fmt(num, suffix='B'):
51+
"""Return size of file in a human readable string."""
5152
# https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
5253
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
5354
if abs(num) < 1024.0:
@@ -57,10 +58,12 @@ def sizeof_fmt(num, suffix='B'):
5758

5859
@staticmethod
5960
def _cmd_exists(cmd):
61+
"""Check whether cmd exists on system."""
6062
# https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
6163
return subprocess.call('type ' + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
6264

6365
def _arch(self):
66+
"""Map together and return the system architecture."""
6467
arch = platform.machine()
6568
if arch in config.X86_MAP:
6669
return config.X86_MAP[arch]
@@ -71,11 +74,13 @@ def _arch(self):
7174
return arch
7275

7376
def _log(self, string):
77+
"""InputStream Helper log method."""
7478
logging_prefix = '[{0}-{1}]'.format(self._addon.getAddonInfo('id'), self._addon.getAddonInfo('version'))
7579
msg = '{0}: {1}'.format(logging_prefix, string)
7680
xbmc.log(msg=msg, level=xbmc.LOGDEBUG)
7781

7882
def _diskspace(self):
83+
"""Return the free disk space available (in bytes) in cdm_path."""
7984
statvfs = os.statvfs(self._cdm_path())
8085
return statvfs.f_frsize * statvfs.f_bavail
8186

@@ -139,7 +144,7 @@ def _parse_chromeos_offset(self, bin_path):
139144

140145
def _run_cmd(self, cmd):
141146
try:
142-
output = subprocess.check_output(cmd)
147+
subprocess.check_output(cmd)
143148
self._log('{0} cmd executed successfully.'.format(cmd))
144149
return True
145150
except subprocess.CalledProcessError, error:
@@ -172,8 +177,6 @@ def _mnt_loop_dev(self):
172177
cmd.insert(0, 'sudo')
173178
else:
174179
self._log('User refused to give sudo permission.')
175-
else:
176-
self._log('User do not have root permissions and/or sudo installed.')
177180

178181
success = self._run_cmd(cmd)
179182
if success:
@@ -183,19 +186,20 @@ def _mnt_loop_dev(self):
183186
return False
184187

185188
def _has_widevine_cdm(self):
189+
"""Checks if Widevine CDM is installed on system."""
186190
if xbmc.getCondVisibility('system.platform.android'): # widevine is built in on android
187191
return True
188192
else:
189193
for filename in os.listdir(self._ia_cdm_path()):
190194
if 'widevine' in filename and filename.endswith(config.CDM_EXTENSIONS):
191-
self._log(
192-
'Found Widevine binary at {0}'.format(os.path.join(self._ia_cdm_path(), filename)))
195+
self._log('Found Widevine binary at {0}'.format(os.path.join(self._ia_cdm_path(), filename)))
193196
return True
194197

195198
self._log('Widevine is not installed.')
196199
return False
197200

198201
def _json_rpc_request(self, payload):
202+
"""Kodi JSON-RPC request. Return the response in a dictionary."""
199203
self._log('jsonrpc payload: {0}'.format(payload))
200204
response = xbmc.executeJSONRPC(json.dumps(payload))
201205
self._log('jsonrpc response: {0}'.format(response))
@@ -290,6 +294,7 @@ def _enable_inputstream(self):
290294
return True
291295

292296
def _supports_widevine(self):
297+
"""Check if Widevine is supported on the architecture/operating system/Kodi version."""
293298
dialog = xbmcgui.Dialog()
294299
if xbmc.getCondVisibility('system.platform.android'):
295300
min_version = config.WIDEVINE_ANDROID_MINIMUM_KODI_VERSION
@@ -339,6 +344,7 @@ def _parse_chromeos_recovery_conf(self):
339344
return devices
340345

341346
def _install_widevine_cdm_x86(self):
347+
"""Install Widevine CDM on x86 based architectures."""
342348
dialog = xbmcgui.Dialog()
343349
if dialog.yesno(self._language(30001), self._language(30002)):
344350
cdm_version = self._current_widevine_cdm_version()
@@ -369,6 +375,7 @@ def _install_widevine_cdm_x86(self):
369375
return False
370376

371377
def _install_widevine_cdm_arm(self):
378+
"""Install Widevine CDM on ARM-based architectures."""
372379
arm_device = [x for x in self._parse_chromeos_recovery_conf() if config.CHROMEOS_ARM_HWID in x['hwidmatch']][0]
373380
required_diskspace = int(arm_device['filesize']) + int(arm_device['zipfilesize'])
374381
dialog = xbmcgui.Dialog()
@@ -403,7 +410,7 @@ def _install_widevine_cdm_arm(self):
403410
self._cleanup()
404411
busy_dialog.close()
405412
else:
406-
self._extract_cdm_from_img()
413+
self._extract_widevine_cdm_from_img()
407414
self._install_cdm()
408415
self._cleanup()
409416
if self._has_widevine_cdm():
@@ -417,7 +424,7 @@ def _install_widevine_cdm_arm(self):
417424
return False
418425

419426
def _widevine_eula(self):
420-
"""Displays the Widevine EULA."""
427+
"""Display the Widevine EULA and prompt user to accept it."""
421428
if os.path.exists(os.path.join(self._cdm_path(), config.WIDEVINE_LICENSE_FILE)):
422429
license_file = os.path.join(self._cdm_path(), config.WIDEVINE_LICENSE_FILE)
423430
with open(license_file, 'r') as f:
@@ -435,7 +442,7 @@ def _widevine_eula(self):
435442
dialog = xbmcgui.Dialog()
436443
return dialog.yesno(self._language(30026), eula, yeslabel=self._language(30027), nolabel=self._language(30028))
437444

438-
def _extract_cdm_from_img(self):
445+
def _extract_widevine_cdm_from_img(self):
439446
"""Extract the Widevine CDM binary from the mounted Chrome OS image."""
440447
for root, dirs, files in os.walk(self._mnt_path()):
441448
for filename in files:
@@ -450,9 +457,10 @@ def _install_cdm(self):
450457
"""Loop through local cdm folder and symlink/copy binaries to inputstream cdm_path."""
451458
for cdm_file in os.listdir(self._cdm_path()):
452459
if cdm_file.endswith(config.CDM_EXTENSIONS):
460+
self._log('[install_cdm] found file: {0}'.format(cdm_file))
453461
cdm_path_addon = os.path.join(self._cdm_path(), cdm_file)
454462
cdm_path_inputstream = os.path.join(self._ia_cdm_path(), cdm_file)
455-
if self._os == 'Windows': # don't symlink on Windows
463+
if self._os == 'Windows': # copy on windows
456464
shutil.copyfile(cdm_path_addon, cdm_path_inputstream)
457465
else:
458466
os.symlink(cdm_path_addon, cdm_path_inputstream)
@@ -491,11 +499,11 @@ def _cleanup(self):
491499
return True
492500

493501
def _supports_hls(self):
502+
"""Return if HLS support is available in inputstream.adaptive."""
494503
if LooseVersion(self._inputstream_version()) >= LooseVersion(config.HLS_MINIMUM_IA_VERSION):
495504
return True
496505
else:
497-
self._log(
498-
'HLS is not supported on {0} version {1}'.format(self._inputstream_addon, self._inputstream_version()))
506+
self._log('HLS is unsupported on {0} version {1}'.format(self._inputstream_addon, self._inputstream_version()))
499507
dialog = xbmcgui.Dialog()
500508
dialog.ok(self._language(30004),
501509
self._language(30017).format(self._inputstream_addon, config.HLS_MINIMUM_IA_VERSION))

0 commit comments

Comments
 (0)