diff --git a/jellyfin_kodi/dialogs/context.py b/jellyfin_kodi/dialogs/context.py index e4ce520f..83b3eea0 100644 --- a/jellyfin_kodi/dialogs/context.py +++ b/jellyfin_kodi/dialogs/context.py @@ -64,14 +64,13 @@ class ContextMenu(xbmcgui.WindowXMLDialog): if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU): self.close() - if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK): + if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK) and self.getFocusId() == LIST: - if self.getFocusId() == LIST: - option = self.list_.getSelectedItem() - self.selected_option = ensure_text(option.getLabel()) - LOG.info('option selected: %s', self.selected_option) + option = self.list_.getSelectedItem() + self.selected_option = ensure_text(option.getLabel()) + LOG.info('option selected: %s', self.selected_option) - self.close() + self.close() def _add_editcontrol(self, x, y, height, width, password=0): diff --git a/jellyfin_kodi/dialogs/serverconnect.py b/jellyfin_kodi/dialogs/serverconnect.py index 95f31c91..a6ddc5f2 100644 --- a/jellyfin_kodi/dialogs/serverconnect.py +++ b/jellyfin_kodi/dialogs/serverconnect.py @@ -87,16 +87,15 @@ class ServerConnect(xbmcgui.WindowXMLDialog): if action in (ACTION_BACK, ACTION_PREVIOUS_MENU, ACTION_PARENT_DIR): self.close() - if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK): + if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK) and self.getFocusId() == LIST: - if self.getFocusId() == LIST: - server = self.list_.getSelectedItem() - selected_id = server.getProperty('id') - LOG.info('Server Id selected: %s', selected_id) + server = self.list_.getSelectedItem() + selected_id = server.getProperty('id') + LOG.info('Server Id selected: %s', selected_id) - if self._connect_server(selected_id): - self.message_box.setVisibleCondition('false') - self.close() + if self._connect_server(selected_id): + self.message_box.setVisibleCondition('false') + self.close() def onClick(self, control): diff --git a/jellyfin_kodi/dialogs/usersconnect.py b/jellyfin_kodi/dialogs/usersconnect.py index 414fa51f..57daecab 100644 --- a/jellyfin_kodi/dialogs/usersconnect.py +++ b/jellyfin_kodi/dialogs/usersconnect.py @@ -70,19 +70,18 @@ class UsersConnect(xbmcgui.WindowXMLDialog): if action in (ACTION_BACK, ACTION_PREVIOUS_MENU, ACTION_PARENT_DIR): self.close() - if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK): + if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK) and self.getFocusId() == LIST: - if self.getFocusId() == LIST: - user = self.list_.getSelectedItem() - selected_id = user.getProperty('id') - LOG.info('User Id selected: %s', selected_id) + user = self.list_.getSelectedItem() + selected_id = user.getProperty('id') + LOG.info('User Id selected: %s', selected_id) - for user in self.users: - if user['Id'] == selected_id: - self._user = user - break + for user in self.users: + if user['Id'] == selected_id: + self._user = user + break - self.close() + self.close() def onClick(self, control): diff --git a/jellyfin_kodi/entrypoint/context.py b/jellyfin_kodi/entrypoint/context.py index b20af031..53719060 100644 --- a/jellyfin_kodi/entrypoint/context.py +++ b/jellyfin_kodi/entrypoint/context.py @@ -158,15 +158,7 @@ class Context(object): self.delete_item() def delete_item(self): - - delete = True - - if not settings('skipContextMenu.bool'): - - if not dialog("yesno", "{jellyfin}", translate(33015)): - delete = False - - if delete: + if settings('skipContextMenu.bool') and dialog("yesno", "{jellyfin}", translate(33015)): TheVoid('DeleteItem', {'ServerId': self.server, 'Id': self.item['Id']}) def transcode(self): diff --git a/jellyfin_kodi/entrypoint/service.py b/jellyfin_kodi/entrypoint/service.py index 9fa890ed..f9decef8 100644 --- a/jellyfin_kodi/entrypoint/service.py +++ b/jellyfin_kodi/entrypoint/service.py @@ -337,10 +337,8 @@ class Service(xbmc.Monitor): if self.library_thread is not None: self.library_thread.fast_sync() - elif method == 'UserConfigurationUpdated': - - if data.get('ServerId') is None: - Views().get_views() + elif method == 'UserConfigurationUpdated' and data.get('ServerId') is None: + Views().get_views() def onSettingsChanged(self): diff --git a/jellyfin_kodi/helper/api.py b/jellyfin_kodi/helper/api.py index 441fe33e..b85ce61e 100644 --- a/jellyfin_kodi/helper/api.py +++ b/jellyfin_kodi/helper/api.py @@ -32,20 +32,14 @@ class API(object): def get_naming(self): - if self.item['Type'] == 'Episode': + if self.item['Type'] == 'Episode' and 'SeriesName' in self.item: + return "%s: %s" % (self.item['SeriesName'], self.item['Name']) - if 'SeriesName' in self.item: - return "%s: %s" % (self.item['SeriesName'], self.item['Name']) + elif self.item['Type'] == 'MusicAlbum' and 'AlbumArtist' in self.item: + return "%s: %s" % (self.item['AlbumArtist'], self.item['Name']) - elif self.item['Type'] == 'MusicAlbum': - - if 'AlbumArtist' in self.item: - return "%s: %s" % (self.item['AlbumArtist'], self.item['Name']) - - elif self.item['Type'] == 'Audio': - - if self.item.get('Artists'): - return "%s: %s" % (self.item['Artists'][0], self.item['Name']) + elif self.item['Type'] == 'Audio' and self.item.get('Artists'): + return "%s: %s" % (self.item['Artists'][0], self.item['Name']) return self.item['Name'] @@ -93,13 +87,11 @@ class API(object): if "msmpeg4" in track['codec']: track['codec'] = "divx" - elif "mpeg4" in track['codec']: - if "simple profile" in track['profile'] or not track['profile']: - track['codec'] = "xvid" + elif "mpeg4" in track['codec'] and ("simple profile" in track['profile'] or not track['profile']): + track['codec'] = "xvid" - elif "h264" in track['codec']: - if container in ('mp4', 'mov', 'm4v'): - track['codec'] = "avc1" + elif "h264" in track['codec'] and container in ('mp4', 'mov', 'm4v'): + track['codec'] = "avc1" try: width, height = self.item.get('AspectRatio', track.get('AspectRatio', "0")).split(':') diff --git a/jellyfin_kodi/helper/utils.py b/jellyfin_kodi/helper/utils.py index 08364f8c..7b814116 100644 --- a/jellyfin_kodi/helper/utils.py +++ b/jellyfin_kodi/helper/utils.py @@ -215,8 +215,8 @@ def set_screensaver(value): class JSONRPC(object): - version = 1 - jsonrpc = "2.0" + id = 1 + jsonrpc_version = "2.0" def __init__(self, method, **kwargs): @@ -228,8 +228,8 @@ class JSONRPC(object): def _query(self): query = { - 'jsonrpc': self.jsonrpc, - 'id': self.version, + 'jsonrpc': self.jsonrpc_version, + 'id': self.id, 'method': self.method, } if self.params is not None: diff --git a/jellyfin_kodi/jellyfin/connection_manager.py b/jellyfin_kodi/jellyfin/connection_manager.py index f5eb05e5..05ed79b4 100644 --- a/jellyfin_kodi/jellyfin/connection_manager.py +++ b/jellyfin_kodi/jellyfin/connection_manager.py @@ -260,8 +260,8 @@ class ConnectionManager(object): } servers.append(info) - else: - return servers + + return servers # TODO: Make IPv6 compatable def _convert_endpoint_address_to_manual_address(self, info): diff --git a/jellyfin_kodi/jellyfin/credentials.py b/jellyfin_kodi/jellyfin/credentials.py index e52bdee8..42e708a9 100644 --- a/jellyfin_kodi/jellyfin/credentials.py +++ b/jellyfin_kodi/jellyfin/credentials.py @@ -82,9 +82,8 @@ class Credentials(object): if existing['Id'] == server['Id']: # Merge the data - if server.get('DateLastAccessed'): - if self._date_object(server['DateLastAccessed']) > self._date_object(existing['DateLastAccessed']): - existing['DateLastAccessed'] = server['DateLastAccessed'] + if server.get('DateLastAccessed') and self._date_object(server['DateLastAccessed']) > self._date_object(existing['DateLastAccessed']): + existing['DateLastAccessed'] = server['DateLastAccessed'] if server.get('UserLinkType'): existing['UserLinkType'] = server['UserLinkType'] @@ -112,9 +111,9 @@ class Credentials(object): existing['ConnectServerId'] = server['ConnectServerId'] return existing - else: - servers.append(server) - return server + + servers.append(server) + return server def _date_object(self, date): # Convert string to date diff --git a/jellyfin_kodi/objects/obj.py b/jellyfin_kodi/objects/obj.py index 63c9dbc2..b506a969 100644 --- a/jellyfin_kodi/objects/obj.py +++ b/jellyfin_kodi/objects/obj.py @@ -100,9 +100,8 @@ class Objects(object): elif obj is item and obj is not None: obj = item.get(obj_param) - if obj_filters and obj: - if not self.__filters__(obj, obj_filters): - obj = None + if obj_filters and obj and not self.__filters__(obj, obj_filters): + obj = None if obj is None and len(params) != params.index(param): continue diff --git a/jellyfin_kodi/views.py b/jellyfin_kodi/views.py index 4f43992f..f2713928 100644 --- a/jellyfin_kodi/views.py +++ b/jellyfin_kodi/views.py @@ -177,12 +177,6 @@ class Views(object): ''' Get the media folders. Add or remove them. Do not proceed if issue getting libraries. ''' - media = { - 'movies': "Movie", - 'tvshows': "Series", - 'musicvideos': "MusicVideo" - } - try: libraries = self.get_libraries() except IndexError as error: @@ -242,8 +236,8 @@ class Views(object): temp_view['Media'] = media self.add_playlist(playlist_path, temp_view, True) self.add_nodes(node_path, temp_view, True) - else: # Compensate for the duplicate. - index += 1 + + index += 1 # Compensate for the duplicate. else: if view['Media'] in ('movies', 'tvshows', 'musicvideos'): self.add_playlist(playlist_path, view) @@ -743,9 +737,10 @@ class Views(object): temp_view['Name'] = "%s (%s)" % (view['Name'], translate(media)) self.window_node(index, temp_view, *node) self.window_wnode(windex, temp_view, *node) - else: # Add one to compensate for the duplicate. - index += 1 - windex += 1 + + # Add one to compensate for the duplicate. + index += 1 + windex += 1 else: for node in NODES[view['Media']]: diff --git a/service.py b/service.py index 5b8447a1..353cc58a 100644 --- a/service.py +++ b/service.py @@ -25,7 +25,7 @@ from helper import LazyLogger # noqa: F402 ################################################################################################# LOG = LazyLogger(__name__) -DELAY = int(settings('startupDelay') if settings('SyncInstallRunDone.bool') else 4 or 0) +DELAY = int(settings('startupDelay') if settings('SyncInstallRunDone.bool') else 4) #################################################################################################