mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Remove more Connect
This commit is contained in:
parent
481ee11301
commit
647636430f
6 changed files with 8 additions and 199 deletions
|
@ -115,7 +115,7 @@ class Connect(object):
|
|||
|
||||
return state['Credentials']
|
||||
|
||||
elif (server_selection or state['State'] in (CONNECTION_STATE['ConnectSignIn'], CONNECTION_STATE['ServerSelection']) or
|
||||
elif (server_selection or state['State'] == CONNECTION_STATE['ServerSelection'] or
|
||||
state['State'] == CONNECTION_STATE['Unavailable'] and not settings('SyncInstallRunDone.bool')):
|
||||
|
||||
self.select_servers(state)
|
||||
|
@ -157,7 +157,7 @@ class Connect(object):
|
|||
def select_servers(self, state=None):
|
||||
|
||||
state = state or self.connect_manager.connect({'enableAutoLogin': False})
|
||||
user = state.get('ConnectUser') or {}
|
||||
user = {}
|
||||
|
||||
dialog = ServerConnect("script-jellyfin-connect-server.xml", *XML_PATH)
|
||||
dialog.set_args(**{
|
||||
|
|
|
@ -54,13 +54,9 @@ class ServerConnect(xbmcgui.WindowXMLDialog):
|
|||
def get_server(self):
|
||||
return self._selected_server
|
||||
|
||||
def is_connect_login(self):
|
||||
return self._connect_login
|
||||
|
||||
def is_manual_server(self):
|
||||
return self._manual_server
|
||||
|
||||
|
||||
def onInit(self):
|
||||
|
||||
self.message = self.getControl(MESSAGE)
|
||||
|
|
|
@ -34,7 +34,7 @@ class UsersConnect(xbmcgui.WindowXMLDialog):
|
|||
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
|
||||
|
||||
def set_args(self, **kwargs):
|
||||
# connect_manager, user_image, servers, jellyfin_connect
|
||||
# connect_manager, user_image, servers
|
||||
for key, value in kwargs.iteritems():
|
||||
setattr(self, key, value)
|
||||
|
||||
|
@ -47,7 +47,6 @@ class UsersConnect(xbmcgui.WindowXMLDialog):
|
|||
def is_manual_login(self):
|
||||
return self._manual_login
|
||||
|
||||
|
||||
def onInit(self):
|
||||
|
||||
self.list_ = self.getControl(LIST)
|
||||
|
|
|
@ -20,7 +20,6 @@ CONNECTION_STATE = {
|
|||
'ServerSelection': 1,
|
||||
'ServerSignIn': 2,
|
||||
'SignedIn': 3,
|
||||
'ConnectSignIn': 4,
|
||||
'ServerUpdateNeeded': 5
|
||||
}
|
||||
CONNECTION_MODE = {
|
||||
|
@ -69,12 +68,6 @@ class ConnectionManager(object):
|
|||
return self.connect
|
||||
elif key == "login":
|
||||
return self.login
|
||||
elif key == "connect-user":
|
||||
return self.connect_user()
|
||||
elif key == "connect-token":
|
||||
return self.connect_token()
|
||||
elif key == "connect-user-id":
|
||||
return self.connect_user_id()
|
||||
elif key == "server":
|
||||
return self.get_server_info(self.server_id)
|
||||
elif key == "server-id":
|
||||
|
@ -111,8 +104,6 @@ class ConnectionManager(object):
|
|||
|
||||
self.user = None
|
||||
credentials = self.credentials.get_credentials()
|
||||
credentials['ConnectAccessToken'] = None
|
||||
credentials['ConnectUserId'] = None
|
||||
credentials['Servers'] = list()
|
||||
self.credentials.get_credentials(credentials)
|
||||
|
||||
|
@ -133,19 +124,14 @@ class ConnectionManager(object):
|
|||
|
||||
# Clone the credentials
|
||||
credentials = self.credentials.get_credentials()
|
||||
connect_servers = self._get_connect_servers(credentials)
|
||||
found_servers = self._find_servers(self._server_discovery())
|
||||
|
||||
if not connect_servers and not found_servers and not credentials['Servers']: # back out right away, no point in continuing
|
||||
if not found_servers and not credentials['Servers']: # back out right away, no point in continuing
|
||||
LOG.info("Found no servers")
|
||||
|
||||
return list()
|
||||
|
||||
servers = list(credentials['Servers'])
|
||||
self._merge_servers(servers, found_servers)
|
||||
self._merge_servers(servers, connect_servers)
|
||||
|
||||
servers = self._filter_servers(servers, connect_servers)
|
||||
|
||||
try:
|
||||
servers.sort(key=lambda x: datetime.strptime(x['DateLastAccessed'], "%Y-%m-%dT%H:%M:%SZ"), reverse=True)
|
||||
|
@ -240,15 +226,6 @@ class ConnectionManager(object):
|
|||
LOG.info("Begin connect")
|
||||
return self._connect_to_servers(self.get_available_servers(), options)
|
||||
|
||||
def connect_user(self):
|
||||
return self.user
|
||||
|
||||
def connect_user_id(self):
|
||||
return self.credentials.get_credentials().get('ConnectUserId')
|
||||
|
||||
def connect_token(self):
|
||||
return self.credentials.get_credentials().get('ConnectAccessToken')
|
||||
|
||||
def emby_user_id(self):
|
||||
return self.get_server_info(self.server_id)['UserId']
|
||||
|
||||
|
@ -270,9 +247,6 @@ class ConnectionManager(object):
|
|||
def get_public_users(self):
|
||||
return self.client.emby.get_public_users()
|
||||
|
||||
def get_connect_url(self, handler):
|
||||
return "https://connect.emby.media/service/%s" % handler
|
||||
|
||||
def get_emby_url(self, base, handler):
|
||||
return "%s/emby/%s" % (base, handler)
|
||||
|
||||
|
@ -310,12 +284,6 @@ class ConnectionManager(object):
|
|||
|
||||
if len(servers) == 1:
|
||||
result = self.connect_to_server(servers[0], options)
|
||||
|
||||
"""
|
||||
if result['State'] == CONNECTION_STATE['Unavailable']:
|
||||
result['State'] = CONNECTION_STATE['ConnectSignIn'] if result['ConnectUser'] is None else CONNECTION_STATE['ServerSelection']
|
||||
"""
|
||||
|
||||
LOG.debug("resolving connectToServers with result['State']: %s", result)
|
||||
|
||||
return result
|
||||
|
@ -330,12 +298,10 @@ class ConnectionManager(object):
|
|||
|
||||
# Return loaded credentials if exists
|
||||
credentials = self.credentials.get_credentials()
|
||||
self._ensure_connect_user(credentials)
|
||||
|
||||
return {
|
||||
'Servers': servers,
|
||||
'State': CONNECTION_STATE['ConnectSignIn'] if (not len(servers) and not self.connect_user()) else (result.get('State') or CONNECTION_STATE['ServerSelection']),
|
||||
'ConnectUser': self.connect_user()
|
||||
'State': result.get('State') or CONNECTION_STATE['ServerSelection'],
|
||||
}
|
||||
|
||||
def _try_connect(self, url, timeout=None, options={}):
|
||||
|
@ -408,20 +374,11 @@ class ConnectionManager(object):
|
|||
def _on_successful_connection(self, server, system_info, connection_mode, options):
|
||||
|
||||
credentials = self.credentials.get_credentials()
|
||||
|
||||
if credentials.get('ConnectAccessToken') and options.get('enableAutoLogin') is not False:
|
||||
|
||||
if self._ensure_connect_user(credentials) is not False:
|
||||
|
||||
if server.get('ExchangeToken'):
|
||||
self._add_authentication_info_from_connect(server, connection_mode, credentials, options)
|
||||
|
||||
return self._after_connect_validated(server, credentials, system_info, connection_mode, True, options)
|
||||
|
||||
def _resolve_failure(self):
|
||||
return {
|
||||
'State': CONNECTION_STATE['Unavailable'],
|
||||
'ConnectUser': self.connect_user()
|
||||
'State': CONNECTION_STATE['Unavailable']
|
||||
}
|
||||
|
||||
def _get_min_server_version(self, val=None):
|
||||
|
@ -462,23 +419,6 @@ class ConnectionManager(object):
|
|||
def _string_equals_ignore_case(self, str1, str2):
|
||||
return (str1 or "").lower() == (str2 or "").lower()
|
||||
|
||||
def _get_connect_user(self, user_id, access_token):
|
||||
|
||||
if not user_id:
|
||||
raise AttributeError("null userId")
|
||||
|
||||
if not access_token:
|
||||
raise AttributeError("null accessToken")
|
||||
|
||||
return self._request_url({
|
||||
'type': "GET",
|
||||
'url': self.get_connect_url('user?id=%s' % user_id),
|
||||
'dataType': "json",
|
||||
'headers': {
|
||||
'X-Connect-UserToken': access_token
|
||||
}
|
||||
})
|
||||
|
||||
def _server_discovery(self):
|
||||
|
||||
MULTI_GROUP = ("<broadcast>", 7359)
|
||||
|
@ -516,37 +456,6 @@ class ConnectionManager(object):
|
|||
LOG.error("Error trying to find servers: %s", e)
|
||||
return servers
|
||||
|
||||
def _get_connect_servers(self, credentials):
|
||||
|
||||
LOG.info("Begin getConnectServers")
|
||||
|
||||
servers = list()
|
||||
|
||||
if not credentials.get('ConnectAccessToken') or not credentials.get('ConnectUserId'):
|
||||
return servers
|
||||
|
||||
url = self.get_connect_url("servers?userId=%s" % credentials['ConnectUserId'])
|
||||
request = {
|
||||
'type': "GET",
|
||||
'url': url,
|
||||
'dataType': "json",
|
||||
'headers': {
|
||||
'X-Connect-UserToken': credentials['ConnectAccessToken']
|
||||
}
|
||||
}
|
||||
for server in self._request_url(request):
|
||||
servers.append({
|
||||
'ExchangeToken': server['AccessKey'],
|
||||
'ConnectServerId': server['Id'],
|
||||
'Id': server['SystemId'],
|
||||
'Name': server['Name'],
|
||||
'RemoteAddress': server['Url'],
|
||||
'LocalAddress': server['LocalAddress'],
|
||||
'UserLinkType': "Guest" if server['UserType'].lower() == "guest" else "LinkedUser",
|
||||
})
|
||||
|
||||
return servers
|
||||
|
||||
def _get_last_used_server(self):
|
||||
|
||||
servers = self.credentials.get_credentials()['Servers']
|
||||
|
@ -590,22 +499,6 @@ class ConnectionManager(object):
|
|||
else:
|
||||
return servers
|
||||
|
||||
def _filter_servers(self, servers, connect_servers):
|
||||
|
||||
filtered = list()
|
||||
for server in servers:
|
||||
if server.get('ExchangeToken') is None:
|
||||
# It's not a connect server, so assume it's still valid
|
||||
filtered.append(server)
|
||||
continue
|
||||
|
||||
for connect_server in connect_servers:
|
||||
if server['Id'] == connect_server['Id']:
|
||||
filtered.append(server)
|
||||
break
|
||||
|
||||
return filtered
|
||||
|
||||
def _convert_endpoint_address_to_manual_address(self, info):
|
||||
|
||||
if info.get('Address') and info.get('EndpointAddress'):
|
||||
|
@ -634,45 +527,6 @@ class ConnectionManager(object):
|
|||
|
||||
return address
|
||||
|
||||
def _get_connect_password_hash(self, password):
|
||||
|
||||
password = self._clean_connect_password(password)
|
||||
return hashlib.md5(password).hexdigest()
|
||||
|
||||
def _clean_connect_password(self, password):
|
||||
|
||||
password = password or ""
|
||||
|
||||
password = password.replace("&", '&')
|
||||
password = password.replace("/", '\')
|
||||
password = password.replace("!", '!')
|
||||
password = password.replace("$", '$')
|
||||
password = password.replace("\"", '"')
|
||||
password = password.replace("<", '<')
|
||||
password = password.replace(">", '>')
|
||||
password = password.replace("'", ''')
|
||||
|
||||
return password
|
||||
|
||||
def _ensure_connect_user(self, credentials):
|
||||
|
||||
if self.user and self.user['Id'] == credentials['ConnectUserId']:
|
||||
return
|
||||
|
||||
elif credentials.get('ConnectUserId') and credentials.get('ConnectAccessToken'):
|
||||
self.user = None
|
||||
|
||||
try:
|
||||
result = self._get_connect_user(credentials['ConnectUserId'], credentials['ConnectAccessToken'])
|
||||
self._on_connect_user_signin(result)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _on_connect_user_signin(self, user):
|
||||
|
||||
self.user = user
|
||||
LOG.info("connectusersignedin %s", user)
|
||||
|
||||
def _save_user_info_into_credentials(self, server, user):
|
||||
|
||||
info = {
|
||||
|
@ -681,43 +535,6 @@ class ConnectionManager(object):
|
|||
}
|
||||
self.credentials.add_update_user(server, info)
|
||||
|
||||
def _add_authentication_info_from_connect(self, server, connection_mode, credentials, options={}):
|
||||
|
||||
if not server.get('ExchangeToken'):
|
||||
raise KeyError("server['ExchangeToken'] cannot be null")
|
||||
|
||||
if not credentials.get('ConnectUserId'):
|
||||
raise KeyError("credentials['ConnectUserId'] cannot be null")
|
||||
|
||||
auth = "MediaBrowser "
|
||||
auth += "Client=%s, " % self.config['app.name']
|
||||
auth += "Device=%s, " % self.config['app.device_name']
|
||||
auth += "DeviceId=%s, " % self.config['app.device_id']
|
||||
auth += "Version=%s " % self.config['app.version']
|
||||
|
||||
try:
|
||||
auth = self._request_url({
|
||||
'url': self.get_emby_url(get_server_address(server, connection_mode), "Connect/Exchange"),
|
||||
'type': "GET",
|
||||
'dataType': "json",
|
||||
'verify': options.get('ssl'),
|
||||
'params': {
|
||||
'ConnectUserId': credentials['ConnectUserId']
|
||||
},
|
||||
'headers': {
|
||||
'X-MediaBrowser-Token': server['ExchangeToken'],
|
||||
'X-Emby-Authorization': auth
|
||||
}
|
||||
})
|
||||
except Exception:
|
||||
server['UserId'] = None
|
||||
server['AccessToken'] = None
|
||||
return False
|
||||
else:
|
||||
server['UserId'] = auth['LocalUserId']
|
||||
server['AccessToken'] = auth['AccessToken']
|
||||
return auth
|
||||
|
||||
def _after_connect_validated(self, server, credentials, system_info, connection_mode, verify_authentication, options):
|
||||
|
||||
if options.get('enableAutoLogin') == False:
|
||||
|
@ -753,8 +570,7 @@ class ConnectionManager(object):
|
|||
self.config['auth.ssl'] = options.get('ssl', self.config['auth.ssl'])
|
||||
|
||||
result = {
|
||||
'Servers': [server],
|
||||
'ConnectUser': self.connect_user()
|
||||
'Servers': [server]
|
||||
}
|
||||
|
||||
result['State'] = CONNECTION_STATE['SignedIn'] if server.get('AccessToken') else CONNECTION_STATE['ServerSignIn']
|
||||
|
|
|
@ -100,8 +100,6 @@ class Events(object):
|
|||
event('RemoveLibrarySelection')
|
||||
elif mode == 'addlibs':
|
||||
event('AddLibrarySelection')
|
||||
elif mode == 'connect':
|
||||
event('jellyfinConnect')
|
||||
elif mode == 'addserver':
|
||||
event('AddServer')
|
||||
elif mode == 'login':
|
||||
|
|
|
@ -229,7 +229,7 @@ class Service(xbmc.Monitor):
|
|||
|
||||
if method not in ('ServerUnreachable', 'ServerShuttingDown', 'UserDataChanged', 'ServerConnect',
|
||||
'LibraryChanged', 'ServerOnline', 'SyncLibrary', 'RepairLibrary', 'RemoveLibrary',
|
||||
'JellyfinConnect', 'SyncLibrarySelection', 'RepairLibrarySelection', 'AddServer',
|
||||
'SyncLibrarySelection', 'RepairLibrarySelection', 'AddServer',
|
||||
'Unauthorized', 'UpdateServer', 'UserConfigurationUpdated', 'ServerRestarting',
|
||||
'RemoveServer', 'AddLibrarySelection', 'CheckUpdate', 'RemoveLibrarySelection'):
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue