22
22
23
23
import xbmc
24
24
from xbmcaddon import Addon
25
- from xbmcgui import Dialog , DialogProgress
26
25
import xbmcvfs
27
- from .kodiutils import execute_jsonrpc , get_addon_info , get_proxies , get_setting , localize , log , set_setting , translate_path
26
+ from .kodiutils import (browsesingle , execute_jsonrpc , get_addon_info , get_proxies , get_setting , localize , log ,
27
+ notification , ok_dialog , progress_dialog , set_setting , textviewer , translate_path , yesno_dialog )
28
28
from .unicodehelper import to_unicode
29
29
30
30
# NOTE: Work around issue caused by platform still using os.popen()
@@ -356,11 +356,11 @@ def _http_request(url):
356
356
raise HTTPError ('HTTP %s Error for url: %s' % (req .getcode (), url ), response = req )
357
357
break
358
358
except HTTPError :
359
- Dialog (). ok (localize (30004 ), localize (30013 , filename = filename )) # Failed to retrieve file
359
+ ok_dialog (localize (30004 ), localize (30013 , filename = filename )) # Failed to retrieve file
360
360
return None
361
361
except BadStatusLine :
362
362
if retry :
363
- Dialog (). ok (localize (30004 ), localize (30013 , filename = filename )) # Failed to retrieve file
363
+ ok_dialog (localize (30004 ), localize (30013 , filename = filename )) # Failed to retrieve file
364
364
return None
365
365
return req
366
366
@@ -387,8 +387,8 @@ def _http_download(self, url, message=None):
387
387
388
388
self ._download_path = os .path .join (self ._temp_path (), filename )
389
389
total_length = float (req .info ().get ('content-length' ))
390
- progress_dialog = DialogProgress ()
391
- progress_dialog .create (localize (30014 ), message ) # Download in progress
390
+ progress = progress_dialog ()
391
+ progress .create (localize (30014 ), message ) # Download in progress
392
392
393
393
chunk_size = 32 * 1024
394
394
with open (self ._download_path , 'wb' ) as image :
@@ -400,13 +400,13 @@ def _http_download(self, url, message=None):
400
400
image .write (chunk )
401
401
size += len (chunk )
402
402
percent = int (size * 100 / total_length )
403
- if progress_dialog .iscanceled ():
404
- progress_dialog .close ()
403
+ if progress .iscanceled ():
404
+ progress .close ()
405
405
req .close ()
406
406
return False
407
- progress_dialog .update (percent )
407
+ progress .update (percent )
408
408
409
- progress_dialog .close ()
409
+ progress .close ()
410
410
return True
411
411
412
412
def _has_inputstream (self ):
@@ -440,22 +440,22 @@ def _supports_widevine(self):
440
440
"""Checks if Widevine is supported on the architecture/operating system/Kodi version."""
441
441
if self ._arch () not in config .WIDEVINE_SUPPORTED_ARCHS :
442
442
log ('Unsupported Widevine architecture found: {arch}' , arch = self ._arch ())
443
- Dialog (). ok (localize (30004 ), localize (30007 )) # Widevine not available on this architecture
443
+ ok_dialog (localize (30004 ), localize (30007 )) # Widevine not available on this architecture
444
444
return False
445
445
446
446
if system_os () not in config .WIDEVINE_SUPPORTED_OS :
447
447
log ('Unsupported Widevine OS found: {os}' , os = system_os ())
448
- Dialog (). ok (localize (30004 ), localize (30011 , os = system_os ())) # Operating system not supported by Widevine
448
+ ok_dialog (localize (30004 ), localize (30011 , os = system_os ())) # Operating system not supported by Widevine
449
449
return False
450
450
451
451
if LooseVersion (config .WIDEVINE_MINIMUM_KODI_VERSION [system_os ()]) > LooseVersion (self ._kodi_version ()):
452
452
log ('Unsupported Kodi version for Widevine: {version}' , version = self ._kodi_version ())
453
- Dialog (). ok (localize (30004 ), localize (30010 , version = config .WIDEVINE_MINIMUM_KODI_VERSION [system_os ()])) # Kodi too old
453
+ ok_dialog (localize (30004 ), localize (30010 , version = config .WIDEVINE_MINIMUM_KODI_VERSION [system_os ()])) # Kodi too old
454
454
return False
455
455
456
456
if 'WindowsApps' in translate_path ('special://xbmcbin/' ): # uwp is not supported
457
457
log ('Unsupported UWP Kodi version detected.' )
458
- Dialog (). ok (localize (30004 ), localize (30012 )) # Windows Store Kodi falls short
458
+ ok_dialog (localize (30004 ), localize (30012 )) # Windows Store Kodi falls short
459
459
return False
460
460
461
461
return True
@@ -522,7 +522,7 @@ def _latest_widevine_version(self, eula=False):
522
522
arm_device = self ._select_best_chromeos_image (devices )
523
523
if arm_device is None :
524
524
log ('We could not find an ARM device in recovery.conf' )
525
- Dialog (). ok (localize (30004 ), localize (30005 ))
525
+ ok_dialog (localize (30004 ), localize (30005 ))
526
526
return ''
527
527
return arm_device ['version' ]
528
528
@@ -555,12 +555,12 @@ def _install_widevine_x86(self):
555
555
556
556
downloaded = self ._http_download (url )
557
557
if downloaded :
558
- progress_dialog = DialogProgress ()
559
- progress_dialog .create (heading = localize (30043 ), line1 = localize (30044 )) # Extracting Widevine CDM
560
- progress_dialog .update (94 , line1 = localize (30049 )) # Installing Widevine CDM
558
+ progress = progress_dialog ()
559
+ progress .create (heading = localize (30043 ), line1 = localize (30044 )) # Extracting Widevine CDM
560
+ progress .update (94 , line1 = localize (30049 )) # Installing Widevine CDM
561
561
self ._unzip (self ._ia_cdm_path ())
562
562
563
- progress_dialog .update (97 , line1 = localize (30050 )) # Finishing
563
+ progress .update (97 , line1 = localize (30050 )) # Finishing
564
564
self ._cleanup ()
565
565
if not self ._widevine_eula ():
566
566
return False
@@ -571,13 +571,13 @@ def _install_widevine_x86(self):
571
571
os .rename (os .path .join (self ._ia_cdm_path (), config .WIDEVINE_MANIFEST_FILE ), self ._widevine_config_path ())
572
572
wv_check = self ._check_widevine ()
573
573
if wv_check :
574
- progress_dialog .update (100 , line1 = localize (30051 )) # Widevine CDM successfully installed.
575
- Dialog (). notification (localize (30037 ), localize (30051 )) # Success! Widevine successfully installed.
576
- progress_dialog .close ()
574
+ progress .update (100 , line1 = localize (30051 )) # Widevine CDM successfully installed.
575
+ notification (localize (30037 ), localize (30051 )) # Success! Widevine successfully installed.
576
+ progress .close ()
577
577
return wv_check
578
578
579
- progress_dialog .close ()
580
- Dialog (). ok (localize (30004 ), localize (30005 )) # An error occurred
579
+ progress .close ()
580
+ ok_dialog (localize (30004 ), localize (30005 )) # An error occurred
581
581
582
582
return False
583
583
@@ -588,52 +588,54 @@ def _install_widevine_arm(self): # pylint: disable=too-many-statements
588
588
arm_device = self ._select_best_chromeos_image (devices )
589
589
if arm_device is None :
590
590
log ('We could not find an ARM device in recovery.conf' )
591
- Dialog (). ok (localize (30004 ), localize (30005 ))
591
+ ok_dialog (localize (30004 ), localize (30005 ))
592
592
return ''
593
593
required_diskspace = int (arm_device ['filesize' ]) + int (arm_device ['zipfilesize' ])
594
- if Dialog ().yesno (localize (30001 ), # Due to distributing issues, this takes a long time
595
- localize (30006 , diskspace = self ._sizeof_fmt (required_diskspace ))) and self ._widevine_eula ():
594
+ if yesno_dialog (localize (30001 ), # Due to distributing issues, this takes a long time
595
+ localize (30006 , diskspace = self ._sizeof_fmt (required_diskspace )),
596
+ autoanswer = True ) and self ._widevine_eula ():
596
597
if system_os () != 'Linux' :
597
- Dialog (). ok (localize (30004 ), localize (30019 , os = system_os ()))
598
+ ok_dialog (localize (30004 ), localize (30019 , os = system_os ()))
598
599
return False
599
600
600
601
while required_diskspace >= self ._diskspace ():
601
- if Dialog (). yesno (localize (30004 ), localize (30055 )): # Not enough space, alternative path?
602
- self ._update_temp_path (Dialog (). browseSingle (3 , localize (30909 ), 'files' )) # Temporary path
602
+ if yesno_dialog (localize (30004 ), localize (30055 )): # Not enough space, alternative path?
603
+ self ._update_temp_path (browsesingle (3 , localize (30909 ), 'files' )) # Temporary path
603
604
continue
604
605
605
- Dialog (). ok (localize (30004 ), # Not enough free disk space
606
- localize (30018 , diskspace = self ._sizeof_fmt (required_diskspace )))
606
+ ok_dialog (localize (30004 ), # Not enough free disk space
607
+ localize (30018 , diskspace = self ._sizeof_fmt (required_diskspace )))
607
608
return False
608
609
609
610
if not self ._cmd_exists ('fdisk' ) and not self ._cmd_exists ('parted' ):
610
- Dialog (). ok (localize (30004 ), localize (30020 , command1 = 'fdisk' , command2 = 'parted' )) # Commands are missing
611
+ ok_dialog (localize (30004 ), localize (30020 , command1 = 'fdisk' , command2 = 'parted' )) # Commands are missing
611
612
return False
612
613
613
614
if not self ._cmd_exists ('mount' ):
614
- Dialog (). ok (localize (30004 ), localize (30021 , command = 'mount' )) # Mount command is missing
615
+ ok_dialog (localize (30004 ), localize (30021 , command = 'mount' )) # Mount command is missing
615
616
return False
616
617
617
618
if not self ._cmd_exists ('losetup' ):
618
- Dialog (). ok (localize (30004 ), localize (30021 , command = 'losetup' )) # Losetup command is missing
619
+ ok_dialog (localize (30004 ), localize (30021 , command = 'losetup' )) # Losetup command is missing
619
620
return False
620
621
621
- if os .getuid () != 0 : # ask for permissions to run cmds as root
622
- if not Dialog ().yesno (localize (30001 ), localize (30030 , cmds = ', ' .join (root_cmds )), yeslabel = localize (30027 ), nolabel = localize (30028 )):
623
- return False
622
+ if os .getuid () != 0 and not yesno_dialog (localize (30001 ), # Ask for permission to run cmds as root
623
+ localize (30030 , cmds = ', ' .join (root_cmds )),
624
+ nolabel = localize (30028 ), yeslabel = localize (30027 ), autoanswer = True ):
625
+ return False
624
626
625
627
# Clean up any remaining mounts
626
628
self ._unmount ()
627
629
628
630
url = arm_device ['url' ]
629
631
downloaded = self ._http_download (url , message = localize (30022 )) # Downloading the recovery image
630
632
if downloaded :
631
- progress_dialog = DialogProgress ()
632
- progress_dialog .create (heading = localize (30043 ), line1 = localize (30044 )) # Extracting Widevine CDM
633
+ progress = progress_dialog ()
634
+ progress .create (heading = localize (30043 ), line1 = localize (30044 )) # Extracting Widevine CDM
633
635
bin_filename = url .split ('/' )[- 1 ].replace ('.zip' , '' )
634
636
bin_path = os .path .join (self ._temp_path (), bin_filename )
635
637
636
- progress_dialog .update (5 , line1 = localize (30045 ), line2 = localize (30046 ), line3 = localize (30047 )) # Uncompressing image
638
+ progress .update (5 , line1 = localize (30045 ), line2 = localize (30046 ), line3 = localize (30047 )) # Uncompressing image
637
639
success = [
638
640
self ._unzip (self ._temp_path (), bin_filename ),
639
641
self ._check_loop (),
@@ -642,27 +644,27 @@ def _install_widevine_arm(self): # pylint: disable=too-many-statements
642
644
self ._mnt_loop_dev (),
643
645
]
644
646
if all (success ):
645
- progress_dialog .update (91 , line1 = localize (30048 )) # Extracting Widevine CDM
647
+ progress .update (91 , line1 = localize (30048 )) # Extracting Widevine CDM
646
648
self ._extract_widevine_from_img ()
647
- progress_dialog .update (94 , line1 = localize (30049 )) # Installing Widevine CDM
648
- progress_dialog .update (97 , line1 = localize (30050 )) # Finishing
649
+ progress .update (94 , line1 = localize (30049 )) # Installing Widevine CDM
650
+ progress .update (97 , line1 = localize (30050 )) # Finishing
649
651
self ._cleanup ()
650
652
if self ._has_widevine ():
651
653
set_setting ('chromeos_version' , arm_device ['version' ])
652
654
with open (self ._widevine_config_path (), 'w' ) as config_file :
653
655
config_file .write (json .dumps (devices , indent = 4 ))
654
656
wv_check = self ._check_widevine ()
655
657
if wv_check :
656
- progress_dialog .update (100 , line1 = localize (30051 )) # Widevine CDM successfully installed.
657
- Dialog (). notification (localize (30037 ), localize (30051 )) # Success! Widevine CDM successfully installed.
658
- progress_dialog .close ()
658
+ progress .update (100 , line1 = localize (30051 )) # Widevine CDM successfully installed.
659
+ notification (localize (30037 ), localize (30051 )) # Success! Widevine CDM successfully installed.
660
+ progress .close ()
659
661
return wv_check
660
662
else :
661
- progress_dialog .update (100 , line1 = localize (30050 )) # Finishing
663
+ progress .update (100 , line1 = localize (30050 )) # Finishing
662
664
self ._cleanup ()
663
665
664
- progress_dialog .close ()
665
- Dialog (). ok (localize (30004 ), localize (30005 )) # An error occurred
666
+ progress .close ()
667
+ ok_dialog (localize (30004 ), localize (30005 )) # An error occurred
666
668
667
669
return False
668
670
@@ -682,9 +684,9 @@ def remove_widevine(self):
682
684
if widevinecdm and xbmcvfs .exists (widevinecdm ):
683
685
log ('Remove Widevine CDM at {path}' , path = widevinecdm )
684
686
xbmcvfs .delete (widevinecdm )
685
- Dialog (). notification (localize (30037 ), localize (30052 )) # Success! Widevine successfully removed.
687
+ notification (localize (30037 ), localize (30052 )) # Success! Widevine successfully removed.
686
688
return True
687
- Dialog (). notification (localize (30004 ), localize (30053 )) # Error. Widevine CDM not found.
689
+ notification (localize (30004 ), localize (30053 )) # Error. Widevine CDM not found.
688
690
return False
689
691
690
692
@staticmethod
@@ -725,7 +727,7 @@ def _update_widevine(self):
725
727
726
728
if LooseVersion (latest_version ) > LooseVersion (current_version ):
727
729
log ('There is an update available for {component}' , component = component )
728
- if Dialog (). yesno ( localize (30040 ), localize (30033 ), yeslabel = localize (30034 ), nolabel = localize (30028 ) ):
730
+ if yesno_dialog ( localize (30040 ), localize (30033 ), nolabel = localize (30028 ), yeslabel = localize (30034 ), autoanswer = True ):
729
731
self .install_widevine ()
730
732
else :
731
733
log ('User declined to update {component}.' , component = component )
@@ -750,7 +752,7 @@ def _widevine_eula(self):
750
752
with archive .open (config .WIDEVINE_LICENSE_FILE ) as file_obj :
751
753
eula = file_obj .read ().decode ().strip ().replace ('\n ' , ' ' )
752
754
753
- return Dialog (). yesno ( localize (30026 ), eula , yeslabel = localize (30027 ), nolabel = localize (30028 ) ) # Widevine CDM EULA
755
+ return yesno_dialog ( localize (30026 ), eula , nolabel = localize (30028 ), yeslabel = localize (30027 ), autoanswer = True ) # Widevine CDM EULA
754
756
755
757
def _extract_widevine_from_img (self ):
756
758
''' Extract the Widevine CDM binary from the mounted Chrome OS image '''
@@ -799,7 +801,7 @@ def _missing_widevine_libs(self):
799
801
import struct
800
802
if struct .calcsize ('P' ) * 8 == 64 :
801
803
log ('ARM64 ldd check failed. User needs 32-bit userspace.' )
802
- Dialog (). ok (localize (30004 ), localize (30039 )) # Widevine not available on ARM64
804
+ ok_dialog (localize (30004 ), localize (30039 )) # Widevine not available on ARM64
803
805
804
806
log ('Failed to check for missing Widevine libraries.' )
805
807
return None
@@ -811,18 +813,18 @@ def _check_widevine(self):
811
813
812
814
if not os .path .exists (self ._widevine_config_path ()):
813
815
log ('Widevine or recovery config is missing. Reinstall is required.' )
814
- Dialog (). ok (localize (30001 ), localize (30031 )) # An update of Widevine is required
816
+ ok_dialog (localize (30001 ), localize (30031 )) # An update of Widevine is required
815
817
return self .install_widevine ()
816
818
817
819
if 'x86' in self ._arch (): # check that widevine arch matches system arch
818
820
wv_config = self ._load_widevine_config ()
819
821
if config .WIDEVINE_ARCH_MAP_X86 [self ._arch ()] != wv_config ['arch' ]:
820
822
log ('Widevine/system arch mismatch. Reinstall is required.' )
821
- Dialog (). ok (localize (30001 ), localize (30031 )) # An update of Widevine is required
823
+ ok_dialog (localize (30001 ), localize (30031 )) # An update of Widevine is required
822
824
return self .install_widevine ()
823
825
824
826
if self ._missing_widevine_libs ():
825
- Dialog (). ok (localize (30004 ), localize (30032 , libs = ', ' .join (self ._missing_widevine_libs ()))) # Missing libraries
827
+ ok_dialog (localize (30004 ), localize (30032 , libs = ', ' .join (self ._missing_widevine_libs ()))) # Missing libraries
826
828
return False
827
829
828
830
self ._update_widevine ()
@@ -866,7 +868,7 @@ def _cleanup(self):
866
868
if unattach_output ['success' ]:
867
869
self ._loop_dev = False
868
870
if self ._modprobe_loop :
869
- Dialog (). notification (localize (30035 ), localize (30036 )) # Unload by hand in CLI
871
+ notification (localize (30035 ), localize (30036 )) # Unload by hand in CLI
870
872
if not self ._has_widevine ():
871
873
shutil .rmtree (self ._ia_cdm_path ())
872
874
@@ -892,7 +894,7 @@ def _check_drm(self):
892
894
if self ._has_widevine ():
893
895
return self ._check_widevine ()
894
896
895
- if Dialog (). yesno ( localize (30041 ), localize (30002 ), yeslabel = localize (30038 ), nolabel = localize (30028 ) ): # Widevine required
897
+ if yesno_dialog ( localize (30041 ), localize (30002 ), nolabel = localize (30028 ), yeslabel = localize (30038 ), autoanswer = True ): # Widevine required
896
898
return self .install_widevine ()
897
899
898
900
return False
@@ -921,18 +923,18 @@ def check_inputstream(self):
921
923
if not self ._has_inputstream ():
922
924
# Try to install InputStream add-on
923
925
if not self ._install_inputstream ():
924
- Dialog (). ok (localize (30004 ), localize (30008 , addon = self .inputstream_addon )) # inputstream is missing on system
926
+ ok_dialog (localize (30004 ), localize (30008 , addon = self .inputstream_addon )) # inputstream is missing on system
925
927
return False
926
928
elif not self ._inputstream_enabled ():
927
- ret = Dialog (). yesno (localize (30001 ), localize (30009 , addon = self .inputstream_addon )) # inputstream is disabled
929
+ ret = yesno_dialog (localize (30001 ), localize (30009 , addon = self .inputstream_addon )) # inputstream is disabled
928
930
if ret :
929
931
self ._enable_inputstream ()
930
932
return False
931
933
log ('{addon} {version} is installed and enabled.' , addon = self .inputstream_addon , version = self ._inputstream_version ())
932
934
933
935
if self .protocol == 'hls' and not self ._supports_hls ():
934
- Dialog (). ok (localize (30004 ), # HLS Minimum version is needed
935
- localize (30017 , addon = self .inputstream_addon , version = config .HLS_MINIMUM_IA_VERSION ))
936
+ ok_dialog (localize (30004 ), # HLS Minimum version is needed
937
+ localize (30017 , addon = self .inputstream_addon , version = config .HLS_MINIMUM_IA_VERSION ))
936
938
return False
937
939
938
940
return self ._check_drm ()
@@ -963,4 +965,4 @@ def info_dialog(self):
963
965
+ "\n - " .join (wv_info ) + "\n \n "
964
966
+ localize (30830 , url = config .ISSUE_URL ))
965
967
966
- Dialog (). textviewer (localize (30901 ), text )
968
+ textviewer (localize (30901 ), text )
0 commit comments