Most flake8 warnings corrected

This commit is contained in:
Odd Stråbø 2019-10-03 04:14:54 +02:00
commit 00765c0a12
58 changed files with 1144 additions and 1262 deletions

View file

@ -8,14 +8,14 @@ from . import settings
##################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__)
LOG = logging.getLogger("JELLYFIN." + __name__)
##################################################################################################
class API(object):
def __init__(self, item, server=None):
''' Get item information in special cases.
server is the server address, provide if your functions requires it.
'''
@ -225,7 +225,7 @@ class API(object):
return path
def get_user_artwork(self, user_id):
''' Get jellyfin user profile picture.
'''
return "%s/emby/Users/%s/Images/Primary?Format=original" % (self.server, user_id)
@ -286,7 +286,7 @@ class API(object):
if obj.get('SeriesTag'):
all_artwork['Series.Primary'] = self.get_artwork(obj['SeriesId'], "Primary", obj['SeriesTag'], query)
if not all_artwork['Primary']:
all_artwork['Primary'] = all_artwork['Series.Primary']

View file

@ -2,9 +2,8 @@
#################################################################################################
class LibraryException(Exception):
# Jellyfin library sync exception
def __init__(self, status):
self.status = status

View file

@ -20,7 +20,7 @@ from downloader import TheVoid
#################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__)
LOG = logging.getLogger("JELLYFIN." + __name__)
#################################################################################################
@ -52,8 +52,8 @@ def set_properties(item, method, server_id=None):
window('jellyfin_play.json', current)
class PlayUtils(object):
class PlayUtils(object):
def __init__(self, item, force_transcode=False, server_id=None, server=None, token=None):
@ -236,7 +236,7 @@ class PlayUtils(object):
def transcode(self, source, audio=None, subtitle=None):
if not 'TranscodingUrl' in source:
if 'TranscodingUrl' not in source:
raise Exception("use get_sources to get transcoding url")
self.info['Method'] = "Transcode"
@ -248,7 +248,7 @@ class PlayUtils(object):
url_parsed = params.split('&')
for i in url_parsed:
if 'AudioStreamIndex' in i or 'AudioBitrate' in i or 'SubtitleStreamIndex' in i: # handle manually
if 'AudioStreamIndex' in i or 'AudioBitrate' in i or 'SubtitleStreamIndex' in i: # handle manually
url_parsed.remove(i)
params = "%s%s" % ('&'.join(url_parsed), self.get_audio_subs(source, audio, subtitle))
@ -275,13 +275,19 @@ class PlayUtils(object):
self.info['Method'] = "DirectStream"
if self.item['Type'] == "Audio":
self.info['Path'] = ("%s/emby/Audio/%s/stream.%s?static=true&api_key=%s" %
(self.info['ServerAddress'], self.item['Id'],
source.get('Container', "mp4").split(',')[0],
self.info['Token']))
self.info['Path'] = "%s/emby/Audio/%s/stream.%s?static=true&api_key=%s" % (
self.info['ServerAddress'],
self.item['Id'],
source.get('Container', "mp4").split(',')[0],
self.info['Token']
)
else:
self.info['Path'] = ("%s/emby/Videos/%s/stream?static=true&MediaSourceId=%s&api_key=%s" %
(self.info['ServerAddress'], self.item['Id'], source['Id'], self.info['Token']))
self.info['Path'] = "%s/emby/Videos/%s/stream?static=true&MediaSourceId=%s&api_key=%s" % (
self.info['ServerAddress'],
self.item['Id'],
source['Id'],
self.info['Token']
)
return self.info['Path']
@ -495,7 +501,6 @@ class PlayUtils(object):
listitem.setSubtitles(subs)
self.item['PlaybackInfo']['Subtitles'] = mapping
@classmethod
def download_external_subs(cls, src, filename):
@ -579,7 +584,7 @@ class PlayUtils(object):
selection = list(audio_streams.keys())
resp = dialog("select", _(33013), selection)
audio_selected = audio_streams[selection[resp]] if resp else source['DefaultAudioStreamIndex']
else: # Only one choice
else: # Only one choice
audio_selected = audio_streams[next(iter(audio_streams))]
else:
audio_selected = source['DefaultAudioStreamIndex']
@ -628,7 +633,13 @@ class PlayUtils(object):
if stream['IsTextSubtitleStream'] and 'DeliveryUrl' in stream and stream['DeliveryUrl'].lower().startswith('/videos'):
url = "%s/emby%s" % (self.info['ServerAddress'], stream['DeliveryUrl'])
else:
url = ("%s/emby/Videos/%s/%s/Subtitles/%s/Stream.%s?api_key=%s" %
(self.info['ServerAddress'], self.item['Id'], source['Id'], index, stream['Codec'], self.info['Token']))
url = "%s/emby/Videos/%s/%s/Subtitles/%s/Stream.%s?api_key=%s" % (
self.info['ServerAddress'],
self.item['Id'],
source['Id'],
index,
stream['Codec'],
self.info['Token']
)
return url

View file

@ -11,10 +11,11 @@ import xbmcaddon
##################################################################################################
LOG = logging.getLogger('JELLYFIN.'+__name__)
LOG = logging.getLogger('JELLYFIN.' + __name__)
##################################################################################################
def _(string):
''' Get add-on string. Returns in unicode.
@ -26,7 +27,7 @@ def _(string):
if not result:
result = xbmc.getLocalizedString(string)
return result

View file

@ -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):

View file

@ -11,10 +11,11 @@ from utils import should_stop
#################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__)
LOG = logging.getLogger("JELLYFIN." + __name__)
#################################################################################################
def progress(message=None):
''' Will start and close the progress dialog.
@ -61,6 +62,7 @@ def catch(errors=(Exception,)):
return wrapper
return decorator
def silent_catch(errors=(Exception,)):
''' Wrapper to catch exceptions and ignore them
@ -76,6 +78,7 @@ def silent_catch(errors=(Exception,)):
return wrapper
return decorator
def stop(default=None):
''' Wrapper to catch exceptions and return using catch
@ -100,6 +103,7 @@ def stop(default=None):
return wrapper
return decorator
def jellyfin_item():
''' Wrapper to retrieve the jellyfin_db item.
@ -113,6 +117,7 @@ def jellyfin_item():
return wrapper
return decorator
def library_check():
''' Wrapper to retrieve the library
@ -148,7 +153,7 @@ def library_check():
return
view = {'Id': views[0], 'Name': views[1]}
else: # Grab the first music library
else: # Grab the first music library
return
else:
for ancestor in ancestors:

View file

@ -13,10 +13,11 @@ from . import _, indent, write_xml, dialog, settings
#################################################################################################
LOG = logging.getLogger("JELLYFIN."+__name__)
LOG = logging.getLogger("JELLYFIN." + __name__)
#################################################################################################
def sources():
''' Create master lock compatible sources.
@ -77,6 +78,7 @@ def sources():
indent(xml)
write_xml(etree.tostring(xml, 'UTF-8'), file)
def tvtunes_nfo(path, urls):
''' Create tvtunes.nfo
@ -96,6 +98,7 @@ def tvtunes_nfo(path, urls):
indent(xml)
write_xml(etree.tostring(xml, 'UTF-8'), path)
def advanced_settings():
''' Track the existence of <cleanonupdate>true</cleanonupdate>