mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-08-20 22:41:35 +00:00
Most flake8 warnings corrected
This commit is contained in:
parent
e92d60f7c7
commit
00765c0a12
58 changed files with 1144 additions and 1262 deletions
|
@ -22,16 +22,19 @@ from dateutil import tz, parser
|
|||
|
||||
#################################################################################################
|
||||
|
||||
LOG = logging.getLogger("JELLYFIN."+__name__)
|
||||
LOG = logging.getLogger("JELLYFIN." + __name__)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
def addon_id():
|
||||
return "plugin.video.jellyfin"
|
||||
|
||||
|
||||
def kodi_version():
|
||||
return xbmc.getInfoLabel('System.BuildVersion')[:2]
|
||||
|
||||
|
||||
def window(key, value=None, clear=False, window_id=10000):
|
||||
|
||||
''' Get or set window properties.
|
||||
|
@ -65,6 +68,7 @@ def window(key, value=None, clear=False, window_id=10000):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
def settings(setting, value=None):
|
||||
|
||||
''' Get or add add-on settings.
|
||||
|
@ -87,9 +91,11 @@ def settings(setting, value=None):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
def create_id():
|
||||
return uuid4()
|
||||
|
||||
|
||||
def compare_version(a, b):
|
||||
|
||||
''' -1 a is smaller
|
||||
|
@ -107,6 +113,7 @@ def compare_version(a, b):
|
|||
|
||||
return 0
|
||||
|
||||
|
||||
def find(dict, item):
|
||||
|
||||
''' Find value in dictionary.
|
||||
|
@ -114,11 +121,12 @@ def find(dict, item):
|
|||
if item in dict:
|
||||
return dict[item]
|
||||
|
||||
for key,value in sorted(dict.iteritems(), key=lambda (k,v): (v,k)):
|
||||
for key, value in sorted(dict.iteritems(), key=lambda (k, v): (v, k)):
|
||||
|
||||
if re.match(key, item, re.I):
|
||||
return dict[key]
|
||||
|
||||
|
||||
def event(method, data=None, sender=None, hexlify=False):
|
||||
|
||||
''' Data is a dictionary.
|
||||
|
@ -134,13 +142,16 @@ def event(method, data=None, sender=None, hexlify=False):
|
|||
xbmc.executebuiltin('NotifyAll(%s, %s, %s)' % (sender, method, data))
|
||||
LOG.debug("---[ event: %s/%s ] %s", sender, method, data)
|
||||
|
||||
|
||||
def dialog(dialog_type, *args, **kwargs):
|
||||
|
||||
d = xbmcgui.Dialog()
|
||||
|
||||
if "icon" in kwargs:
|
||||
kwargs['icon'] = kwargs['icon'].replace("{jellyfin}",
|
||||
"special://home/addons/plugin.video.jellyfin/resources/icon.png")
|
||||
kwargs['icon'] = kwargs['icon'].replace(
|
||||
"{jellyfin}",
|
||||
"special://home/addons/plugin.video.jellyfin/resources/icon.png"
|
||||
)
|
||||
if "heading" in kwargs:
|
||||
kwargs['heading'] = kwargs['heading'].replace("{jellyfin}", _('addon_name'))
|
||||
|
||||
|
@ -155,6 +166,7 @@ def dialog(dialog_type, *args, **kwargs):
|
|||
}
|
||||
return types[dialog_type](*args, **kwargs)
|
||||
|
||||
|
||||
def should_stop():
|
||||
|
||||
''' Checkpoint during the sync process.
|
||||
|
@ -171,6 +183,7 @@ def should_stop():
|
|||
|
||||
return False
|
||||
|
||||
|
||||
def get_screensaver():
|
||||
|
||||
''' Get the current screensaver value.
|
||||
|
@ -181,6 +194,7 @@ def get_screensaver():
|
|||
except KeyError:
|
||||
return ""
|
||||
|
||||
|
||||
def set_screensaver(value):
|
||||
|
||||
''' Toggle the screensaver
|
||||
|
@ -192,6 +206,7 @@ def set_screensaver(value):
|
|||
result = JSONRPC('Settings.setSettingValue').execute(params)
|
||||
LOG.info("---[ screensaver/%s ] %s", value, result)
|
||||
|
||||
|
||||
class JSONRPC(object):
|
||||
|
||||
version = 1
|
||||
|
@ -221,6 +236,7 @@ class JSONRPC(object):
|
|||
self.params = params
|
||||
return json.loads(xbmc.executeJSONRPC(self._query()))
|
||||
|
||||
|
||||
def validate(path):
|
||||
|
||||
''' Verify if path is accessible.
|
||||
|
@ -241,6 +257,7 @@ def validate(path):
|
|||
|
||||
return True
|
||||
|
||||
|
||||
def values(item, keys):
|
||||
|
||||
''' Grab the values in the item for a list of keys {key},{key1}....
|
||||
|
@ -248,6 +265,7 @@ def values(item, keys):
|
|||
'''
|
||||
return (item[key.replace('{', "").replace('}', "")] if type(key) == str and key.startswith('{') else key for key in keys)
|
||||
|
||||
|
||||
def indent(elem, level=0):
|
||||
|
||||
''' Prettify xml docs.
|
||||
|
@ -256,20 +274,21 @@ def indent(elem, level=0):
|
|||
i = "\n" + level * " "
|
||||
if len(elem):
|
||||
if not elem.text or not elem.text.strip():
|
||||
elem.text = i + " "
|
||||
elem.text = i + " "
|
||||
if not elem.tail or not elem.tail.strip():
|
||||
elem.tail = i
|
||||
elem.tail = i
|
||||
for elem in elem:
|
||||
indent(elem, level + 1)
|
||||
indent(elem, level + 1)
|
||||
if not elem.tail or not elem.tail.strip():
|
||||
elem.tail = i
|
||||
elem.tail = i
|
||||
else:
|
||||
if level and (not elem.tail or not elem.tail.strip()):
|
||||
elem.tail = i
|
||||
elem.tail = i
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
return
|
||||
|
||||
|
||||
def write_xml(content, file):
|
||||
with open(file, 'w') as infile:
|
||||
|
||||
|
@ -332,6 +351,7 @@ def unzip(path, dest, folder=None):
|
|||
|
||||
LOG.info("Unzipped %s", path)
|
||||
|
||||
|
||||
def unzip_recursive(path, dirs, dest):
|
||||
|
||||
for directory in dirs:
|
||||
|
@ -348,6 +368,7 @@ def unzip_recursive(path, dirs, dest):
|
|||
for file in files:
|
||||
unzip_file(os.path.join(dirs_dir, file.decode('utf-8')), os.path.join(dest_dir, file.decode('utf-8')))
|
||||
|
||||
|
||||
def unzip_file(path, dest):
|
||||
|
||||
''' Unzip specific file. Path should start with zip://
|
||||
|
@ -355,6 +376,7 @@ def unzip_file(path, dest):
|
|||
xbmcvfs.copy(path, dest)
|
||||
LOG.debug("unzip: %s to %s", path, dest)
|
||||
|
||||
|
||||
def get_zip_directory(path, folder):
|
||||
|
||||
dirs, files = xbmcvfs.listdir(path)
|
||||
|
@ -367,6 +389,7 @@ def get_zip_directory(path, folder):
|
|||
if result:
|
||||
return result
|
||||
|
||||
|
||||
def copytree(path, dest):
|
||||
|
||||
''' Copy folder content from one to another.
|
||||
|
@ -384,6 +407,7 @@ def copytree(path, dest):
|
|||
|
||||
LOG.info("Copied %s", path)
|
||||
|
||||
|
||||
def copy_recursive(path, dirs, dest):
|
||||
|
||||
for directory in dirs:
|
||||
|
@ -400,6 +424,7 @@ def copy_recursive(path, dirs, dest):
|
|||
for file in files:
|
||||
copy_file(os.path.join(dirs_dir, file.decode('utf-8')), os.path.join(dest_dir, file.decode('utf-8')))
|
||||
|
||||
|
||||
def copy_file(path, dest):
|
||||
|
||||
''' Copy specific file.
|
||||
|
@ -410,6 +435,7 @@ def copy_file(path, dest):
|
|||
xbmcvfs.copy(path, dest)
|
||||
LOG.debug("copy: %s to %s", path, dest)
|
||||
|
||||
|
||||
def normalize_string(text):
|
||||
|
||||
''' For theme media, do not modify unless modified in TV Tunes.
|
||||
|
@ -431,11 +457,13 @@ def normalize_string(text):
|
|||
|
||||
return text
|
||||
|
||||
|
||||
def split_list(itemlist, size):
|
||||
|
||||
''' Split up list in pieces of size. Will generate a list of lists
|
||||
'''
|
||||
return [itemlist[i:i+size] for i in range(0, len(itemlist), size)]
|
||||
return [itemlist[i:i + size] for i in range(0, len(itemlist), size)]
|
||||
|
||||
|
||||
def convert_to_local(date):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue