mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Cleanup __shortcuts__ in client.py and associated code (#66)
* client.py - remove "connected" * client.py - remove "config" & configuration.py - removed shortcuts and get/set item functions * client.py - remove "auth" & connection_manager.py - remove __shortcuts__ & __getitem__ * client.py - remove "auth" & connection_manager.py - remove __shortcuts__ & __getitem__ * client.py - remove "callback" * client.py - remove "websocket" and __getitem__ & ws_client.py - remove __shortcuts__ * Fix rebase mess-up
This commit is contained in:
parent
138451d516
commit
4049023559
19 changed files with 134 additions and 185 deletions
|
@ -81,9 +81,9 @@ class Connect(object):
|
||||||
''' Get Jellyfin client.
|
''' Get Jellyfin client.
|
||||||
'''
|
'''
|
||||||
client = Jellyfin(server_id)
|
client = Jellyfin(server_id)
|
||||||
client['config/app']("Kodi", self.info['Version'], self.info['DeviceName'], self.info['DeviceId'])
|
client.config.app("Kodi", self.info['Version'], self.info['DeviceName'], self.info['DeviceId'])
|
||||||
client['config']['http.user_agent'] = "Jellyfin-Kodi/%s" % self.info['Version']
|
client.config.data['http.user_agent'] = "Jellyfin-Kodi/%s" % self.info['Version']
|
||||||
client['config']['auth.ssl'] = self.get_ssl()
|
client.config.data['auth.ssl'] = self.get_ssl()
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class Connect(object):
|
||||||
self.connect_manager = client.auth
|
self.connect_manager = client.auth
|
||||||
|
|
||||||
if server_id is None:
|
if server_id is None:
|
||||||
client['config']['app.default'] = True
|
client.config.data['app.default'] = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
state = client.authenticate(credentials or {}, options or {})
|
state = client.authenticate(credentials or {}, options or {})
|
||||||
|
@ -107,8 +107,8 @@ class Connect(object):
|
||||||
client.callback = event
|
client.callback = event
|
||||||
self.get_user(client)
|
self.get_user(client)
|
||||||
|
|
||||||
settings('serverName', client['config/auth.server-name'])
|
settings('serverName', client.config.data['auth.server-name'])
|
||||||
settings('server', client['config/auth.server'])
|
settings('server', client.config.data['auth.server'])
|
||||||
|
|
||||||
event('ServerOnline', {'ServerId': server_id})
|
event('ServerOnline', {'ServerId': server_id})
|
||||||
event('LoadServer', {'ServerId': server_id})
|
event('LoadServer', {'ServerId': server_id})
|
||||||
|
@ -152,7 +152,9 @@ class Connect(object):
|
||||||
settings('username', self.user['Name'])
|
settings('username', self.user['Name'])
|
||||||
|
|
||||||
if 'PrimaryImageTag' in self.user:
|
if 'PrimaryImageTag' in self.user:
|
||||||
window('JellyfinUserImage', api.API(self.user, client['auth/server-address']).get_user_artwork(self.user['Id']))
|
server_data = client.auth.get_server_info(client.auth.server_id)
|
||||||
|
server_address = client.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
window('JellyfinUserImage', api.API(self.user, server_address).get_user_artwork(self.user['Id']))
|
||||||
|
|
||||||
def select_servers(self, state=None):
|
def select_servers(self, state=None):
|
||||||
|
|
||||||
|
@ -213,8 +215,9 @@ class Connect(object):
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
|
|
||||||
users = self.connect_manager['public-users']
|
users = self.connect_manager.get_public_users()
|
||||||
server = self.connect_manager['server-address']
|
server_data = self.connect_manager.get_server_info(self.connect_manager.server_id)
|
||||||
|
server = self.connect_manager.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
|
||||||
if not users:
|
if not users:
|
||||||
try:
|
try:
|
||||||
|
@ -236,7 +239,7 @@ class Connect(object):
|
||||||
return self.login_manual(username)
|
return self.login_manual(username)
|
||||||
except RuntimeError: pass
|
except RuntimeError: pass
|
||||||
else:
|
else:
|
||||||
return self.connect_manager['login'](server, username)
|
return self.connect_manager.login(server, username)
|
||||||
|
|
||||||
elif dialog.is_manual_login():
|
elif dialog.is_manual_login():
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -118,9 +118,10 @@ class LoginManual(xbmcgui.WindowXMLDialog):
|
||||||
|
|
||||||
def _login(self, username, password):
|
def _login(self, username, password):
|
||||||
|
|
||||||
mode = self.connect_manager['server-mode']
|
mode = self.connect_manager.get_server_info(self.connect_manager.server_id)['LastConnectionMode']
|
||||||
server = self.connect_manager['server-address']
|
server_data = self.connect_manager.get_server_info(self.connect_manager.server_id)
|
||||||
result = self.connect_manager['login'](server, username, password)
|
server = self.connect_manager.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
result = self.connect_manager.login(server, username, password)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
self._error(ERROR['Invalid'], _('invalid_auth'))
|
self._error(ERROR['Invalid'], _('invalid_auth'))
|
||||||
|
|
|
@ -116,7 +116,7 @@ class ServerConnect(xbmcgui.WindowXMLDialog):
|
||||||
self.message_box.setVisibleCondition('true')
|
self.message_box.setVisibleCondition('true')
|
||||||
self.busy.setVisibleCondition('true')
|
self.busy.setVisibleCondition('true')
|
||||||
|
|
||||||
result = self.connect_manager['connect-to-server'](server)
|
result = self.connect_manager.connect_to_server(server)
|
||||||
|
|
||||||
if result['State'] == CONNECTION_STATE['Unavailable']:
|
if result['State'] == CONNECTION_STATE['Unavailable']:
|
||||||
self.busy.setVisibleCondition('false')
|
self.busy.setVisibleCondition('false')
|
||||||
|
|
|
@ -118,7 +118,7 @@ class ServerManual(xbmcgui.WindowXMLDialog):
|
||||||
|
|
||||||
server_address = "%s:%s" % (server, port) if port else server
|
server_address = "%s:%s" % (server, port) if port else server
|
||||||
self._message("%s %s..." % (_(30610), server_address))
|
self._message("%s %s..." % (_(30610), server_address))
|
||||||
result = self.connect_manager['manual-server'](server_address)
|
result = self.connect_manager.connect_to_address(server_address)
|
||||||
|
|
||||||
if result['State'] == CONNECTION_STATE['Unavailable']:
|
if result['State'] == CONNECTION_STATE['Unavailable']:
|
||||||
self._message(_(30609))
|
self._message(_(30609))
|
||||||
|
|
|
@ -45,11 +45,11 @@ class Jellyfin(object):
|
||||||
|
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
|
|
||||||
Jellyfin('123456')['config/app']
|
Jellyfin('123456').config.data['app']
|
||||||
|
|
||||||
# Permanent client reference
|
# Permanent client reference
|
||||||
client = Jellyfin('123456').get_client()
|
client = Jellyfin('123456').get_client()
|
||||||
client['config/app']
|
client.config.data['app']
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Borg - multiple instances, shared state
|
# Borg - multiple instances, shared state
|
||||||
|
|
|
@ -55,7 +55,7 @@ class JellyfinClient(object):
|
||||||
|
|
||||||
LOG.info("User is authenticated.")
|
LOG.info("User is authenticated.")
|
||||||
self.logged_in = True
|
self.logged_in = True
|
||||||
self.callback("ServerOnline", {'Id': self['auth/server-id']})
|
self.callback("ServerOnline", {'Id': self.auth.server_id})
|
||||||
|
|
||||||
state['Credentials'] = self.get_credentials()
|
state['Credentials'] = self.get_credentials()
|
||||||
|
|
||||||
|
@ -81,23 +81,3 @@ class JellyfinClient(object):
|
||||||
|
|
||||||
self.wsc.stop_client()
|
self.wsc.stop_client()
|
||||||
self.http.stop_session()
|
self.http.stop_session()
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
LOG.debug("__getitem__(%r)", key)
|
|
||||||
|
|
||||||
if key.startswith('config'):
|
|
||||||
return self.config[key.replace('config/', "", 1)] if "/" in key else self.config
|
|
||||||
|
|
||||||
elif key.startswith('websocket'):
|
|
||||||
return self.wsc.__shortcuts__(key.replace('websocket/', "", 1))
|
|
||||||
|
|
||||||
elif key.startswith('callback'):
|
|
||||||
return self.callback_ws if 'ws' in key else self.callback
|
|
||||||
|
|
||||||
elif key.startswith('auth'):
|
|
||||||
return self.auth.__shortcuts__(key.replace('auth/', "", 1))
|
|
||||||
|
|
||||||
elif key == 'connected':
|
|
||||||
return self.logged_in
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
def jellyfin_url(client, handler):
|
def jellyfin_url(client, handler):
|
||||||
return "%s/emby/%s" % (client.config['auth.server'], handler)
|
return "%s/emby/%s" % (client.config.data['auth.server'], handler)
|
||||||
|
|
||||||
|
|
||||||
def basic_info():
|
def basic_info():
|
||||||
|
|
|
@ -25,27 +25,6 @@ class Config(object):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self.http()
|
self.http()
|
||||||
|
|
||||||
def __shortcuts__(self, key):
|
|
||||||
LOG.debug("__shortcuts__(%r)", key)
|
|
||||||
|
|
||||||
if key == "auth":
|
|
||||||
return self.auth
|
|
||||||
elif key == "app":
|
|
||||||
return self.app
|
|
||||||
elif key == "http":
|
|
||||||
return self.http
|
|
||||||
elif key == "data":
|
|
||||||
return self
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
LOG.debug("__getitem__(%r)", key)
|
|
||||||
return self.data.get(key, self.__shortcuts__(key))
|
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
|
||||||
self.data[key] = value
|
|
||||||
|
|
||||||
def app(self, name, version, device_name, device_id, capabilities=None, device_pixel_ratio=None):
|
def app(self, name, version, device_name, device_id, capabilities=None, device_pixel_ratio=None):
|
||||||
LOG.info("Begin app constructor.")
|
LOG.info("Begin app constructor.")
|
||||||
|
|
||||||
|
|
|
@ -57,48 +57,6 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
self.http = HTTP(client)
|
self.http = HTTP(client)
|
||||||
|
|
||||||
def __shortcuts__(self, key):
|
|
||||||
LOG.debug("__shortcuts__(%r)", key)
|
|
||||||
|
|
||||||
if key == "clear":
|
|
||||||
return self.clear_data
|
|
||||||
elif key == "servers":
|
|
||||||
return self.get_available_servers()
|
|
||||||
elif key in ("reconnect", "refresh"):
|
|
||||||
return self.connect
|
|
||||||
elif key == "login":
|
|
||||||
return self.login
|
|
||||||
elif key == "server":
|
|
||||||
return self.get_server_info(self.server_id)
|
|
||||||
elif key == "server-id":
|
|
||||||
return self.server_id
|
|
||||||
elif key == "server-version":
|
|
||||||
return self.server_version
|
|
||||||
elif key == "user-id":
|
|
||||||
return self.jellyfin_user_id()
|
|
||||||
elif key == "public-users":
|
|
||||||
return self.get_public_users()
|
|
||||||
elif key == "token":
|
|
||||||
return self.jellyfin_token()
|
|
||||||
elif key == "manual-server":
|
|
||||||
return self.connect_to_address
|
|
||||||
elif key == "connect-to-server":
|
|
||||||
return self.connect_to_server
|
|
||||||
elif key == "server-address":
|
|
||||||
server = self.get_server_info(self.server_id)
|
|
||||||
return get_server_address(server, server['LastConnectionMode'])
|
|
||||||
elif key == "revoke-token":
|
|
||||||
return self.revoke_token()
|
|
||||||
elif key == "server-mode":
|
|
||||||
server = self.get_server_info(self.server_id)
|
|
||||||
return server['LastConnectionMode']
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
LOG.debug("__getitem__(%r)", key)
|
|
||||||
return self.__shortcuts__(key)
|
|
||||||
|
|
||||||
def clear_data(self):
|
def clear_data(self):
|
||||||
|
|
||||||
LOG.info("connection manager clearing data")
|
LOG.info("connection manager clearing data")
|
||||||
|
@ -117,7 +75,7 @@ class ConnectionManager(object):
|
||||||
self['server']['AccessToken'] = None
|
self['server']['AccessToken'] = None
|
||||||
self.credentials.get_credentials(self.credentials.get_credentials())
|
self.credentials.get_credentials(self.credentials.get_credentials())
|
||||||
|
|
||||||
self.config['auth.token'] = None
|
self.config.data['auth.token'] = None
|
||||||
|
|
||||||
def get_available_servers(self):
|
def get_available_servers(self):
|
||||||
|
|
||||||
|
@ -151,7 +109,7 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
if not server:
|
if not server:
|
||||||
raise AttributeError("server cannot be empty")
|
raise AttributeError("server cannot be empty")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = {
|
request = {
|
||||||
'type': "POST",
|
'type': "POST",
|
||||||
|
@ -219,6 +177,14 @@ class ConnectionManager(object):
|
||||||
LOG.info("beginning connection tests")
|
LOG.info("beginning connection tests")
|
||||||
return self._test_next_connection_mode(tests, 0, server, options)
|
return self._test_next_connection_mode(tests, 0, server, options)
|
||||||
|
|
||||||
|
def get_server_address(self, server, mode): #TODO: De-duplicated (Duplicated from above when getting rid of shortcuts)
|
||||||
|
|
||||||
|
modes = {
|
||||||
|
CONNECTION_MODE['Local']: server.get('LocalAddress'),
|
||||||
|
CONNECTION_MODE['Manual']: server.get('ManualAddress')
|
||||||
|
}
|
||||||
|
return modes.get(mode) or server.get('ManualAddress', server.get('LocalAddress'))
|
||||||
|
|
||||||
def connect(self, options={}):
|
def connect(self, options={}):
|
||||||
|
|
||||||
LOG.info("Begin connect")
|
LOG.info("Begin connect")
|
||||||
|
@ -261,7 +227,7 @@ class ConnectionManager(object):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _add_app_info(self):
|
def _add_app_info(self):
|
||||||
return "%s/%s" % (self.config['app.name'], self.config['app.version'])
|
return "%s/%s" % (self.config.data['app.name'], self.config.data['app.version'])
|
||||||
|
|
||||||
def _get_headers(self, request):
|
def _get_headers(self, request):
|
||||||
|
|
||||||
|
@ -526,15 +492,15 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
if options.get('enableAutoLogin') == False:
|
if options.get('enableAutoLogin') == False:
|
||||||
|
|
||||||
self.config['auth.user_id'] = server.pop('UserId', None)
|
self.config.data['auth.user_id'] = server.pop('UserId', None)
|
||||||
self.config['auth.token'] = server.pop('AccessToken', None)
|
self.config.data['auth.token'] = server.pop('AccessToken', None)
|
||||||
|
|
||||||
elif verify_authentication and server.get('AccessToken'):
|
elif verify_authentication and server.get('AccessToken'):
|
||||||
|
|
||||||
if self._validate_authentication(server, connection_mode, options) is not False:
|
if self._validate_authentication(server, connection_mode, options) is not False:
|
||||||
|
|
||||||
self.config['auth.user_id'] = server['UserId']
|
self.config.data['auth.user_id'] = server['UserId']
|
||||||
self.config['auth.token'] = server['AccessToken']
|
self.config.data['auth.token'] = server['AccessToken']
|
||||||
return self._after_connect_validated(server, credentials, system_info, connection_mode, False, options)
|
return self._after_connect_validated(server, credentials, system_info, connection_mode, False, options)
|
||||||
|
|
||||||
return self._resolve_failure()
|
return self._resolve_failure()
|
||||||
|
@ -551,10 +517,10 @@ class ConnectionManager(object):
|
||||||
self.server_id = server['Id']
|
self.server_id = server['Id']
|
||||||
|
|
||||||
# Update configs
|
# Update configs
|
||||||
self.config['auth.server'] = get_server_address(server, connection_mode)
|
self.config.data['auth.server'] = get_server_address(server, connection_mode)
|
||||||
self.config['auth.server-name'] = server['Name']
|
self.config.data['auth.server-name'] = server['Name']
|
||||||
self.config['auth.server=id'] = server['Id']
|
self.config.data['auth.server=id'] = server['Id']
|
||||||
self.config['auth.ssl'] = options.get('ssl', self.config['auth.ssl'])
|
self.config.data['auth.ssl'] = options.get('ssl', self.config.data['auth.ssl'])
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
'Servers': [server]
|
'Servers': [server]
|
||||||
|
@ -602,8 +568,8 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
credentials = self.credentials.get_credentials()
|
credentials = self.credentials.get_credentials()
|
||||||
|
|
||||||
self.config['auth.user_id'] = result['User']['Id']
|
self.config.data['auth.user_id'] = result['User']['Id']
|
||||||
self.config['auth.token'] = result['AccessToken']
|
self.config.data['auth.token'] = result['AccessToken']
|
||||||
|
|
||||||
for server in credentials['Servers']:
|
for server in credentials['Servers']:
|
||||||
if server['Id'] == result['ServerId']:
|
if server['Id'] == result['ServerId']:
|
||||||
|
|
|
@ -24,13 +24,13 @@ class HTTP(object):
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
|
|
||||||
self.client = client
|
self.client = client
|
||||||
self.config = client['config']
|
self.config = client.config
|
||||||
|
|
||||||
def start_session(self):
|
def start_session(self):
|
||||||
|
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
|
|
||||||
max_retries = self.config['http.max_retries']
|
max_retries = self.config.data['http.max_retries']
|
||||||
self.session.mount("http://", requests.adapters.HTTPAdapter(max_retries=max_retries))
|
self.session.mount("http://", requests.adapters.HTTPAdapter(max_retries=max_retries))
|
||||||
self.session.mount("https://", requests.adapters.HTTPAdapter(max_retries=max_retries))
|
self.session.mount("https://", requests.adapters.HTTPAdapter(max_retries=max_retries))
|
||||||
|
|
||||||
|
@ -48,14 +48,14 @@ class HTTP(object):
|
||||||
def _replace_user_info(self, string):
|
def _replace_user_info(self, string):
|
||||||
|
|
||||||
if '{server}' in string:
|
if '{server}' in string:
|
||||||
if self.config['auth.server']:
|
if self.config.data['auth.server']:
|
||||||
string = string.decode('utf-8').replace("{server}", self.config['auth.server'])
|
string = string.decode('utf-8').replace("{server}", self.config.data['auth.server'])
|
||||||
else:
|
else:
|
||||||
raise Exception("Server address not set.")
|
raise Exception("Server address not set.")
|
||||||
|
|
||||||
if '{UserId}'in string:
|
if '{UserId}'in string:
|
||||||
if self.config['auth.user_id']:
|
if self.config.data['auth.user_id']:
|
||||||
string = string.decode('utf-8').replace("{UserId}", self.config['auth.user_id'])
|
string = string.decode('utf-8').replace("{UserId}", self.config.data['auth.user_id'])
|
||||||
else:
|
else:
|
||||||
raise Exception("UserId is not set.")
|
raise Exception("UserId is not set.")
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class HTTP(object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
LOG.error(error)
|
LOG.error(error)
|
||||||
self.client['callback']("ServerUnreachable", {'ServerId': self.config['auth.server-id']})
|
self.client.callback("ServerUnreachable", {'ServerId': self.config.data['auth.server-id']})
|
||||||
|
|
||||||
raise HTTPException("ServerUnreachable", error)
|
raise HTTPException("ServerUnreachable", error)
|
||||||
|
|
||||||
|
@ -122,12 +122,12 @@ class HTTP(object):
|
||||||
if r.status_code == 401:
|
if r.status_code == 401:
|
||||||
|
|
||||||
if 'X-Application-Error-Code' in r.headers:
|
if 'X-Application-Error-Code' in r.headers:
|
||||||
self.client['callback']("AccessRestricted", {'ServerId': self.config['auth.server-id']})
|
self.client.callback("AccessRestricted", {'ServerId': self.config.data['auth.server-id']})
|
||||||
|
|
||||||
raise HTTPException("AccessRestricted", error)
|
raise HTTPException("AccessRestricted", error)
|
||||||
else:
|
else:
|
||||||
self.client['callback']("Unauthorized", {'ServerId': self.config['auth.server-id']})
|
self.client.callback("Unauthorized", {'ServerId': self.config.data['auth.server-id']})
|
||||||
self.client['auth/revoke-token']
|
self.client.auth.revoke_token()
|
||||||
|
|
||||||
raise HTTPException("Unauthorized", error)
|
raise HTTPException("Unauthorized", error)
|
||||||
|
|
||||||
|
@ -147,14 +147,14 @@ class HTTP(object):
|
||||||
raise HTTPException(r.status_code, error)
|
raise HTTPException(r.status_code, error)
|
||||||
|
|
||||||
except requests.exceptions.MissingSchema as error:
|
except requests.exceptions.MissingSchema as error:
|
||||||
raise HTTPException("MissingSchema", {'Id': self.config['auth.server']})
|
raise HTTPException("MissingSchema", {'Id': self.config.data['auth.server']})
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.config['server-time'] = r.headers['Date']
|
self.config.data['server-time'] = r.headers['Date']
|
||||||
elapsed = int(r.elapsed.total_seconds() * 1000)
|
elapsed = int(r.elapsed.total_seconds() * 1000)
|
||||||
response = r.json()
|
response = r.json()
|
||||||
LOG.debug("---<[ http ][%s ms]", elapsed)
|
LOG.debug("---<[ http ][%s ms]", elapsed)
|
||||||
|
@ -167,11 +167,11 @@ class HTTP(object):
|
||||||
def _request(self, data):
|
def _request(self, data):
|
||||||
|
|
||||||
if 'url' not in data:
|
if 'url' not in data:
|
||||||
data['url'] = "%s/emby/%s" % (self.config['auth.server'], data.pop('handler', ""))
|
data['url'] = "%s/emby/%s" % (self.config.data['auth.server'], data.pop('handler', ""))
|
||||||
|
|
||||||
self._get_header(data)
|
self._get_header(data)
|
||||||
data['timeout'] = data.get('timeout') or self.config['http.timeout']
|
data['timeout'] = data.get('timeout') or self.config.data['http.timeout']
|
||||||
data['verify'] = data.get('verify') or self.config['auth.ssl'] or False
|
data['verify'] = data.get('verify') or self.config.data['auth.ssl'] or False
|
||||||
data['url'] = self._replace_user_info(data['url'])
|
data['url'] = self._replace_user_info(data['url'])
|
||||||
self._process_params(data.get('params') or {})
|
self._process_params(data.get('params') or {})
|
||||||
self._process_params(data.get('json') or {})
|
self._process_params(data.get('json') or {})
|
||||||
|
@ -198,7 +198,7 @@ class HTTP(object):
|
||||||
'Content-type': "application/json",
|
'Content-type': "application/json",
|
||||||
'Accept-Charset': "UTF-8,*",
|
'Accept-Charset': "UTF-8,*",
|
||||||
'Accept-encoding': "gzip",
|
'Accept-encoding': "gzip",
|
||||||
'User-Agent': self.config['http.user_agent'] or "%s/%s" % (self.config['app.name'], self.config['app.version'])
|
'User-Agent': self.config.data['http.user_agent'] or "%s/%s" % (self.config.data['app.name'], self.config.data['app.version'])
|
||||||
})
|
})
|
||||||
|
|
||||||
if 'x-emby-authorization' not in data['headers']:
|
if 'x-emby-authorization' not in data['headers']:
|
||||||
|
@ -209,17 +209,17 @@ class HTTP(object):
|
||||||
def _authorization(self, data):
|
def _authorization(self, data):
|
||||||
|
|
||||||
auth = "MediaBrowser "
|
auth = "MediaBrowser "
|
||||||
auth += "Client=%s, " % self.config['app.name'].encode('utf-8')
|
auth += "Client=%s, " % self.config.data['app.name'].encode('utf-8')
|
||||||
auth += "Device=%s, " % self.config['app.device_name'].encode('utf-8')
|
auth += "Device=%s, " % self.config.data['app.device_name'].encode('utf-8')
|
||||||
auth += "DeviceId=%s, " % self.config['app.device_id'].encode('utf-8')
|
auth += "DeviceId=%s, " % self.config.data['app.device_id'].encode('utf-8')
|
||||||
auth += "Version=%s" % self.config['app.version'].encode('utf-8')
|
auth += "Version=%s" % self.config.data['app.version'].encode('utf-8')
|
||||||
|
|
||||||
data['headers'].update({'x-emby-authorization': auth})
|
data['headers'].update({'x-emby-authorization': auth})
|
||||||
|
|
||||||
if self.config['auth.token'] and self.config['auth.user_id']:
|
if self.config.data.get('auth.token') and self.config.data.get('auth.user_id'):
|
||||||
|
|
||||||
auth += ', UserId=%s' % self.config['auth.user_id'].encode('utf-8')
|
auth += ', UserId=%s' % self.config.data['auth.user_id'].encode('utf-8')
|
||||||
data['headers'].update({'x-emby-authorization': auth, 'X-MediaBrowser-Token': self.config['auth.token'].encode('utf-8')})
|
data['headers'].update({'x-emby-authorization': auth, 'X-MediaBrowser-Token': self.config.data['auth.token'].encode('utf-8')})
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -30,16 +30,6 @@ class WSClient(threading.Thread):
|
||||||
self.client = client
|
self.client = client
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def __shortcuts__(self, key):
|
|
||||||
LOG.debug("__shortcuts__(%r)", key)
|
|
||||||
|
|
||||||
if key == "send":
|
|
||||||
return self.send
|
|
||||||
elif key == "stop":
|
|
||||||
return self.stop_client()
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def send(self, message, data=""):
|
def send(self, message, data=""):
|
||||||
|
|
||||||
if self.wsc is None:
|
if self.wsc is None:
|
||||||
|
@ -50,9 +40,9 @@ class WSClient(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
monitor = xbmc.Monitor()
|
monitor = xbmc.Monitor()
|
||||||
token = self.client['config/auth.token']
|
token = self.client.config.data['auth.token']
|
||||||
device_id = self.client['config/app.device_id']
|
device_id = self.client.config.data['app.device_id']
|
||||||
server = self.client['config/auth.server']
|
server = self.client.config.data['auth.server']
|
||||||
server = server.replace('https', "wss") if server.startswith('https') else server.replace('http', "ws")
|
server = server.replace('https', "wss") if server.startswith('https') else server.replace('http', "ws")
|
||||||
wsc_url = "%s/embywebsocket?api_key=%s&device_id=%s" % (server, token, device_id)
|
wsc_url = "%s/embywebsocket?api_key=%s&device_id=%s" % (server, token, device_id)
|
||||||
|
|
||||||
|
@ -88,10 +78,10 @@ class WSClient(threading.Thread):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.client['config/app.default']:
|
if not self.client.config.data['app.default']:
|
||||||
data['ServerId'] = self.client['auth/server-id']
|
data['ServerId'] = self.client.auth.server_id
|
||||||
|
|
||||||
self.client['callback_ws'](message['MessageType'], data)
|
self.client.callback(message['MessageType'], data)
|
||||||
|
|
||||||
def stop_client(self):
|
def stop_client(self):
|
||||||
|
|
||||||
|
|
|
@ -456,7 +456,7 @@ class Library(threading.Thread):
|
||||||
def save_last_sync(self):
|
def save_last_sync(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
time_now = datetime.strptime(self.server['config/server-time'].split(', ', 1)[1], '%d %b %Y %H:%M:%S GMT') - timedelta(minutes=2)
|
time_now = datetime.strptime(self.server.config.data['server-time'].split(', ', 1)[1], '%d %b %Y %H:%M:%S GMT') - timedelta(minutes=2)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
|
||||||
LOG.exception(error)
|
LOG.exception(error)
|
||||||
|
|
|
@ -144,8 +144,9 @@ class Monitor(xbmc.Monitor):
|
||||||
self.void_responder(data, item)
|
self.void_responder(data, item)
|
||||||
|
|
||||||
elif method == 'GetServerAddress':
|
elif method == 'GetServerAddress':
|
||||||
|
|
||||||
server_address = server['auth/server-address']
|
server_data = server.auth.get_server_info(server.auth.server_id)
|
||||||
|
server_address = server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
self.void_responder(data, server_address)
|
self.void_responder(data, server_address)
|
||||||
|
|
||||||
elif method == 'GetPlaybackInfo':
|
elif method == 'GetPlaybackInfo':
|
||||||
|
@ -160,7 +161,7 @@ class Monitor(xbmc.Monitor):
|
||||||
|
|
||||||
elif method == 'GetToken':
|
elif method == 'GetToken':
|
||||||
|
|
||||||
token = server['auth/token']
|
token = server.auth.jellyfin_token()
|
||||||
self.void_responder(data, token)
|
self.void_responder(data, token)
|
||||||
|
|
||||||
elif method == 'GetSession':
|
elif method == 'GetSession':
|
||||||
|
@ -235,7 +236,7 @@ class Monitor(xbmc.Monitor):
|
||||||
|
|
||||||
elif method == 'PlayPlaylist':
|
elif method == 'PlayPlaylist':
|
||||||
|
|
||||||
server.jellyfin.post_session(server['config/app.session'], "Playing", {
|
server.jellyfin.post_session(server.config.data['app.session'], "Playing", {
|
||||||
'PlayCommand': "PlayNow",
|
'PlayCommand': "PlayNow",
|
||||||
'ItemIds': data['Id'],
|
'ItemIds': data['Id'],
|
||||||
'StartPositionTicks': 0
|
'StartPositionTicks': 0
|
||||||
|
@ -262,7 +263,7 @@ class Monitor(xbmc.Monitor):
|
||||||
self.server_instance(data['ServerId'])
|
self.server_instance(data['ServerId'])
|
||||||
|
|
||||||
elif method == 'AddUser':
|
elif method == 'AddUser':
|
||||||
server.jellyfin.session_add_user(server['config/app.session'], data['Id'], data['Add'])
|
server.jellyfin.session_add_user(server.config.data['app.session'], data['Id'], data['Add'])
|
||||||
self.additional_users(server)
|
self.additional_users(server)
|
||||||
|
|
||||||
elif method == 'Player.OnPlay':
|
elif method == 'Player.OnPlay':
|
||||||
|
@ -292,12 +293,12 @@ class Monitor(xbmc.Monitor):
|
||||||
for user in all_users:
|
for user in all_users:
|
||||||
|
|
||||||
if user['Name'].lower() in additional.decode('utf-8').lower():
|
if user['Name'].lower() in additional.decode('utf-8').lower():
|
||||||
server.jellyfin.session_add_user(server['config/app.session'], user['Id'], True)
|
server.jellyfin.session_add_user(server.config.data['app.session'], user['Id'], True)
|
||||||
|
|
||||||
self.additional_users(server)
|
self.additional_users(server)
|
||||||
|
|
||||||
def post_capabilities(self, server):
|
def post_capabilities(self, server):
|
||||||
LOG.info("--[ post capabilities/%s ]", server['auth/server-id'])
|
LOG.info("--[ post capabilities/%s ]", server.auth.server_id)
|
||||||
|
|
||||||
server.jellyfin.post_capabilities({
|
server.jellyfin.post_capabilities({
|
||||||
'PlayableMediaTypes': "Audio,Video",
|
'PlayableMediaTypes': "Audio,Video",
|
||||||
|
@ -314,9 +315,8 @@ class Monitor(xbmc.Monitor):
|
||||||
"Play,Playstate,PlayNext,PlayMediaSource"
|
"Play,Playstate,PlayNext,PlayMediaSource"
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
session = server.jellyfin.get_device(self.device_id)
|
session = server.jellyfin.get_device(self.device_id)
|
||||||
server['config']['app.session'] = session[0]['Id']
|
server.config.data['app.session'] = session[0]['Id']
|
||||||
|
|
||||||
def additional_users(self, server):
|
def additional_users(self, server):
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ class Monitor(xbmc.Monitor):
|
||||||
for index, user in enumerate(session[0]['AdditionalUsers']):
|
for index, user in enumerate(session[0]['AdditionalUsers']):
|
||||||
|
|
||||||
info = server.jellyfin.get_user(user['UserId'])
|
info = server.jellyfin.get_user(user['UserId'])
|
||||||
image = api.API(info, server['config/auth.server']).get_user_artwork(user['UserId'])
|
image = api.API(info, server.config.data['auth.server']).get_user_artwork(user['UserId'])
|
||||||
window('JellyfinAdditionalUserImage.%s' % index, image)
|
window('JellyfinAdditionalUserImage.%s' % index, image)
|
||||||
window('JellyfinAdditionalUserPosition.%s' % user['UserId'], str(index))
|
window('JellyfinAdditionalUserPosition.%s' % user['UserId'], str(index))
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,9 @@ class Movies(KodiDb):
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
If item exists, entry will be updated.
|
If item exists, entry will be updated.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Movie')
|
obj = self.objects.map(item, 'Movie')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -213,7 +215,9 @@ class Movies(KodiDb):
|
||||||
Process movies inside boxset.
|
Process movies inside boxset.
|
||||||
Process removals from boxset.
|
Process removals from boxset.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Boxset')
|
obj = self.objects.map(item, 'Boxset')
|
||||||
|
|
||||||
obj['Overview'] = API.get_overview(obj['Overview'])
|
obj['Overview'] = API.get_overview(obj['Overview'])
|
||||||
|
@ -291,7 +295,9 @@ class Movies(KodiDb):
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
Poster with progress bar
|
Poster with progress bar
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'MovieUserData')
|
obj = self.objects.map(item, 'MovieUserData')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -56,7 +56,9 @@ class Music(KodiDb):
|
||||||
''' If item does not exist, entry will be added.
|
''' If item does not exist, entry will be added.
|
||||||
If item exists, entry will be updated.
|
If item exists, entry will be updated.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Artist')
|
obj = self.objects.map(item, 'Artist')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -125,7 +127,9 @@ class Music(KodiDb):
|
||||||
|
|
||||||
''' Update object to kodi.
|
''' Update object to kodi.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Album')
|
obj = self.objects.map(item, 'Album')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -234,7 +238,9 @@ class Music(KodiDb):
|
||||||
|
|
||||||
''' Update object to kodi.
|
''' Update object to kodi.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Song')
|
obj = self.objects.map(item, 'Song')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -352,7 +358,9 @@ class Music(KodiDb):
|
||||||
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
|
obj['Path'] = obj['Path'].replace(obj['Filename'], "")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj['Path'] = "%s/emby/Audio/%s/" % (self.server['auth/server-address'], obj['Id'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
obj['Path'] = "%s/emby/Audio/%s/" % (server_address, obj['Id'])
|
||||||
obj['Filename'] = "stream.%s?static=true" % obj['Container']
|
obj['Filename'] = "stream.%s?static=true" % obj['Container']
|
||||||
|
|
||||||
def song_artist_discography(self, obj):
|
def song_artist_discography(self, obj):
|
||||||
|
@ -429,7 +437,9 @@ class Music(KodiDb):
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
Poster with progress bar
|
Poster with progress bar
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'SongUserData')
|
obj = self.objects.map(item, 'SongUserData')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -55,7 +55,9 @@ class MusicVideos(KodiDb):
|
||||||
If we don't get the track number from Jellyfin, see if we can infer it
|
If we don't get the track number from Jellyfin, see if we can infer it
|
||||||
from the sortname attribute.
|
from the sortname attribute.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'MusicVideo')
|
obj = self.objects.map(item, 'MusicVideo')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -192,7 +194,9 @@ class MusicVideos(KodiDb):
|
||||||
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
''' This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
Poster with progress bar
|
Poster with progress bar
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'MusicVideoUserData')
|
obj = self.objects.map(item, 'MusicVideoUserData')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -63,7 +63,9 @@ class TVShows(KodiDb):
|
||||||
Process seasons.
|
Process seasons.
|
||||||
Apply series pooling.
|
Apply series pooling.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Series')
|
obj = self.objects.map(item, 'Series')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -230,7 +232,9 @@ class TVShows(KodiDb):
|
||||||
|
|
||||||
If the show is empty, try to remove it.
|
If the show is empty, try to remove it.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Season')
|
obj = self.objects.map(item, 'Season')
|
||||||
|
|
||||||
obj['ShowId'] = show_id
|
obj['ShowId'] = show_id
|
||||||
|
@ -265,7 +269,9 @@ class TVShows(KodiDb):
|
||||||
Create additional entry for widgets.
|
Create additional entry for widgets.
|
||||||
This is only required for plugin/episode.
|
This is only required for plugin/episode.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'Episode')
|
obj = self.objects.map(item, 'Episode')
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
|
@ -459,7 +465,9 @@ class TVShows(KodiDb):
|
||||||
Make sure there's no other bookmarks created by widget.
|
Make sure there's no other bookmarks created by widget.
|
||||||
Create additional entry for widgets. This is only required for plugin/episode.
|
Create additional entry for widgets. This is only required for plugin/episode.
|
||||||
'''
|
'''
|
||||||
API = api.API(item, self.server['auth/server-address'])
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(item, server_address)
|
||||||
obj = self.objects.map(item, 'EpisodeUserData')
|
obj = self.objects.map(item, 'EpisodeUserData')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -252,8 +252,9 @@ class Player(xbmc.Player):
|
||||||
return
|
return
|
||||||
|
|
||||||
break
|
break
|
||||||
|
server_data = item['Server'].auth.get_server_info(item['Server'].auth.server_id)
|
||||||
API = api.API(next_item, item['Server']['auth/server-address'])
|
server_address = item['Server'].auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
API = api.API(next_item, server_address)
|
||||||
data = objects.map(next_item, "UpNext")
|
data = objects.map(next_item, "UpNext")
|
||||||
artwork = API.get_all_artwork(objects.map(next_item, 'ArtworkParent'), True)
|
artwork = API.get_all_artwork(objects.map(next_item, 'ArtworkParent'), True)
|
||||||
data['art'] = {
|
data['art'] = {
|
||||||
|
|
|
@ -856,15 +856,16 @@ class Views(object):
|
||||||
|
|
||||||
def window_artwork(self, prop, view_id):
|
def window_artwork(self, prop, view_id):
|
||||||
|
|
||||||
if not self.server['connected']:
|
if not self.server.logged_in:
|
||||||
window('%s.artwork' % prop, clear=True)
|
window('%s.artwork' % prop, clear=True)
|
||||||
|
|
||||||
elif self.server['connected'] and self.media_folders is not None:
|
elif self.server.logged_in and 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', {}):
|
||||||
|
server_data = self.server.auth.get_server_info(self.server.auth.server_id)
|
||||||
artwork = api.API(None, self.server['auth/server-address']).get_artwork(view_id, 'Primary')
|
server_address = self.server.auth.get_server_address(server_data, server_data['LastConnectionMode'])
|
||||||
|
artwork = api.API(None, server_address).get_artwork(view_id, 'Primary')
|
||||||
window('%s.artwork' % prop, artwork)
|
window('%s.artwork' % prop, artwork)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue