Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove __shortcuts__ in http.py and some in client.py #27 #64

Merged
merged 4 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/lib/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_user(self, client):

''' 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:
Expand Down
6 changes: 2 additions & 4 deletions resources/lib/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def browse_info():

def _http(action, url, request={}, server_id=None):
request.update({'url': url, 'type': action})

return Jellyfin(server_id)['http/request'](request)

return Jellyfin(server_id).http.request(request)

def _get(handler, params=None, server_id=None):
return _http("GET", get_jellyfinserver_url(handler), {'params': params}, server_id)
Expand Down Expand Up @@ -305,7 +303,7 @@ def run(self):
}

try:
result = self.server['http/request'](request, s)
result = self.server.http.request(request, s)

for item in result['Items']:

Expand Down
2 changes: 1 addition & 1 deletion resources/lib/full_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def process_library(self, library_id):

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'):
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/helper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def wrapper(self, item, *args, **kwargs):
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':
Expand Down
6 changes: 0 additions & 6 deletions resources/lib/jellyfin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ def __getitem__(self, key):
if key.startswith('config'):
return self.config[key.replace('config/', "", 1)] if "/" in key else self.config

elif key.startswith('http'):
return self.http.__shortcuts__(key.replace('http/', "", 1))

elif key.startswith('websocket'):
return self.wsc.__shortcuts__(key.replace('websocket/', "", 1))

Expand All @@ -100,9 +97,6 @@ def __getitem__(self, key):
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

Expand Down
8 changes: 0 additions & 8 deletions resources/lib/jellyfin/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def __init__(self, client):
self.client = client
self.config = client['config']

def __shortcuts__(self, key):
LOG.debug("__shortcuts__(%r)", key)

if key == "request":
return self.request

return

def start_session(self):

self.session = requests.Session()
Expand Down
10 changes: 5 additions & 5 deletions resources/lib/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def startup(self):
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():
Expand Down Expand Up @@ -400,7 +400,7 @@ def fast_sync(self):
"""
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:
Expand All @@ -409,7 +409,7 @@ def fast_sync(self):
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'])
Expand All @@ -431,15 +431,15 @@ def fast_sync(self):
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'])


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'])
Expand Down
58 changes: 29 additions & 29 deletions resources/lib/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,22 @@ def onNotification(self, sender, method, data):

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':
Expand All @@ -150,12 +150,12 @@ def onNotification(self, sender, method, data):

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':
Expand All @@ -165,31 +165,31 @@ def onNotification(self, sender, method, data):

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':
Expand All @@ -201,49 +201,49 @@ def onNotification(self, sender, method, data):

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
})

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'),
Expand All @@ -262,7 +262,7 @@ def onNotification(self, sender, method, data):
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':
Expand All @@ -286,20 +286,20 @@ def server_instance(self, server_id=None):
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': (
Expand All @@ -316,7 +316,7 @@ def post_capabilities(self, server):
'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):
Expand All @@ -327,15 +327,15 @@ def additional_users(self, server):
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)

return

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))
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/objects/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion resources/lib/objects/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def trailer(self, obj):
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']:
Expand Down
8 changes: 4 additions & 4 deletions resources/lib/objects/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def artist_link(self, obj):
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)
Expand Down Expand Up @@ -318,7 +318,7 @@ def song_add(self, obj):
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)
Expand Down Expand Up @@ -373,7 +373,7 @@ def song_artist_discography(self, obj):
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)
Expand Down Expand Up @@ -407,7 +407,7 @@ def song_artist_link(self, obj):
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)
Expand Down
Loading