1
1
# -*- coding: utf-8 -*-
2
- ''' Implements the main InputStream Helper class '''
2
+ """ Implements the main InputStream Helper class"""
3
3
from __future__ import absolute_import , division , unicode_literals
4
4
import os
5
5
from inputstreamhelper import config
13
13
14
14
15
15
class InputStreamException (Exception ):
16
- ''' Stub Exception '''
16
+ """ Stub Exception"""
17
17
18
18
19
19
def system_os ():
20
- ''' Get system platform, and remember this information '''
20
+ """ Get system platform, and remember this information"""
21
21
22
22
# If it wasn't stored before, get the correct value
23
23
if not hasattr (system_os , 'name' ):
@@ -33,10 +33,10 @@ def system_os():
33
33
34
34
35
35
class Helper :
36
- ''' The main InputStream Helper class '''
36
+ """ The main InputStream Helper class"""
37
37
38
38
def __init__ (self , protocol , drm = None ):
39
- ''' Initialize InputStream Helper class '''
39
+ """ Initialize InputStream Helper class"""
40
40
self ._download_path = None
41
41
self ._loop_dev = None
42
42
self ._modprobe_loop = False
@@ -69,7 +69,7 @@ def __init__(self, protocol, drm=None):
69
69
install_opener (build_opener (ProxyHandler (proxies )))
70
70
71
71
def __repr__ (self ):
72
- ''' String representation of Helper class '''
72
+ """ String representation of Helper class"""
73
73
return 'Helper({protocol}, drm={drm})' .format (protocol = self .protocol , drm = self .drm )
74
74
75
75
@classmethod
@@ -80,7 +80,7 @@ def _diskspace(cls):
80
80
81
81
@classmethod
82
82
def _temp_path (cls ):
83
- ''' Return temporary path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp '''
83
+ """ Return temporary path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp"""
84
84
from xbmcvfs import exists , mkdirs
85
85
temp_path = translate_path (os .path .join (get_setting ('temp_path' , 'special://masterprofile/addon_data/script.module.inputstreamhelper' ), 'temp' ))
86
86
if not exists (temp_path ):
@@ -90,7 +90,7 @@ def _temp_path(cls):
90
90
91
91
@classmethod
92
92
def _mnt_path (cls ):
93
- ''' Return mount path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp/mnt '''
93
+ """ Return mount path, usually ~/.kodi/userdata/addon_data/script.module.inputstreamhelper/temp/mnt"""
94
94
from xbmcvfs import exists , mkdir
95
95
mnt_path = os .path .join (cls ._temp_path (), 'mnt' )
96
96
if not exists (mnt_path ):
@@ -100,7 +100,7 @@ def _mnt_path(cls):
100
100
101
101
@classmethod
102
102
def _ia_cdm_path (cls ):
103
- ''' Return the specified CDM path for inputstream.adaptive, usually ~/.kodi/cdm '''
103
+ """ Return the specified CDM path for inputstream.adaptive, usually ~/.kodi/cdm"""
104
104
from xbmcaddon import Addon
105
105
try :
106
106
addon = Addon ('inputstream.adaptive' )
@@ -116,7 +116,7 @@ def _ia_cdm_path(cls):
116
116
117
117
@classmethod
118
118
def _backup_path (cls ):
119
- ''' Return the path to the cdm backups '''
119
+ """ Return the path to the cdm backups"""
120
120
from xbmcvfs import exists , mkdir
121
121
path = os .path .join (addon_profile (), 'backup' )
122
122
if not exists (path ):
@@ -125,36 +125,37 @@ def _backup_path(cls):
125
125
126
126
@classmethod
127
127
def _widevine_config_path (cls ):
128
- ''' Return the full path to the widevine or recovery config file '''
128
+ """ Return the full path to the widevine or recovery config file"""
129
129
if 'x86' in cls ._arch ():
130
130
return os .path .join (cls ._ia_cdm_path (), config .WIDEVINE_CONFIG_NAME )
131
131
return os .path .join (cls ._ia_cdm_path (), os .path .basename (config .CHROMEOS_RECOVERY_URL ) + '.json' )
132
132
133
133
@classmethod
134
134
def _load_widevine_config (cls ):
135
- ''' Load the widevine or recovery config in JSON format '''
135
+ """ Load the widevine or recovery config in JSON format"""
136
136
from json import loads
137
137
with open (cls ._widevine_config_path (), 'r' ) as config_file :
138
138
return loads (config_file .read ())
139
139
140
140
@classmethod
141
141
def _widevine_path (cls ):
142
- ''' Get full widevine path '''
142
+ """ Get full widevine path"""
143
143
widevine_cdm_filename = config .WIDEVINE_CDM_FILENAME [system_os ()]
144
144
if widevine_cdm_filename is None :
145
145
return False
146
146
147
147
if cls ._ia_cdm_path ():
148
148
widevine_path = os .path .join (cls ._ia_cdm_path (), widevine_cdm_filename )
149
149
from xbmcvfs import exists
150
+
150
151
if exists (widevine_path ):
151
152
return widevine_path
152
153
153
154
return False
154
155
155
156
@classmethod
156
157
def _kodi_version (cls ):
157
- ''' Return the current Kodi version '''
158
+ """ Return the current Kodi version"""
158
159
from xbmc import getInfoLabel
159
160
version = getInfoLabel ('System.BuildVersion' )
160
161
return version .split (' ' )[0 ]
@@ -224,18 +225,18 @@ def _helper_disabled(self):
224
225
225
226
@staticmethod
226
227
def disable ():
227
- ''' Disable plugin '''
228
+ """ Disable plugin"""
228
229
if get_setting ('disabled' , 'false' ) == 'false' :
229
230
set_setting ('disabled' , 'true' )
230
231
231
232
@staticmethod
232
233
def enable ():
233
- ''' Enable plugin '''
234
+ """ Enable plugin"""
234
235
if get_setting ('disabled' , 'false' ) == 'true' :
235
236
set_setting ('disabled' , 'false' )
236
237
237
238
def _inputstream_version (self ):
238
- ''' Return the requested inputstream version '''
239
+ """ Return the requested inputstream version"""
239
240
from xbmcaddon import Addon
240
241
try :
241
242
addon = Addon (self .inputstream_addon )
@@ -277,7 +278,7 @@ def _chromeos_offset(self, bin_path):
277
278
return '0'
278
279
279
280
def _run_cmd (self , cmd , sudo = False , shell = False ):
280
- ''' Run subprocess command and return if it succeeds as a bool '''
281
+ """ Run subprocess command and return if it succeeds as a bool"""
281
282
from .unicodehelper import to_unicode
282
283
import subprocess
283
284
env = os .environ .copy ()
@@ -364,7 +365,7 @@ def _has_widevine(self):
364
365
365
366
@staticmethod
366
367
def _http_request (url ):
367
- ''' Perform an HTTP request and return request '''
368
+ """ Perform an HTTP request and return request"""
368
369
369
370
try : # Python 3
370
371
from urllib .error import HTTPError
@@ -386,7 +387,7 @@ def _http_request(url):
386
387
return req
387
388
388
389
def _http_get (self , url ):
389
- ''' Perform an HTTP GET request and return content '''
390
+ """ Perform an HTTP GET request and return content"""
390
391
req = self ._http_request (url )
391
392
if req is None :
392
393
return None
@@ -552,7 +553,7 @@ def _latest_widevine_version(self, eula=False):
552
553
return arm_device ['version' ]
553
554
554
555
def _chromeos_config (self ):
555
- ''' Parse the Chrome OS recovery configuration and put it in a dictionary '''
556
+ """ Parse the Chrome OS recovery configuration and put it in a dictionary"""
556
557
url = config .CHROMEOS_RECOVERY_URL
557
558
conf = [line for line in self ._http_get (url ).split ('\n \n ' ) if 'hwidmatch=' in line ]
558
559
@@ -759,7 +760,7 @@ def _install_widevine_arm(self): # pylint: disable=too-many-statements
759
760
return False
760
761
761
762
def install_widevine (self ):
762
- ''' Wrapper function that calls Widevine installer method depending on architecture '''
763
+ """ Wrapper function that calls Widevine installer method depending on architecture"""
763
764
if not self ._supports_widevine ():
764
765
return False
765
766
@@ -849,7 +850,7 @@ def _widevine_eula(self):
849
850
return yesno_dialog (localize (30026 ), eula , nolabel = localize (30028 ), yeslabel = localize (30027 )) # Widevine CDM EULA
850
851
851
852
def _extract_widevine_from_img (self , backup_path ):
852
- ''' Extract the Widevine CDM binary from the mounted Chrome OS image '''
853
+ """ Extract the Widevine CDM binary from the mounted Chrome OS image"""
853
854
from shutil import copyfile
854
855
from xbmcvfs import exists , mkdir
855
856
@@ -930,7 +931,7 @@ def _check_widevine(self):
930
931
return True
931
932
932
933
def _unzip (self , unzip_dir , file_to_unzip = None , result = []): # pylint: disable=dangerous-default-value
933
- ''' Unzip files to specified path '''
934
+ """ Unzip files to specified path"""
934
935
from xbmcvfs import exists , mkdirs
935
936
936
937
if not exists (unzip_dir ):
@@ -954,15 +955,15 @@ def _unzip(self, unzip_dir, file_to_unzip=None, result=[]): # pylint: disable=d
954
955
return bool (result )
955
956
956
957
def _unmount (self ):
957
- ''' Unmount mountpoint if mounted '''
958
+ """ Unmount mountpoint if mounted"""
958
959
while os .path .ismount (self ._mnt_path ()):
959
960
log ('Unmount {mountpoint}' , mountpoint = self ._mnt_path ())
960
961
umount_output = self ._run_cmd (['umount' , self ._mnt_path ()], sudo = True )
961
962
if not umount_output ['success' ]:
962
963
break
963
964
964
965
def _cleanup (self ):
965
- ''' Clean up function after Widevine CDM installation '''
966
+ """ Clean up function after Widevine CDM installation"""
966
967
from shutil import rmtree
967
968
self ._unmount ()
968
969
if self ._attached_loop_dev :
0 commit comments