Skip to content

Commit 7dc9d3a

Browse files
Parse chromeos devices into list of dictionaries
1 parent 9fae3d4 commit 7dc9d3a

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

lib/inputstreamhelper.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,22 @@ def _current_widevine_cdm_version(self):
288288
return self._http_request()
289289

290290
def _parse_chromeos_recovery_conf(self):
291-
"""Parse the download URL and required disk space from the Chrome OS recovery configuration."""
292-
download_dict = {}
291+
"""Parse the Chrome OS recovery configuration and put it in a dictionary."""
292+
devices = []
293293
self._url = config.CHROMEOS_RECOVERY_CONF
294-
conf = self._http_request().split('\n\n')
295-
devices = [x for x in conf if 'name=' in x]
296-
for device in devices:
297-
if config.CHROMEOS_ARM_HWID in device.split('\nhwidmatch=')[1].split('\n')[0]:
298-
for line in device.splitlines():
299-
if 'url' in line:
300-
download_dict['url'] = line.split('url=')[1]
301-
if 'zipfilesize' in line:
302-
zip_filesize = int(line.split('filesize=')[1])
303-
if 'zip' not in line and 'filesize' in line:
304-
bin_filesize = int(line.split('filesize=')[1])
305-
306-
download_dict['required_diskspace'] = zip_filesize + bin_filesize
307-
return download_dict
308-
309-
self._log('Failed to parse Chrome OS recovery.conf')
310-
return False
294+
conf = [x for x in self._http_request().split('\n\n') if 'name=' in x]
295+
for device in conf:
296+
device_dict = {}
297+
for device_info in device.splitlines():
298+
key_value = device_info.split('=')
299+
key = key_value[0]
300+
if len(key_value) > 1: # some keys have empty values
301+
value = key_value[1]
302+
device_dict[key] = value
303+
devices.append(device_dict)
304+
305+
self._log('chromeos devices: {0}'.format(devices))
306+
return devices
311307

312308
def _install_widevine_cdm_x86(self):
313309
dialog = xbmcgui.Dialog()
@@ -340,15 +336,16 @@ def _install_widevine_cdm_x86(self):
340336
return False
341337

342338
def _install_widevine_cdm_arm(self):
339+
arm_device = [x for x in self._parse_chromeos_recovery_conf() if config.CHROMEOS_ARM_HWID in x['hwidmatch']][0]
340+
required_diskspace = int(arm_device['filesize']) + int(arm_device['zipfilesize'])
343341
dialog = xbmcgui.Dialog()
344-
download_dict = self._parse_chromeos_recovery_conf()
345-
if dialog.yesno(self._language(30001), self._language(30002)) and dialog.yesno(self._language(30001), self._language(30006).format(self.sizeof_fmt(download_dict['required_diskspace']))) and self._widevine_eula():
342+
if dialog.yesno(self._language(30001), self._language(30002)) and dialog.yesno(self._language(30001), self._language(30006).format(self.sizeof_fmt(required_diskspace))) and self._widevine_eula():
346343
if self._os != 'Linux':
347344
dialog.ok(self._language(30004), self._language(30019).format(self._os))
348345
return False
349-
if download_dict['required_diskspace'] >= self._diskspace():
346+
if required_diskspace >= self._diskspace():
350347
dialog.ok(self._language(30004),
351-
self._language(30018).format(self.sizeof_fmt(download_dict['diskspace'])))
348+
self._language(30018).format(self.sizeof_fmt(required_diskspace)))
352349
return False
353350
if not self._cmd_exists('fdisk') and not self._cmd_exists('parted'):
354351
dialog.ok(self._language(30004), self._language(30020).format('fdisk', 'parted'))
@@ -360,7 +357,7 @@ def _install_widevine_cdm_arm(self):
360357
dialog.ok(self._language(30004), self._language(30021).format('losetup'))
361358
return False
362359

363-
self._url = download_dict['url']
360+
self._url = arm_device['url']
364361
downloaded = self._http_request(download=True, message=self._language(30022))
365362
if downloaded:
366363
dialog.ok(self._language(30023), self._language(30024))

0 commit comments

Comments
 (0)