From b7fa48ea84fcbdd2f79f249dbbd536f226a11aee Mon Sep 17 00:00:00 2001 From: TrueTechy Date: Wed, 4 Sep 2019 03:58:31 +0100 Subject: [PATCH] client.py - remove api --- resources/lib/connect.py | 2 +- resources/lib/full_sync.py | 2 +- resources/lib/helper/wrapper.py | 2 +- resources/lib/jellyfin/client.py | 3 -- resources/lib/library.py | 10 +++--- resources/lib/monitor.py | 58 ++++++++++++++++---------------- resources/lib/objects/actions.py | 4 +-- resources/lib/objects/movies.py | 2 +- resources/lib/objects/music.py | 8 ++--- resources/lib/objects/tvshows.py | 4 +-- resources/lib/player.py | 16 ++++----- resources/lib/views.py | 4 +-- 12 files changed, 56 insertions(+), 59 deletions(-) diff --git a/resources/lib/connect.py b/resources/lib/connect.py index b1fba75d..041b51ab 100644 --- a/resources/lib/connect.py +++ b/resources/lib/connect.py @@ -148,7 +148,7 @@ class Connect(object): ''' Save user info. ''' - self.user = client['api'].get_user() + self.user = client.jellyfin.get_user() settings('username', self.user['Name']) if 'PrimaryImageTag' in self.user: diff --git a/resources/lib/full_sync.py b/resources/lib/full_sync.py index 50560cea..6ba1c86b 100644 --- a/resources/lib/full_sync.py +++ b/resources/lib/full_sync.py @@ -228,7 +228,7 @@ class FullSync(object): return - library = self.server['api'].get_item(library_id.replace('Mixed:', "")) + library = self.server.jellyfin.get_item(library_id.replace('Mixed:', "")) if library_id.startswith('Mixed:'): for mixed in ('movies', 'tvshows'): diff --git a/resources/lib/helper/wrapper.py b/resources/lib/helper/wrapper.py index 71c07280..b5a89976 100644 --- a/resources/lib/helper/wrapper.py +++ b/resources/lib/helper/wrapper.py @@ -136,7 +136,7 @@ def library_check(): view = None if view is None: - ancestors = self.server['api'].get_ancestors(item['Id']) + ancestors = self.server.jellyfin.get_ancestors(item['Id']) if not ancestors: if item['Type'] == 'MusicArtist': diff --git a/resources/lib/jellyfin/client.py b/resources/lib/jellyfin/client.py index 7642ded8..5f4f4007 100644 --- a/resources/lib/jellyfin/client.py +++ b/resources/lib/jellyfin/client.py @@ -97,9 +97,6 @@ class JellyfinClient(object): elif key.startswith('auth'): return self.auth.__shortcuts__(key.replace('auth/', "", 1)) - elif key.startswith('api'): - return self.jellyfin - elif key == 'connected': return self.logged_in diff --git a/resources/lib/library.py b/resources/lib/library.py index a33a6407..9332cd4b 100644 --- a/resources/lib/library.py +++ b/resources/lib/library.py @@ -348,7 +348,7 @@ class Library(threading.Thread): if settings('SyncInstallRunDone.bool'): if settings('kodiCompanion.bool'): - for plugin in self.server['api'].get_plugins(): + for plugin in self.server.jellyfin.get_plugins(): if plugin['Name'] in ("Jellyfin.Kodi Sync Queue", "Kodi companion", "Kodi Sync Queue"): if not self.fast_sync(): @@ -400,7 +400,7 @@ class Library(threading.Thread): """ for library in sync['Whitelist']: - data = self.server['api'].get_date_modified(last_sync, library.replace('Mixed:', ""), "Series,Episode,BoxSet,Movie,MusicVideo,MusicArtist,MusicAlbum,Audio") + data = self.server.jellyfin.get_date_modified(last_sync, library.replace('Mixed:', ""), "Series,Episode,BoxSet,Movie,MusicVideo,MusicArtist,MusicAlbum,Audio") [self.updated_output[query['Type']].put(query) for query in data['Items']] """ try: @@ -409,7 +409,7 @@ class Library(threading.Thread): removed = [] for media in filters: - result = self.server['api'].get_sync_queue(last_sync, ",".join([x for x in filters if x != media])) + result = self.server.jellyfin.get_sync_queue(last_sync, ",".join([x for x in filters if x != media])) updated.extend(result['ItemsAdded']) updated.extend(result['ItemsUpdated']) userdata.extend(result['UserDataChanged']) @@ -431,7 +431,7 @@ class Library(threading.Thread): self.removed(removed) """ - result = self.server['api'].get_sync_queue(last_sync) + result = self.server.jellyfin.get_sync_queue(last_sync) self.userdata(result['UserDataChanged']) self.removed(result['ItemsRemoved']) @@ -439,7 +439,7 @@ class Library(threading.Thread): filters.extend(["tvshows", "boxsets", "musicvideos", "music"]) # Get only movies. - result = self.server['api'].get_sync_queue(last_sync, ",".join(filters)) + result = self.server.jellyfin.get_sync_queue(last_sync, ",".join(filters)) self.updated(result['ItemsAdded']) self.updated(result['ItemsUpdated']) self.userdata(result['UserDataChanged']) diff --git a/resources/lib/monitor.py b/resources/lib/monitor.py index 9e6b9c39..d2c60d68 100644 --- a/resources/lib/monitor.py +++ b/resources/lib/monitor.py @@ -125,22 +125,22 @@ class Monitor(xbmc.Monitor): if method == 'GetItem': - item = server['api'].get_item(data['Id']) + item = server.jellyfin.get_item(data['Id']) self.void_responder(data, item) elif method == 'GetAdditionalParts': - item = server['api'].get_additional_parts(data['Id']) + item = server.jellyfin.get_additional_parts(data['Id']) self.void_responder(data, item) elif method == 'GetIntros': - item = server['api'].get_intros(data['Id']) + item = server.jellyfin.get_intros(data['Id']) self.void_responder(data, item) elif method == 'GetImages': - item = server['api'].get_images(data['Id']) + item = server.jellyfin.get_images(data['Id']) self.void_responder(data, item) elif method == 'GetServerAddress': @@ -150,12 +150,12 @@ class Monitor(xbmc.Monitor): elif method == 'GetPlaybackInfo': - sources = server['api'].get_play_info(data['Id'], data['Profile']) + sources = server.jellyfin.get_play_info(data['Id'], data['Profile']) self.void_responder(data, sources) elif method == 'GetLiveStream': - sources = server['api'].get_live_stream(data['Id'], data['PlaySessionId'], data['Token'], data['Profile']) + sources = server.jellyfin.get_live_stream(data['Id'], data['PlaySessionId'], data['Token'], data['Profile']) self.void_responder(data, sources) elif method == 'GetToken': @@ -165,31 +165,31 @@ class Monitor(xbmc.Monitor): elif method == 'GetSession': - session = server['api'].get_device(self.device_id) + session = server.jellyfin.get_device(self.device_id) self.void_responder(data, session) elif method == 'GetUsers': - users = server['api'].get_users() + users = server.jellyfin.get_users() self.void_responder(data, users) elif method == 'GetTranscodeOptions': - result = server['api'].get_transcode_settings() + result = server.jellyfin.get_transcode_settings() self.void_responder(data, result) elif method == 'GetThemes': if data['Type'] == 'Video': - theme = server['api'].get_items_theme_video(data['Id']) + theme = server.jellyfin.get_items_theme_video(data['Id']) else: - theme = server['api'].get_items_theme_song(data['Id']) + theme = server.jellyfin.get_items_theme_song(data['Id']) self.void_responder(data, theme) elif method == 'GetTheme': - theme = server['api'].get_themes(data['Id']) + theme = server.jellyfin.get_themes(data['Id']) self.void_responder(data, theme) elif method == 'Browse': @@ -201,41 +201,41 @@ class Monitor(xbmc.Monitor): elif method == 'BrowseSeason': - result = server['api'].get_seasons(data['Id']) + result = server.jellyfin.get_seasons(data['Id']) self.void_responder(data, result) elif method == 'LiveTV': - result = server['api'].get_channels() + result = server.jellyfin.get_channels() self.void_responder(data, result) elif method == 'RecentlyAdded': - result = server['api'].get_recently_added(data.get('Media'), data.get('Id'), data.get('Limit')) + result = server.jellyfin.get_recently_added(data.get('Media'), data.get('Id'), data.get('Limit')) self.void_responder(data, result) elif method == 'Genres': - result = server['api'].get_genres(data.get('Id')) + result = server.jellyfin.get_genres(data.get('Id')) self.void_responder(data, result) elif method == 'Recommended': - result = server['api'].get_recommendation(data.get('Id'), data.get('Limit')) + result = server.jellyfin.get_recommendation(data.get('Id'), data.get('Limit')) self.void_responder(data, result) elif method == 'RefreshItem': - server['api'].refresh_item(data['Id']) + server.jellyfin.refresh_item(data['Id']) elif method == 'FavoriteItem': - server['api'].favorite(data['Id'], data['Favorite']) + server.jellyfin.favorite(data['Id'], data['Favorite']) elif method == 'DeleteItem': - server['api'].delete_item(data['Id']) + server.jellyfin.delete_item(data['Id']) elif method == 'PlayPlaylist': - server['api'].post_session(server['config/app.session'], "Playing", { + server.jellyfin.post_session(server['config/app.session'], "Playing", { 'PlayCommand': "PlayNow", 'ItemIds': data['Id'], 'StartPositionTicks': 0 @@ -243,7 +243,7 @@ class Monitor(xbmc.Monitor): elif method == 'Play': - items = server['api'].get_items(data['ItemIds']) + items = server.jellyfin.get_items(data['ItemIds']) PlaylistWorker(data.get('ServerId'), items, data['PlayCommand'] == 'PlayNow', data.get('StartPositionTicks', 0), data.get('AudioStreamIndex'), @@ -262,7 +262,7 @@ class Monitor(xbmc.Monitor): self.server_instance(data['ServerId']) elif method == 'AddUser': - server['api'].session_add_user(server['config/app.session'], data['Id'], data['Add']) + server.jellyfin.session_add_user(server['config/app.session'], data['Id'], data['Add']) self.additional_users(server) elif method == 'Player.OnPlay': @@ -286,20 +286,20 @@ class Monitor(xbmc.Monitor): elif settings('additionalUsers'): users = settings('additionalUsers').split(',') - all_users = server['api'].get_users() + all_users = server.jellyfin.get_users() for additional in users: for user in all_users: if user['Name'].lower() in additional.decode('utf-8').lower(): - server['api'].session_add_user(server['config/app.session'], user['Id'], True) + server.jellyfin.session_add_user(server['config/app.session'], user['Id'], True) self.additional_users(server) def post_capabilities(self, server): LOG.info("--[ post capabilities/%s ]", server['auth/server-id']) - server['api'].post_capabilities({ + server.jellyfin.post_capabilities({ 'PlayableMediaTypes': "Audio,Video", 'SupportsMediaControl': True, 'SupportedCommands': ( @@ -316,7 +316,7 @@ class Monitor(xbmc.Monitor): 'IconUrl': "https://raw.githubusercontent.com/jellyfin/jellyfin-kodi/master/kodi_icon.png", }) - session = server['api'].get_device(self.device_id) + session = server.jellyfin.get_device(self.device_id) server['config']['app.session'] = session[0]['Id'] def additional_users(self, server): @@ -327,7 +327,7 @@ class Monitor(xbmc.Monitor): window('JellyfinAdditionalUserImage.%s' % i, clear=True) try: - session = server['api'].get_device(self.device_id) + session = server.jellyfin.get_device(self.device_id) except Exception as error: LOG.exception(error) @@ -335,7 +335,7 @@ class Monitor(xbmc.Monitor): for index, user in enumerate(session[0]['AdditionalUsers']): - info = server['api'].get_user(user['UserId']) + info = server.jellyfin.get_user(user['UserId']) image = api.API(info, server['config/auth.server']).get_user_artwork(user['UserId']) window('JellyfinAdditionalUserImage.%s' % index, image) window('JellyfinAdditionalUserPosition.%s' % user['UserId'], str(index)) diff --git a/resources/lib/objects/actions.py b/resources/lib/objects/actions.py index de919d8c..5c5b169c 100644 --- a/resources/lib/objects/actions.py +++ b/resources/lib/objects/actions.py @@ -721,7 +721,7 @@ def on_update(data, server): if item: if not window('jellyfin.skip.%s.bool' % item[0]): - server['api'].item_played(item[0], playcount) + server.jellyfin.item_played(item[0], playcount) window('jellyfin.skip.%s' % item[0], clear=True) @@ -769,7 +769,7 @@ def on_play(data, server): return - item = server['api'].get_item(item[0]) + item = server.jellyfin.get_item(item[0]) item['PlaybackInfo'] = {'Path': file} playutils.set_properties(item, 'DirectStream' if settings('useDirectPaths') == '0' else 'DirectPlay') diff --git a/resources/lib/objects/movies.py b/resources/lib/objects/movies.py index b5f8ef05..6aae8c7f 100644 --- a/resources/lib/objects/movies.py +++ b/resources/lib/objects/movies.py @@ -169,7 +169,7 @@ class Movies(KodiDb): try: if obj['LocalTrailer']: - trailer = self.server['api'].get_local_trailers(obj['Id']) + trailer = self.server.jellyfin.get_local_trailers(obj['Id']) obj['Trailer'] = "plugin://plugin.video.jellyfin/trailer?id=%s&mode=play" % trailer[0]['Id'] elif obj['Trailer']: diff --git a/resources/lib/objects/music.py b/resources/lib/objects/music.py index d1c502fd..d526c4ad 100644 --- a/resources/lib/objects/music.py +++ b/resources/lib/objects/music.py @@ -217,7 +217,7 @@ class Music(KodiDb): except TypeError: try: - self.artist(self.server['api'].get_item(temp_obj['Id']), library=None) + self.artist(self.server.jellyfin.get_item(temp_obj['Id']), library=None) temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except Exception as error: LOG.exception(error) @@ -318,7 +318,7 @@ class Music(KodiDb): if obj['SongAlbumId'] is None: raise TypeError("No album id found associated?") - self.album(self.server['api'].get_item(obj['SongAlbumId'])) + self.album(self.server.jellyfin.get_item(obj['SongAlbumId'])) obj['AlbumId'] = self.jellyfin_db.get_item_by_id(*values(obj, QUEM.get_item_song_obj))[0] except TypeError: self.single(obj) @@ -373,7 +373,7 @@ class Music(KodiDb): except TypeError: try: - self.artist(self.server['api'].get_item(temp_obj['Id']), library=None) + self.artist(self.server.jellyfin.get_item(temp_obj['Id']), library=None) temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except Exception as error: LOG.exception(error) @@ -407,7 +407,7 @@ class Music(KodiDb): except TypeError: try: - self.artist(self.server['api'].get_item(temp_obj['Id']), library=None) + self.artist(self.server.jellyfin.get_item(temp_obj['Id']), library=None) temp_obj['ArtistId'] = self.jellyfin_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except Exception as error: LOG.exception(error) diff --git a/resources/lib/objects/tvshows.py b/resources/lib/objects/tvshows.py index fa7d614e..e155d806 100644 --- a/resources/lib/objects/tvshows.py +++ b/resources/lib/objects/tvshows.py @@ -137,7 +137,7 @@ class TVShows(KodiDb): season_episodes = {} - for season in self.server['api'].get_seasons(obj['Id'])['Items']: + for season in self.server.jellyfin.get_seasons(obj['Id'])['Items']: if season['SeriesId'] != obj['Id']: obj['SeriesId'] = season['SeriesId'] @@ -435,7 +435,7 @@ class TVShows(KodiDb): if obj['ShowId'] is None: try: - self.tvshow(self.server['api'].get_item(obj['SeriesId']), library=None) + self.tvshow(self.server.jellyfin.get_item(obj['SeriesId']), library=None) obj['ShowId'] = self.jellyfin_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj))[0] except (TypeError, KeyError): LOG.error("Unable to add series %s", obj['SeriesId']) diff --git a/resources/lib/player.py b/resources/lib/player.py index 712c9bb9..ef0f8ccc 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -110,7 +110,7 @@ class Player(xbmc.Player): 'AudioStreamIndex': item['AudioStreamIndex'], 'SubtitleStreamIndex': item['SubtitleStreamIndex'] } - item['Server']['api'].session_playing(data) + item['Server'].jellyfin.session_playing(data) window('jellyfin.skip.%s.bool' % item['Id'], True) if monitor.waitForAbort(2): @@ -239,7 +239,7 @@ class Player(xbmc.Player): if item['Type'] != 'Episode' or not item.get('CurrentEpisode'): return - next_items = item['Server']['api'].get_adjacent_episodes(item['CurrentEpisode']['tvshowid'], item['Id']) + next_items = item['Server'].jellyfin.get_adjacent_episodes(item['CurrentEpisode']['tvshowid'], item['Id']) for index, next_item in enumerate(next_items['Items']): if next_item['Id'] == item['Id']: @@ -359,7 +359,7 @@ class Player(xbmc.Player): 'AudioStreamIndex': item['AudioStreamIndex'], 'SubtitleStreamIndex': item['SubtitleStreamIndex'] } - item['Server']['api'].session_progress(data) + item['Server'].jellyfin.session_progress(data) def onPlayBackStopped(self): @@ -402,17 +402,17 @@ class Player(xbmc.Player): 'PositionTicks': int(item['CurrentPosition'] * 10000000), 'PlaySessionId': item['PlaySessionId'] } - item['Server']['api'].session_stop(data) + item['Server'].jellyfin.session_stop(data) if item.get('LiveStreamId'): LOG.info("<[ livestream/%s ]", item['LiveStreamId']) - item['Server']['api'].close_live_stream(item['LiveStreamId']) + item['Server'].jellyfin.close_live_stream(item['LiveStreamId']) elif item['PlayMethod'] == 'Transcode': LOG.info("<[ transcode/%s ]", item['Id']) - item['Server']['api'].close_transcode(item['DeviceId']) + item['Server'].jellyfin.close_transcode(item['DeviceId']) path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/temp/").decode('utf-8') @@ -423,7 +423,7 @@ class Player(xbmc.Player): for file in files: xbmcvfs.delete(os.path.join(path, file.decode('utf-8'))) - result = item['Server']['api'].get_item(item['Id']) or {} + result = item['Server'].jellyfin.get_item(item['Id']) or {} if 'UserData' in result and result['UserData']['Played']: delete = False @@ -440,7 +440,7 @@ class Player(xbmc.Player): LOG.info("Offer delete option") if dialog("yesno", heading=_(30091), line1=_(33015), autoclose=120000): - item['Server']['api'].delete_item(item['Id']) + item['Server'].jellyfin.delete_item(item['Id']) window('jellyfin.external_check', clear=True) diff --git a/resources/lib/views.py b/resources/lib/views.py index 9c2fc457..c3b5af91 100644 --- a/resources/lib/views.py +++ b/resources/lib/views.py @@ -167,8 +167,8 @@ class Views(object): def get_libraries(self): try: - libraries = self.server['api'].get_media_folders()['Items'] - views = self.server['api'].get_views()['Items'] + libraries = self.server.jellyfin.get_media_folders()['Items'] + views = self.server.jellyfin.get_views()['Items'] except Exception as error: LOG.exception(error) raise IndexError("Unable to retrieve libraries: %s" % error)