Skip to content

Commit cdb7b77

Browse files
Cleanup
1 parent a279400 commit cdb7b77

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lib/inputstreamhelper.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def __init__(self, protocol, drm=None):
2525

2626
self._url = None
2727
self._download_path = None
28-
self._bin_path = None
2928
self._mounted = False
3029
self._loop_dev = False
3130

@@ -116,12 +115,12 @@ def _inputstream_version(self):
116115
addon = xbmcaddon.Addon(self._inputstream_addon)
117116
return addon.getAddonInfo('version')
118117

119-
def _parse_chromeos_offset(self):
118+
def _parse_chromeos_offset(self, bin_path):
120119
"""Calculate the Chrome OS losetup start offset using fdisk/parted."""
121120
if self._cmd_exists('fdisk'):
122-
cmd = ['fdisk', self._bin_path, '-l']
121+
cmd = ['fdisk', bin_path, '-l']
123122
else: # parted
124-
cmd = ['parted', '-s', self._bin_path, 'unit s print']
123+
cmd = ['parted', '-s', bin_path, 'unit s print']
125124
self._log('losetup calculation cmd: {0}'.format(cmd))
126125

127126
output = subprocess.check_output(cmd)
@@ -136,9 +135,9 @@ def _parse_chromeos_offset(self):
136135
self._log('Failed to calculate losetup offset.')
137136
return False
138137

139-
def _losetup(self):
138+
def _losetup(self, bin_path):
140139
"""Setup Chrome OS loop device."""
141-
cmd = ['losetup', config.LOOP_DEV, self._bin_path, '-o', self._parse_chromeos_offset()]
140+
cmd = ['losetup', config.LOOP_DEV, bin_path, '-o', self._parse_chromeos_offset(bin_path)]
142141
subprocess.check_output(cmd)
143142
self._loop_dev = True
144143
return True
@@ -322,7 +321,7 @@ def _install_widevine_cdm_x86(self):
322321
if downloaded:
323322
busy_dialog = xbmcgui.DialogBusy()
324323
busy_dialog.create()
325-
self._unzip_cdm()
324+
self._unzip(self._cdm_path())
326325
if self._widevine_eula():
327326
self._install_cdm()
328327
else:
@@ -367,7 +366,10 @@ def _install_widevine_cdm_arm(self):
367366
dialog.ok(self._language(30023), self._language(30024))
368367
busy_dialog = xbmcgui.DialogBusy()
369368
busy_dialog.create()
370-
if not self._unzip_bin() or not self._losetup() or not self._mnt_loop_dev():
369+
370+
bin_filename = self._url.split('/')[-1].replace('.zip', '')
371+
bin_path = os.path.join(self._temp_path(), bin_filename)
372+
if not self._unzip(self._temp_path(), bin_filename) or not self._losetup(bin_path) or not self._mnt_loop_dev():
371373
self._cleanup()
372374
busy_dialog.close()
373375
return False
@@ -425,18 +427,18 @@ def _install_cdm(self):
425427

426428
return True
427429

428-
def _unzip_bin(self):
429-
zip_obj = zipfile.ZipFile(self._download_path)
430-
for filename in zip_obj.namelist():
431-
if filename.endswith('.bin'):
432-
zip_obj.extract(filename, self._temp_path())
433-
self._bin_path = os.path.join(self._temp_path(), filename)
434-
return True
435-
436-
def _unzip_cdm(self):
430+
def _unzip(self, unzip_dir, file_to_unzip=None):
431+
"""Unzip files to specified path."""
437432
zip_obj = zipfile.ZipFile(self._download_path)
438-
zip_obj.extractall(self._cdm_path())
439-
return True
433+
if file_to_unzip:
434+
for filename in zip_obj.namelist():
435+
if filename == file_to_unzip:
436+
zip_obj.extract(filename, unzip_dir)
437+
return True
438+
return False
439+
else: # extract all files
440+
zip_obj.extractall(unzip_dir)
441+
return True
440442

441443
def _cleanup(self):
442444
"""Clean up after Widevine DRM installation."""

0 commit comments

Comments
 (0)