Tool black: auto-format Python code

This commit is contained in:
Odd Stråbø 2024-06-10 09:19:47 +00:00
parent e4d8084c25
commit 7763762212
54 changed files with 6545 additions and 4723 deletions

View file

@ -23,35 +23,30 @@ class Objects(object):
_shared_state = {}
def __init__(self):
''' Hold all persistent data here.
'''
"""Hold all persistent data here."""
self.__dict__ = self._shared_state
def mapping(self):
''' Load objects mapping.
'''
"""Load objects mapping."""
file_dir = os.path.dirname(ensure_text(__file__, get_filesystem_encoding()))
with open(os.path.join(file_dir, 'obj_map.json')) as infile:
with open(os.path.join(file_dir, "obj_map.json")) as infile:
self.objects = json.load(infile)
def map(self, item, mapping_name):
"""Syntax to traverse the item dictionary.
This of the query almost as a url.
''' Syntax to traverse the item dictionary.
This of the query almost as a url.
Item is the Jellyfin item json object structure
Item is the Jellyfin item json object structure
",": each element will be used as a fallback until a value is found.
"?": split filters and key name from the query part, i.e. MediaSources/0?$Name
"$": lead the key name with $. Only one key value can be requested per element.
":": indicates it's a list of elements [], i.e. MediaSources/0/MediaStreams:?$Name
MediaStreams is a list.
"/": indicates where to go directly
'''
",": each element will be used as a fallback until a value is found.
"?": split filters and key name from the query part, i.e. MediaSources/0?$Name
"$": lead the key name with $. Only one key value can be requested per element.
":": indicates it's a list of elements [], i.e. MediaSources/0/MediaStreams:?$Name
MediaStreams is a list.
"/": indicates where to go directly
"""
self.mapped_item = {}
if not mapping_name:
@ -62,7 +57,7 @@ class Objects(object):
for key, value in iteritems(mapping):
self.mapped_item[key] = None
params = value.split(',')
params = value.split(",")
for param in params:
@ -71,19 +66,19 @@ class Objects(object):
obj_key = ""
obj_filters = {}
if '?' in obj_param:
if "?" in obj_param:
if '$' in obj_param:
obj_param, obj_key = obj_param.rsplit('$', 1)
if "$" in obj_param:
obj_param, obj_key = obj_param.rsplit("$", 1)
obj_param, filters = obj_param.rsplit('?', 1)
obj_param, filters = obj_param.rsplit("?", 1)
if filters:
for filter in filters.split('&'):
filter_key, filter_value = filter.split('=')
for filter in filters.split("&"):
filter_key, filter_value = filter.split("=")
obj_filters[filter_key] = filter_value
if ':' in obj_param:
if ":" in obj_param:
result = []
for d in self.__recursiveloop__(obj, obj_param):
@ -94,7 +89,7 @@ class Objects(object):
obj = result
obj_filters = {}
elif '/' in obj_param:
elif "/" in obj_param:
obj = self.__recursive__(obj, obj_param)
elif obj is item and obj is not None:
@ -107,21 +102,31 @@ class Objects(object):
continue
if obj_key:
obj = [d[obj_key] for d in obj if d.get(obj_key)] if type(obj) == list else obj.get(obj_key)
obj = (
[d[obj_key] for d in obj if d.get(obj_key)]
if type(obj) == list
else obj.get(obj_key)
)
self.mapped_item[key] = obj
break
if not mapping_name.startswith('Browse') and not mapping_name.startswith('Artwork') and not mapping_name.startswith('UpNext'):
if (
not mapping_name.startswith("Browse")
and not mapping_name.startswith("Artwork")
and not mapping_name.startswith("UpNext")
):
self.mapped_item['ProviderName'] = self.objects.get('%sProviderName' % mapping_name)
self.mapped_item['Checksum'] = json.dumps(item['UserData'])
self.mapped_item["ProviderName"] = self.objects.get(
"%sProviderName" % mapping_name
)
self.mapped_item["Checksum"] = json.dumps(item["UserData"])
return self.mapped_item
def __recursiveloop__(self, obj, keys):
first, rest = keys.split(':', 1)
first, rest = keys.split(":", 1)
obj = self.__recursive__(obj, first)
if obj:
@ -133,7 +138,7 @@ class Objects(object):
def __recursive__(self, obj, keys):
for string in keys.split('/'):
for string in keys.split("/"):
if not obj:
return
@ -150,10 +155,10 @@ class Objects(object):
inverse = False
if value.startswith('!'):
if value.startswith("!"):
inverse = True
value = value.split('!', 1)[1]
value = value.split("!", 1)[1]
if value.lower() == "null":
value = None