Skip to content

Commit 1583ba5

Browse files
committed
Reorganize structure
1 parent cf694e8 commit 1583ba5

File tree

2 files changed

+56
-47
lines changed

2 files changed

+56
-47
lines changed

lib/inputstreamhelper/__init__.py

+55-46
Original file line numberDiff line numberDiff line change
@@ -136,42 +136,48 @@ def _load_widevine_config(cls):
136136
return loads(config_file.read())
137137

138138
@classmethod
139-
def _has_vendor_widevine(cls):
140-
"""Whether the system has a vendor-supplied widevine CDM"""
141-
widevine_cdm_filename = config.WIDEVINE_CDM_FILENAME[system_os()]
142-
if widevine_cdm_filename is None:
143-
return False
144-
145-
widevine_path = os.path.join(cls._ia_cdm_path(), widevine_cdm_filename)
146-
vendor_widevine_path = '{0}_vendor{1}'.format(*os.path.splitext(widevine_path))
147-
if exists(vendor_widevine_path):
148-
return True
139+
def _widevinecdm_path(cls):
140+
"""Get full widevine path"""
141+
widevinecdm_filename = config.WIDEVINE_CDM_FILENAME[system_os()]
142+
if widevinecdm_filename is None:
143+
return None
144+
if cls._ia_cdm_path() is None:
145+
return None
146+
return os.path.join(cls._ia_cdm_path(), widevinecdm_filename)
149147

150-
return False
148+
@classmethod
149+
def _vendor_widevinecdm_path(cls):
150+
widevinecdm_path = cls._widevinecdm_path()
151+
return '{0}_vendor{1}'.format(*os.path.splitext(widevinecdm_path))
151152

152153
@classmethod
153-
def _widevine_path(cls):
154-
"""Get full widevine path"""
155-
widevine_cdm_filename = config.WIDEVINE_CDM_FILENAME[system_os()]
156-
if widevine_cdm_filename is None:
154+
def _has_widevinecdm(cls):
155+
"""Whether the system has a widevine CDM"""
156+
widevinecdm_path = cls._widevinecdm_path()
157+
if widevinecdm_path is None:
157158
return False
159+
if not exists(widevinecdm_path):
160+
return False
161+
return True
158162

159-
if cls._ia_cdm_path():
160-
widevine_path = os.path.join(cls._ia_cdm_path(), widevine_cdm_filename)
161-
162-
# Support vendor-supplied Widevine CDM
163-
vendor_widevine_path = '{0}_vendor{1}'.format(*os.path.splitext(widevine_path))
164-
if exists(vendor_widevine_path):
165-
if exists(widevine_path):
166-
if not samefile(vendor_widevine_path, widevine_path):
167-
hardlink(vendor_widevine_path, widevine_path)
168-
else:
169-
hardlink(vendor_widevine_path, widevine_path)
170-
171-
if exists(widevine_path):
172-
return widevine_path
163+
@classmethod
164+
def _has_vendor_widevinecdm(cls):
165+
"""Whether the system has a vendor-supplied widevine CDM"""
166+
vendor_widevinecdm_path = cls._vendor_widevinecdm_path()
167+
if not exists(vendor_widevinecdm_path):
168+
return False
169+
return True
173170

174-
return False
171+
@classmethod
172+
def _hardlink_vendor_widevinecdm(cls):
173+
"""Hardlink vendor Widevine into place"""
174+
vendor_widevinecdm_path = cls._vendor_widevinecdm_path()
175+
if not exists(vendor_widevinecdm_path):
176+
return
177+
widevinecdm_path = cls._widevinecdm_path()
178+
if exists(widevinecdm_path) and samefile(vendor_widevinecdm_path, widevinecdm_path):
179+
return
180+
hardlink(vendor_widevinecdm_path, widevinecdm_path)
175181

176182
@classmethod
177183
def _kodi_version(cls):
@@ -268,7 +274,7 @@ def _inputstream_version(self):
268274

269275
@staticmethod
270276
def _get_lib_version(path):
271-
if not path:
277+
if not path or not exists(path):
272278
return '(Not found)'
273279
import re
274280
with open(path, 'rb') as library:
@@ -373,11 +379,13 @@ def _mnt_loop_dev(self):
373379

374380
def _has_widevine(self):
375381
"""Checks if Widevine CDM is installed on system."""
376-
if system_os() == 'Android': # widevine is built in on android
382+
if system_os() == 'Android': # Widevine is built into Android
377383
return True
378384

379-
if self._widevine_path():
380-
log(0, 'Found Widevine binary at {path}', path=self._widevine_path())
385+
self._hardlink_vendor_widevinecdm() # If vendor Widevine is present, hardlink into place
386+
387+
if self._has_widevinecdm():
388+
log(0, 'Found Widevine binary at {path}', path=self._widevinecdm_path())
381389
return True
382390

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

783791
def remove_widevine(self):
784792
"""Removes Widevine CDM"""
785-
widevinecdm = self._widevine_path()
786-
if widevinecdm and exists(widevinecdm):
787-
log(0, 'Remove Widevine CDM at {path}', path=widevinecdm)
788-
delete(widevinecdm)
793+
if self._has_widevinecdm():
794+
widevinecdm_path = self._widevinecdm_path()
795+
log(0, 'Remove Widevine CDM at {path}', path=widevinecdm_path)
796+
delete(widevinecdm_path)
789797
notification(localize(30037), localize(30052)) # Success! Widevine successfully removed.
790798
return True
791799
notification(localize(30004), localize(30053)) # Error. Widevine CDM not found.
@@ -881,12 +889,13 @@ def _missing_widevine_libs(self):
881889
return None
882890

883891
if self._cmd_exists('ldd'):
884-
if not os.access(self._widevine_path(), os.X_OK):
885-
log(0, 'Changing {path} permissions to 744.', path=self._widevine_path())
886-
os.chmod(self._widevine_path(), 0o744)
892+
widevinecdm_path = self._widevinecdm_path()
893+
if not os.access(widevinecdm_path, os.X_OK):
894+
log(0, 'Changing {path} permissions to 744.', path=widevinecdm_path)
895+
os.chmod(widevinecdm_path, 0o744)
887896

888897
missing_libs = []
889-
cmd = ['ldd', self._widevine_path()]
898+
cmd = ['ldd', widevinecdm_path]
890899
output = self._run_cmd(cmd, sudo=False)
891900
if output['success']:
892901
for line in output['output'].splitlines():
@@ -919,7 +928,7 @@ def _check_widevine(self):
919928
if system_os() == 'Android': # no checks needed for Android
920929
return True
921930

922-
if self._has_vendor_widevine(): # no checks needed for vendor-supplied Widevine
931+
if self._has_vendor_widevinecdm(): # no checks needed for vendor-supplied Widevine
923932
return True
924933

925934
if not os.path.exists(self._widevine_config_path()):
@@ -1073,12 +1082,12 @@ def info_dialog(self):
10731082
text += localize(30820) + '\n' # Widevine information
10741083
if system_os() == 'Android':
10751084
text += ' - ' + localize(30821) + '\n'
1076-
elif self._has_vendor_widevine():
1077-
text += ' - ' + localize(30822, version=self._get_lib_version(self._widevine_path())) + '\n'
1085+
elif self._has_vendor_widevinecdm():
1086+
text += ' - ' + localize(30822, version=self._get_lib_version(self._widevinecdm_path())) + '\n'
10781087
else:
10791088
from datetime import datetime
10801089
wv_updated = datetime.fromtimestamp(float(get_setting('last_update'))).strftime("%Y-%m-%d %H:%M") if get_setting('last_update') else 'Never'
1081-
text += ' - ' + localize(30823, version=self._get_lib_version(self._widevine_path()), date=wv_updated) + '\n'
1090+
text += ' - ' + localize(30823, version=self._get_lib_version(self._widevinecdm_path()), date=wv_updated) + '\n'
10821091
text += ' - ' + localize(30824, path=self._ia_cdm_path()) + '\n'
10831092

10841093
if self._arch() in ('arm', 'arm64'): # Chrome OS version

lib/inputstreamhelper/kodiutils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from xbmcaddon import Addon
88
from .unicodehelper import from_unicode, to_unicode
99

10-
ADDON = Addon()
10+
ADDON = Addon('script.module.inputstreamhelper')
1111

1212

1313
class SafeDict(dict):

0 commit comments

Comments
 (0)