6
6
import os
7
7
8
8
from . import config
9
- from .kodiutils import (addon_version , get_proxies , get_setting , get_setting_bool , get_setting_float , get_setting_int , jsonrpc ,
9
+ from .kodiutils import (addon_version , delete , exists , get_proxies , get_setting , get_setting_bool , get_setting_float , get_setting_int , jsonrpc ,
10
10
kodi_to_ascii , kodi_version , localize , log , notification , ok_dialog , progress_dialog , select_dialog ,
11
11
set_setting , set_setting_bool , textviewer , translate_path , yesno_dialog )
12
12
from .utils import arch , http_download , run_cmd , store , system_os , temp_path , unzip
13
13
from .widevine .arm import install_widevine_arm , select_best_chromeos_image , unmount
14
- from .widevine .widevine import (backup_path , has_widevine , ia_cdm_path , install_cdm_from_backup , latest_widevine_version ,
15
- load_widevine_config , missing_widevine_libs , widevine_config_path , widevine_eula , widevine_path )
14
+ from .widevine .widevine import (backup_path , has_widevinecdm , ia_cdm_path , install_cdm_from_backup , latest_widevine_version ,
15
+ load_widevine_config , missing_widevine_libs , widevine_config_path , widevine_eula , widevinecdm_path )
16
16
17
17
# NOTE: Work around issue caused by platform still using os.popen()
18
18
# This helps to survive 'IOError: [Errno 10] No child processes'
@@ -46,7 +46,7 @@ def __init__(self, protocol, drm=None):
46
46
self .drm = drm
47
47
48
48
from platform import uname
49
- log ('Platform information: {uname}' , uname = uname ())
49
+ log (0 , 'Platform information: {uname}' , uname = uname ())
50
50
51
51
if self .protocol not in config .INPUTSTREAM_PROTOCOLS :
52
52
raise InputStreamException ('UnsupportedProtocol' )
@@ -97,7 +97,7 @@ def _inputstream_version(self):
97
97
98
98
@staticmethod
99
99
def _get_lib_version (path ):
100
- if not path :
100
+ if not path or not exists ( path ) :
101
101
return '(Not found)'
102
102
import re
103
103
with open (path , 'rb' ) as library :
@@ -111,20 +111,20 @@ def _has_inputstream(self):
111
111
"""Checks if selected InputStream add-on is installed."""
112
112
data = jsonrpc (method = 'Addons.GetAddonDetails' , params = dict (addonid = self .inputstream_addon ))
113
113
if 'error' in data :
114
- log ('{addon} is not installed.' , addon = self .inputstream_addon )
114
+ log (3 , '{addon} is not installed.' , addon = self .inputstream_addon )
115
115
return False
116
116
117
- log ('{addon} is installed.' , addon = self .inputstream_addon )
117
+ log (0 , '{addon} is installed.' , addon = self .inputstream_addon )
118
118
return True
119
119
120
120
def _inputstream_enabled (self ):
121
121
"""Returns whether selected InputStream add-on is enabled.."""
122
122
data = jsonrpc (method = 'Addons.GetAddonDetails' , params = dict (addonid = self .inputstream_addon , properties = ['enabled' ]))
123
123
if data .get ('result' , {}).get ('addon' , {}).get ('enabled' ):
124
- log ('{addon} {version} is enabled.' , addon = self .inputstream_addon , version = self ._inputstream_version ())
124
+ log (0 , '{addon} {version} is enabled.' , addon = self .inputstream_addon , version = self ._inputstream_version ())
125
125
return True
126
126
127
- log ('{addon} is disabled.' , addon = self .inputstream_addon )
127
+ log (3 , '{addon} is disabled.' , addon = self .inputstream_addon )
128
128
return False
129
129
130
130
def _enable_inputstream (self ):
@@ -138,23 +138,23 @@ def _enable_inputstream(self):
138
138
def _supports_widevine ():
139
139
"""Checks if Widevine is supported on the architecture/operating system/Kodi version."""
140
140
if arch () not in config .WIDEVINE_SUPPORTED_ARCHS :
141
- log ('Unsupported Widevine architecture found: {arch}' , arch = arch ())
141
+ log (4 , 'Unsupported Widevine architecture found: {arch}' , arch = arch ())
142
142
ok_dialog (localize (30004 ), localize (30007 , arch = arch ())) # Widevine not available on this architecture
143
143
return False
144
144
145
145
if system_os () not in config .WIDEVINE_SUPPORTED_OS :
146
- log ('Unsupported Widevine OS found: {os}' , os = system_os ())
146
+ log (4 , 'Unsupported Widevine OS found: {os}' , os = system_os ())
147
147
ok_dialog (localize (30004 ), localize (30011 , os = system_os ())) # Operating system not supported by Widevine
148
148
return False
149
149
150
150
from distutils .version import LooseVersion # pylint: disable=import-error,no-name-in-module,useless-suppression
151
151
if LooseVersion (config .WIDEVINE_MINIMUM_KODI_VERSION [system_os ()]) > LooseVersion (kodi_version ()):
152
- log ('Unsupported Kodi version for Widevine: {version}' , version = kodi_version ())
152
+ log (4 , 'Unsupported Kodi version for Widevine: {version}' , version = kodi_version ())
153
153
ok_dialog (localize (30004 ), localize (30010 , version = config .WIDEVINE_MINIMUM_KODI_VERSION [system_os ()])) # Kodi too old
154
154
return False
155
155
156
156
if 'WindowsApps' in translate_path ('special://xbmcbin/' ): # uwp is not supported
157
- log ('Unsupported UWP Kodi version detected.' )
157
+ log (4 , 'Unsupported UWP Kodi version detected.' )
158
158
ok_dialog (localize (30004 ), localize (30012 )) # Windows Store Kodi falls short
159
159
return False
160
160
@@ -190,7 +190,7 @@ def install_and_finish(self, progress, version):
190
190
install_cdm_from_backup (version )
191
191
192
192
progress .update (98 , message = localize (30050 )) # Finishing
193
- if has_widevine ():
193
+ if has_widevinecdm ():
194
194
wv_check = self ._check_widevine ()
195
195
if wv_check :
196
196
progress .update (100 , message = localize (30051 )) # Widevine CDM successfully installed.
@@ -229,10 +229,9 @@ def install_widevine(self):
229
229
@staticmethod
230
230
def remove_widevine ():
231
231
"""Removes Widevine CDM"""
232
- from xbmcvfs import delete , exists
233
- widevinecdm = widevine_path ()
234
- if widevinecdm and exists (widevinecdm ):
235
- log ('Remove Widevine CDM at {path}' , path = widevinecdm )
232
+ if has_widevinecdm ():
233
+ widevinecdm = widevinecdm_path ()
234
+ log (0 , 'Removed Widevine CDM at {path}' , path = widevinecdm )
236
235
delete (widevinecdm )
237
236
notification (localize (30037 ), localize (30052 )) # Success! Widevine successfully removed.
238
237
return True
@@ -251,7 +250,7 @@ def _first_run():
251
250
if LooseVersion (addon_version ()) > LooseVersion (settings_version ):
252
251
# New version found, save addon_version to settings
253
252
set_setting ('version' , addon_version ())
254
- log ('inputstreamhelper version {version} is running for the first time' , version = addon_version ())
253
+ log (2 , 'InputStreamHelper version {version} is running for the first time' , version = addon_version ())
255
254
return True
256
255
return False
257
256
@@ -263,7 +262,7 @@ def _update_widevine(self):
263
262
if last_update and not self ._first_run ():
264
263
last_update_dt = datetime .fromtimestamp (get_setting_float ('last_update' , 0.0 ))
265
264
if last_update_dt + timedelta (days = get_setting_int ('update_frequency' , 14 )) >= datetime .utcnow ():
266
- log ('Widevine update check was made on {date}' , date = last_update_dt .isoformat ())
265
+ log (2 , 'Widevine update check was made on {date}' , date = last_update_dt .isoformat ())
267
266
return
268
267
269
268
wv_config = load_widevine_config ()
@@ -274,35 +273,35 @@ def _update_widevine(self):
274
273
else :
275
274
component = 'Chrome OS'
276
275
current_version = select_best_chromeos_image (wv_config )['version' ]
277
- log ('Latest {component} version is {version}' , component = component , version = latest_version )
278
- log ('Current {component} version installed is {version}' , component = component , version = current_version )
276
+ log (0 , 'Latest {component} version is {version}' , component = component , version = latest_version )
277
+ log (0 , 'Current {component} version installed is {version}' , component = component , version = current_version )
279
278
280
279
from distutils .version import LooseVersion # pylint: disable=import-error,no-name-in-module,useless-suppression
281
280
if LooseVersion (latest_version ) > LooseVersion (current_version ):
282
- log ('There is an update available for {component}' , component = component )
281
+ log (2 , 'There is an update available for {component}' , component = component )
283
282
if yesno_dialog (localize (30040 ), localize (30033 ), nolabel = localize (30028 ), yeslabel = localize (30034 )):
284
283
self .install_widevine ()
285
284
else :
286
- log ('User declined to update {component}.' , component = component )
285
+ log (3 , 'User declined to update {component}.' , component = component )
287
286
else :
288
287
from time import mktime
289
288
set_setting ('last_update' , mktime (datetime .utcnow ().timetuple ()))
290
- log ('User is on the latest available {component} version.' , component = component )
289
+ log (0 , 'User is on the latest available {component} version.' , component = component )
291
290
292
291
def _check_widevine (self ):
293
292
"""Checks that all Widevine components are installed and available."""
294
293
if system_os () == 'Android' : # no checks needed for Android
295
294
return True
296
295
297
- if not os . path . exists (widevine_config_path ()):
298
- log ('Widevine or Chrome OS recovery.conf is missing. Reinstall is required.' )
296
+ if not exists (widevine_config_path ()):
297
+ log (4 , 'Widevine or Chrome OS recovery.conf is missing. Reinstall is required.' )
299
298
ok_dialog (localize (30001 ), localize (30031 )) # An update of Widevine is required
300
299
return self .install_widevine ()
301
300
302
301
if 'x86' in arch (): # check that widevine arch matches system arch
303
302
wv_config = load_widevine_config ()
304
303
if config .WIDEVINE_ARCH_MAP_X86 [arch ()] != wv_config ['arch' ]:
305
- log ('Widevine/system arch mismatch. Reinstall is required.' )
304
+ log (4 , 'Widevine/system arch mismatch. Reinstall is required.' )
306
305
ok_dialog (localize (30001 ), localize (30031 )) # An update of Widevine is required
307
306
return self .install_widevine ()
308
307
@@ -326,7 +325,7 @@ def cleanup():
326
325
store ('attached_loop_dev' , False )
327
326
if store ('modprobe_loop' ):
328
327
notification (localize (30035 ), localize (30036 )) # Unload by hand in CLI
329
- if not has_widevine ():
328
+ if not has_widevinecdm ():
330
329
rmtree (ia_cdm_path ())
331
330
332
331
rmtree (temp_path ())
@@ -338,7 +337,7 @@ def _supports_hls(self):
338
337
if LooseVersion (self ._inputstream_version ()) >= LooseVersion (config .HLS_MINIMUM_IA_VERSION ):
339
338
return True
340
339
341
- log ('HLS is unsupported on {addon} version {version}' , addon = self .inputstream_addon , version = self ._inputstream_version ())
340
+ log (3 , 'HLS is unsupported on {addon} version {version}' , addon = self .inputstream_addon , version = self ._inputstream_version ())
342
341
return False
343
342
344
343
def _check_drm (self ):
@@ -349,7 +348,7 @@ def _check_drm(self):
349
348
if self .drm != 'widevine' :
350
349
return True
351
350
352
- if has_widevine ():
351
+ if has_widevinecdm ():
353
352
return self ._check_widevine ()
354
353
355
354
if yesno_dialog (localize (30041 ), localize (30002 ), nolabel = localize (30028 ), yeslabel = localize (30038 )): # Widevine required
@@ -368,16 +367,16 @@ def _install_inputstream(self):
368
367
# Check if InputStream add-on exists!
369
368
Addon ('{}' .format (self .inputstream_addon ))
370
369
371
- log ('inputstream addon installed from repo.' )
370
+ log (0 , 'InputStream add-on installed from repo.' )
372
371
return True
373
372
except RuntimeError :
374
- log ('inputstream addon not installed.' )
373
+ log (3 , 'InputStream add-on not installed.' )
375
374
return False
376
375
377
376
def check_inputstream (self ):
378
377
"""Main function. Ensures that all components are available for InputStream add-on playback."""
379
378
if get_setting_bool ('disabled' , False ): # blindly return True if helper has been disabled
380
- log ('inputstreamhelper is disabled in its settings.xml.' )
379
+ log (3 , 'InputStreamHelper is disabled in its settings.xml.' )
381
380
return True
382
381
if self .drm == 'widevine' and not self ._supports_widevine ():
383
382
return False
@@ -391,7 +390,7 @@ def check_inputstream(self):
391
390
if not ret :
392
391
return False
393
392
self ._enable_inputstream ()
394
- log ('{addon} {version} is installed and enabled.' , addon = self .inputstream_addon , version = self ._inputstream_version ())
393
+ log (0 , '{addon} {version} is installed and enabled.' , addon = self .inputstream_addon , version = self ._inputstream_version ())
395
394
396
395
if self .protocol == 'hls' and not self ._supports_hls ():
397
396
ok_dialog (localize (30004 ), # HLS Minimum version is needed
@@ -415,13 +414,13 @@ def info_dialog(self):
415
414
text += ' - ' + localize (30812 , version = self ._inputstream_version (), state = istream_state ) + '\n '
416
415
text += '\n '
417
416
418
- text += ' - ' + localize (30820 ) + '\n ' # Widevine information
417
+ text += localize (30820 ) + '\n ' # Widevine information
419
418
if system_os () == 'Android' :
420
419
text += ' - ' + localize (30821 ) + '\n '
421
420
else :
422
421
from datetime import datetime
423
422
wv_updated = datetime .fromtimestamp (get_setting_float ('last_update' , 0.0 )).strftime ("%Y-%m-%d %H:%M" ) if get_setting_float ('last_update' , 0.0 ) else 'Never'
424
- text += ' - ' + localize (30822 , version = self ._get_lib_version (widevine_path ()), date = wv_updated ) + '\n '
423
+ text += ' - ' + localize (30822 , version = self ._get_lib_version (widevinecdm_path ()), date = wv_updated ) + '\n '
425
424
text += ' - ' + localize (30823 , path = ia_cdm_path ()) + '\n '
426
425
427
426
if arch () in ('arm' , 'arm64' ): # Chrome OS version
@@ -431,7 +430,7 @@ def info_dialog(self):
431
430
432
431
text += localize (30830 , url = config .ISSUE_URL ) # Report issues
433
432
434
- log ('\n {info}' .format (info = kodi_to_ascii (text )), level = 2 )
433
+ log (2 , '\n {info}' .format (info = kodi_to_ascii (text )))
435
434
textviewer (localize (30901 ), text )
436
435
437
436
def rollback_libwv (self ):
@@ -440,7 +439,7 @@ def rollback_libwv(self):
440
439
versions = os .listdir (bpath )
441
440
442
441
# Return if Widevine is not installed
443
- if not os . path . exists (widevine_config_path ()):
442
+ if not exists (widevine_config_path ()):
444
443
notification (localize (30004 ), localize (30041 ))
445
444
return
446
445
@@ -465,7 +464,7 @@ def rollback_libwv(self):
465
464
466
465
version = select_dialog (localize (30057 ), show_versions )
467
466
if version != - 1 :
468
- log ('Rollback to version {version}' , version = versions [version ])
467
+ log (0 , 'Rollback to version {version}' , version = versions [version ])
469
468
install_cdm_from_backup (versions [version ])
470
469
notification (localize (30037 ), localize (30051 )) # Success! Widevine successfully installed.
471
470
0 commit comments