Skip to content

Commit

Permalink
Reorganize structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed Dec 24, 2019
1 parent cf694e8 commit 0364556
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
99 changes: 54 additions & 45 deletions lib/inputstreamhelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,42 +136,48 @@ def _load_widevine_config(cls):
return loads(config_file.read())

@classmethod
def _has_vendor_widevine(cls):
"""Whether the system has a vendor-supplied widevine CDM"""
widevine_cdm_filename = config.WIDEVINE_CDM_FILENAME[system_os()]
if widevine_cdm_filename is None:
return False

widevine_path = os.path.join(cls._ia_cdm_path(), widevine_cdm_filename)
vendor_widevine_path = '{0}_vendor{1}'.format(*os.path.splitext(widevine_path))
if exists(vendor_widevine_path):
return True
def _widevinecdm_path(cls):
"""Get full widevine path"""
widevinecdm_filename = config.WIDEVINE_CDM_FILENAME[system_os()]
if widevinecdm_filename is None:
return None
if cls._ia_cdm_path() is None:
return None
return os.path.join(cls._ia_cdm_path(), widevinecdm_filename)

return False
@classmethod
def _vendor_widevinecdm_path(cls):
widevinecdm_path = cls._widevinecdm_path()
return '{0}_vendor{1}'.format(*os.path.splitext(widevinecdm_path))

@classmethod
def _widevine_path(cls):
"""Get full widevine path"""
widevine_cdm_filename = config.WIDEVINE_CDM_FILENAME[system_os()]
if widevine_cdm_filename is None:
def _has_widevinecdm(cls):
"""Whether the system has a widevine CDM"""
widevinecdm_path = cls._widevinecdm_path()
if widevinecdm_path is None:
return False
if not exists(widevinecdm_path):
return False
return True

if cls._ia_cdm_path():
widevine_path = os.path.join(cls._ia_cdm_path(), widevine_cdm_filename)

# Support vendor-supplied Widevine CDM
vendor_widevine_path = '{0}_vendor{1}'.format(*os.path.splitext(widevine_path))
if exists(vendor_widevine_path):
if exists(widevine_path):
if not samefile(vendor_widevine_path, widevine_path):
hardlink(vendor_widevine_path, widevine_path)
else:
hardlink(vendor_widevine_path, widevine_path)

if exists(widevine_path):
return widevine_path
@classmethod
def _has_vendor_widevinecdm(cls):
"""Whether the system has a vendor-supplied widevine CDM"""
vendor_widevinecdm_path = cls._vendor_widevinecdm_path()
if not exists(vendor_widevinecdm_path):
return False
return True

return False
@classmethod
def _hardlink_vendor_widevinecdm(cls):
"""Hardlink vendor Widevine into place"""
vendor_widevinecdm_path = cls._vendor_widevinecdm_path()
if not exists(vendor_widevinecdm_path):
return
widevinecdm_path = cls._widevinecdm_path()
if exists(widevinecdm_path) and samefile(vendor_widevinecdm_path, widevinecdm_path):
return
hardlink(vendor_widevinecdm_path, widevinecdm_path)

@classmethod
def _kodi_version(cls):
Expand Down Expand Up @@ -373,11 +379,13 @@ def _mnt_loop_dev(self):

def _has_widevine(self):
"""Checks if Widevine CDM is installed on system."""
if system_os() == 'Android': # widevine is built in on android
if system_os() == 'Android': # Widevine is built into Android
return True

if self._widevine_path():
log(0, 'Found Widevine binary at {path}', path=self._widevine_path())
self._hardlink_vendor_widevinecdm() # If vendor Widevine is present, hardlink into place

if self._has_widevinecdm():
log(0, 'Found Widevine binary at {path}', path=self._widevinecdm_path())
return True

log(3, 'Widevine is not installed.')
Expand Down Expand Up @@ -782,10 +790,10 @@ def install_widevine(self):

def remove_widevine(self):
"""Removes Widevine CDM"""
widevinecdm = self._widevine_path()
if widevinecdm and exists(widevinecdm):
log(0, 'Remove Widevine CDM at {path}', path=widevinecdm)
delete(widevinecdm)
if self._has_widevinecdm():
widevinecdm_path = self._widevinecdm_path()
log(0, 'Remove Widevine CDM at {path}', path=widevinecdm_path)
delete(widevinecdm_path)
notification(localize(30037), localize(30052)) # Success! Widevine successfully removed.
return True
notification(localize(30004), localize(30053)) # Error. Widevine CDM not found.
Expand Down Expand Up @@ -881,12 +889,13 @@ def _missing_widevine_libs(self):
return None

if self._cmd_exists('ldd'):
if not os.access(self._widevine_path(), os.X_OK):
log(0, 'Changing {path} permissions to 744.', path=self._widevine_path())
os.chmod(self._widevine_path(), 0o744)
widevinecdm_path = self._widevinecdm_path()
if not os.access(widevinecdm_path, os.X_OK):
log(0, 'Changing {path} permissions to 744.', path=widevinecdm_path)
os.chmod(widevinecdm_path, 0o744)

missing_libs = []
cmd = ['ldd', self._widevine_path()]
cmd = ['ldd', widevinecdm_path]
output = self._run_cmd(cmd, sudo=False)
if output['success']:
for line in output['output'].splitlines():
Expand Down Expand Up @@ -919,7 +928,7 @@ def _check_widevine(self):
if system_os() == 'Android': # no checks needed for Android
return True

if self._has_vendor_widevine(): # no checks needed for vendor-supplied Widevine
if self._has_vendor_widevinecdm(): # no checks needed for vendor-supplied Widevine
return True

if not os.path.exists(self._widevine_config_path()):
Expand Down Expand Up @@ -1073,12 +1082,12 @@ def info_dialog(self):
text += localize(30820) + '\n' # Widevine information
if system_os() == 'Android':
text += ' - ' + localize(30821) + '\n'
elif self._has_vendor_widevine():
text += ' - ' + localize(30822, version=self._get_lib_version(self._widevine_path())) + '\n'
elif self._has_vendor_widevinecdm():
text += ' - ' + localize(30822, version=self._get_lib_version(self._widevinecdm_path())) + '\n'
else:
from datetime import datetime
wv_updated = datetime.fromtimestamp(float(get_setting('last_update'))).strftime("%Y-%m-%d %H:%M") if get_setting('last_update') else 'Never'
text += ' - ' + localize(30823, version=self._get_lib_version(self._widevine_path()), date=wv_updated) + '\n'
text += ' - ' + localize(30823, version=self._get_lib_version(self._widevinecdm_path()), date=wv_updated) + '\n'
text += ' - ' + localize(30824, path=self._ia_cdm_path()) + '\n'

if self._arch() in ('arm', 'arm64'): # Chrome OS version
Expand Down
2 changes: 1 addition & 1 deletion lib/inputstreamhelper/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from xbmcaddon import Addon
from .unicodehelper import from_unicode, to_unicode

ADDON = Addon()
ADDON = Addon('script.module.inputstreamhelper')


class SafeDict(dict):
Expand Down

0 comments on commit 0364556

Please sign in to comment.