Merge pull request #402 from bpepple/simplify-code-🔨

Simplify code 🔨
This commit is contained in:
Odd Stråbø 2021-10-12 17:39:43 +02:00 committed by GitHub
commit aaa7f33a77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 43 additions and 54 deletions

View file

@ -46,7 +46,7 @@ class Connect(object):
if server['Id'] == server_id: if server['Id'] == server_id:
credentials['Servers'] = [server] credentials['Servers'] = [server]
server_select = True if server_id is None and not settings('SyncInstallRunDone.bool') else False server_select = server_id is None and not settings('SyncInstallRunDone.bool')
new_credentials = self.register_client(credentials, options, server_id, server_select) new_credentials = self.register_client(credentials, options, server_id, server_select)
for server in servers: for server in servers:

View file

@ -35,13 +35,12 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs) xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
def set_options(self, options=None): def set_options(self, options=None):
self._options = options
if options is None: if options is None:
self._options = [] self._options = []
else:
self._options = options
def is_selected(self): def is_selected(self):
return True if self.selected_option else False return bool(self.selected_option)
def get_selected(self): def get_selected(self):
return self.selected_option return self.selected_option

View file

@ -40,7 +40,7 @@ class LoginManual(xbmcgui.WindowXMLDialog):
setattr(self, key, value) setattr(self, key, value)
def is_logged_in(self): def is_logged_in(self):
return True if self._user else False return bool(self._user)
def get_user(self): def get_user(self):
return self._user return self._user

View file

@ -31,7 +31,7 @@ class ResumeDialog(xbmcgui.WindowXMLDialog):
self._resume_point = time self._resume_point = time
def is_selected(self): def is_selected(self):
return True if self.selected_option is not None else False return self.selected_option is not None
def get_selected(self): def get_selected(self):
return self.selected_option return self.selected_option

View file

@ -48,7 +48,7 @@ class ServerConnect(xbmcgui.WindowXMLDialog):
setattr(self, key, value) setattr(self, key, value)
def is_server_selected(self): def is_server_selected(self):
return True if self._selected_server else False return bool(self._selected_server)
def get_server(self): def get_server(self):
return self._selected_server return self._selected_server

View file

@ -48,7 +48,7 @@ class ServerManual(xbmcgui.WindowXMLDialog):
setattr(self, key, value) setattr(self, key, value)
def is_connected(self): def is_connected(self):
return True if self._server else False return bool(self._server)
def get_server(self): def get_server(self):
return self._server return self._server

View file

@ -39,7 +39,7 @@ class UsersConnect(xbmcgui.WindowXMLDialog):
setattr(self, key, value) setattr(self, key, value)
def is_user_selected(self): def is_user_selected(self):
return True if self._user else False return bool(self._user)
def get_user(self): def get_user(self):
return self._user return self._user

View file

@ -69,7 +69,7 @@ def validate_view(library_id, item_id):
LOG.exception(error) LOG.exception(error)
return False return False
return True if len(result['Items']) else False return bool(len(result['Items']))
def get_single_item(parent_id, media): def get_single_item(parent_id, media):

View file

@ -267,7 +267,7 @@ def browse(media, view_id=None, folder=None, server_id=None, api_client=None):
monitor = xbmc.Monitor() monitor = xbmc.Monitor()
for i in range(300): for _i in range(300):
if window('jellyfin_online.bool'): if window('jellyfin_online.bool'):
break break
elif monitor.waitForAbort(0.1): elif monitor.waitForAbort(0.1):

View file

@ -540,11 +540,11 @@ class FullSync(object):
settings('MusicRescan.bool', False) settings('MusicRescan.bool', False)
if items: if items:
count = 0
with self.library.music_database_lock if media == 'music' else self.library.database_lock: with self.library.music_database_lock if media == 'music' else self.library.database_lock:
with Database(media) as kodidb: with Database(media) as kodidb:
count = 0
if library.media_type == 'mixed': if library.media_type == 'mixed':
movies = [x for x in items if x[1] == 'Movie'] movies = [x for x in items if x[1] == 'Movie']

View file

@ -185,10 +185,7 @@ def should_stop():
LOG.info("exiiiiitttinggg") LOG.info("exiiiiitttinggg")
return True return True
if not window('jellyfin_online.bool'): return not window('jellyfin_online.bool')
return True
return False
def get_screensaver(): def get_screensaver():

View file

@ -452,5 +452,4 @@ class API(object):
returns the URL the server prefers to use returns the URL the server prefers to use
''' '''
response = self.send_request(server_address, "system/info/public") response = self.send_request(server_address, "system/info/public")
url = response.url.replace('/system/info/public', '') return response.url.replace('/system/info/public', '')
return url

View file

@ -340,13 +340,13 @@ class ConnectionManager(object):
self.config.data['auth.server=id'] = server['Id'] self.config.data['auth.server=id'] = server['Id']
self.config.data['auth.ssl'] = options.get('ssl', self.config.data['auth.ssl']) self.config.data['auth.ssl'] = options.get('ssl', self.config.data['auth.ssl'])
result = {
'Servers': [server]
}
result['State'] = CONNECTION_STATE['SignedIn'] if server.get('AccessToken') else CONNECTION_STATE['ServerSignIn']
# Connected # Connected
return result return {
'Servers': [server],
'State': CONNECTION_STATE['SignedIn']
if server.get('AccessToken')
else CONNECTION_STATE['ServerSignIn'],
}
def _update_server_info(self, server, system_info): def _update_server_info(self, server, system_info):

View file

@ -341,20 +341,21 @@ class Library(threading.Thread):
return True return True
if settings('SyncInstallRunDone.bool'): if settings('SyncInstallRunDone.bool') and settings(
if settings('kodiCompanion.bool'): 'kodiCompanion.bool'
):
if self.server.jellyfin.check_companion_installed(): if self.server.jellyfin.check_companion_installed():
if not self.fast_sync(): if not self.fast_sync():
dialog("ok", "{jellyfin}", translate(33128)) dialog("ok", "{jellyfin}", translate(33128))
raise Exception("Failed to retrieve latest updates") raise Exception("Failed to retrieve latest updates")
LOG.info("--<[ retrieve changes ]") LOG.info("--<[ retrieve changes ]")
else: else:
raise LibraryException('CompanionMissing') raise LibraryException('CompanionMissing')
return True return True
except LibraryException as error: except LibraryException as error:

View file

@ -255,19 +255,17 @@ class Monitor(xbmc.Monitor):
if command in ('Mute', 'Unmute', 'SetVolume', if command in ('Mute', 'Unmute', 'SetVolume',
'SetSubtitleStreamIndex', 'SetAudioStreamIndex', 'SetRepeatMode'): 'SetSubtitleStreamIndex', 'SetAudioStreamIndex', 'SetRepeatMode'):
if command == 'Mute': if command in ['Mute', 'Unmute']:
xbmc.executebuiltin('Mute') xbmc.executebuiltin('Mute')
elif command == 'Unmute':
xbmc.executebuiltin('Mute')
elif command == 'SetVolume':
xbmc.executebuiltin('SetVolume(%s[,showvolumebar])' % args['Volume'])
elif command == 'SetRepeatMode':
xbmc.executebuiltin('xbmc.PlayerControl(%s)' % args['RepeatMode'])
elif command == 'SetAudioStreamIndex': elif command == 'SetAudioStreamIndex':
self.player.set_audio_subs(args['Index']) self.player.set_audio_subs(args['Index'])
elif command == 'SetRepeatMode':
xbmc.executebuiltin('xbmc.PlayerControl(%s)' % args['RepeatMode'])
elif command == 'SetSubtitleStreamIndex': elif command == 'SetSubtitleStreamIndex':
self.player.set_audio_subs(None, args['Index']) self.player.set_audio_subs(None, args['Index'])
elif command == 'SetVolume':
xbmc.executebuiltin('SetVolume(%s[,showvolumebar])' % args['Volume'])
# Kodi needs a bit of time to update it's current status # Kodi needs a bit of time to update it's current status
xbmc.sleep(500) xbmc.sleep(500)
self.player.report_playback() self.player.report_playback()

View file

@ -95,7 +95,7 @@ class Actions(object):
if choice is None: if choice is None:
raise Exception("User backed out of resume dialog.") raise Exception("User backed out of resume dialog.")
item["resumePlayback"] = False if not choice else True item["resumePlayback"] = bool(choice)
if settings('enableCinema.bool') and not item["resumePlayback"]: if settings('enableCinema.bool') and not item["resumePlayback"]:
self._set_intros(item) self._set_intros(item)
@ -314,7 +314,7 @@ class Actions(object):
obj['Artwork']['Backdrop'] = obj['Artwork']['Backdrop'] or [] obj['Artwork']['Backdrop'] = obj['Artwork']['Backdrop'] or []
obj['Artwork']['Thumb'] = obj['Artwork']['Thumb'] or "" obj['Artwork']['Thumb'] = obj['Artwork']['Thumb'] or ""
if not intro and not obj['Type'] == 'Trailer': if not intro and obj['Type'] != 'Trailer':
obj['Artwork']['Primary'] = obj['Artwork']['Primary'] \ obj['Artwork']['Primary'] = obj['Artwork']['Primary'] \
or "special://home/addons/plugin.video.jellyfin/resources/icon.png" or "special://home/addons/plugin.video.jellyfin/resources/icon.png"
else: else:

View file

@ -101,8 +101,7 @@ class Movies(KodiDb):
if obj['Countries']: if obj['Countries']:
self.add_countries(*values(obj, QU.update_country_obj)) self.add_countries(*values(obj, QU.update_country_obj))
tags = [] tags = list(obj['Tags'] or [])
tags.extend(obj['Tags'] or [])
tags.append(obj['LibraryName']) tags.append(obj['LibraryName'])
if obj['Favorite']: if obj['Favorite']:

View file

@ -125,11 +125,10 @@ class Objects(object):
obj = self.__recursive__(obj, first) obj = self.__recursive__(obj, first)
if obj: if obj:
if rest: for item in obj:
for item in obj: if rest:
self.__recursiveloop__(item, rest) self.__recursiveloop__(item, rest)
else: else:
for item in obj:
yield item yield item
def __recursive__(self, obj, keys): def __recursive__(self, obj, keys):

View file

@ -832,17 +832,14 @@ class Views(object):
window_prop = "Jellyfin.wnodes.%s" % index window_prop = "Jellyfin.wnodes.%s" % index
window('%s.index' % window_prop, path.replace('all.xml', "")) # dir window('%s.index' % window_prop, path.replace('all.xml', "")) # dir
window('%s.title' % window_prop, view['Name']) window('%s.title' % window_prop, view['Name'])
window('%s.content' % window_prop, path)
elif node == 'browse': elif node == 'browse':
window_prop = "Jellyfin.wnodes.%s" % index window_prop = "Jellyfin.wnodes.%s" % index
window('%s.title' % window_prop, view['Name']) window('%s.title' % window_prop, view['Name'])
window('%s.content' % window_prop, path)
else: else:
window_prop = "Jellyfin.wnodes.%s.%s" % (index, node) window_prop = "Jellyfin.wnodes.%s.%s" % (index, node)
window('%s.title' % window_prop, node_label) window('%s.title' % window_prop, node_label)
window('%s.content' % window_prop, path) window('%s.content' % window_prop, path)
window('%s.id' % window_prop, view['Id']) window('%s.id' % window_prop, view['Id'])
window('%s.path' % window_prop, window_path) window('%s.path' % window_prop, window_path)
@ -856,7 +853,7 @@ class Views(object):
if not self.server.logged_in: if not self.server.logged_in:
window('%s.artwork' % prop, clear=True) window('%s.artwork' % prop, clear=True)
elif self.server.logged_in and self.media_folders is not None: elif self.media_folders is not None:
for library in self.media_folders: for library in self.media_folders:
if library['Id'] == view_id and 'Primary' in library.get('ImageTags', {}): if library['Id'] == view_id and 'Primary' in library.get('ImageTags', {}):