Implemented Suggestions

This commit is contained in:
Abby Gourlay 2020-03-12 22:12:06 +00:00
parent 068a842184
commit 48ed8ad74c
4 changed files with 15 additions and 34 deletions

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals from __future__ import division, absolute_import, print_function, unicode_literals
import requests import requests
import json import json
@ -43,7 +44,6 @@ class API(object):
self.config = client.config self.config = client.config
self.default_timeout = 5 self.default_timeout = 5
def _http(self, action, url, request={}): def _http(self, action, url, request={}):
request.update({'type': action, 'handler': url}) request.update({'type': action, 'handler': url})
@ -353,12 +353,6 @@ class API(object):
'DeviceId': device_id 'DeviceId': device_id
}) })
#################################################################################################
# New API calls
#################################################################################################
def get_default_headers(self): def get_default_headers(self):
auth = "MediaBrowser " auth = "MediaBrowser "
auth += "Client=%s, " % self.config.data['app.name'].encode('utf-8') auth += "Client=%s, " % self.config.data['app.name'].encode('utf-8')
@ -376,17 +370,7 @@ class API(object):
"x-emby-authorization": auth "x-emby-authorization": auth
} }
def send_request(self, url, path, method=None, timeout=None, headers=None, data=None): def send_request(self, url, path, method="get", timeout=self.default_timeout, headers=self.get_default_headers(), data=None):
if not timeout:
LOG.debug("No timeout set, using default")
timeout = self.default_timeout
if not headers:
LOG.debug("No headers set, using default")
headers = self.get_default_headers()
if not method:
LOG.debug("No method set, using default")
method = "get" #Defaults to get request if none specified
request_method = getattr(requests, method.lower()) request_method = getattr(requests, method.lower())
url = "%s/%s" % (url, path) url = "%s/%s" % (url, path)
request_settings = { request_settings = {
@ -405,11 +389,11 @@ class API(object):
return request_method(url, **request_settings) return request_method(url, **request_settings)
def login(self, server_url, username, password): def login(self, server_url, username, password=""):
path = "Users/AuthenticateByName" path = "Users/AuthenticateByName"
authData = { authData = {
"username": username, "username": username,
"Pw": password or "" "Pw": password
} }
headers = self.get_default_headers() headers = self.get_default_headers()
@ -422,12 +406,12 @@ class API(object):
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()
else: else:
LOG.error("Failed to login to server with status code: "+str(response.status_code)) LOG.error("Failed to login to server with status code: " + str(response.status_code))
LOG.error("Server Response:\n"+str(response.content)) LOG.error("Server Response:\n" + str(response.content))
LOG.debug(headers) LOG.debug(headers)
return {} return {}
except Exception as e: #Find exceptions for likely cases i.e, server timeout, etc except Exception as e: # Find exceptions for likely cases i.e, server timeout, etc
LOG.error(e) LOG.error(e)
return {} return {}

View file

@ -44,7 +44,7 @@ class ConnectionManager(object):
self.API = API(client) self.API = API(client)
def revoke_token(self): #Called once in http#L130 def revoke_token(self):
LOG.info("revoking token") LOG.info("revoking token")
@ -67,7 +67,7 @@ class ConnectionManager(object):
servers = list(credentials['Servers']) servers = list(credentials['Servers'])
#Merges servers we already knew with newly found ones # Merges servers we already knew with newly found ones
for found_server in found_servers: for found_server in found_servers:
try: try:
self.credentials.add_update_server(servers, found_server) self.credentials.add_update_server(servers, found_server)
@ -95,7 +95,7 @@ class ConnectionManager(object):
return {} return {}
LOG.info("Succesfully logged in as %s" % (username)) LOG.info("Succesfully logged in as %s" % (username))
## TODO Change when moving to database storage of server details # TODO Change when moving to database storage of server details
credentials = self.credentials.get() credentials = self.credentials.get()
self.config.data['auth.user_id'] = data['User']['Id'] self.config.data['auth.user_id'] = data['User']['Id']
@ -179,7 +179,7 @@ class ConnectionManager(object):
servers = self.get_available_servers() servers = self.get_available_servers()
LOG.info("connect has %s servers", len(servers)) LOG.info("connect has %s servers", len(servers))
if not (len(servers)): #No servers provided if not (len(servers)): # No servers provided
return { return {
'State': ['ServerSelection'] 'State': ['ServerSelection']
} }
@ -189,7 +189,7 @@ class ConnectionManager(object):
return result return result
def jellyfin_token(self): ## Called once monitor.py#163 def jellyfin_token(self): # Called once monitor.py#163
return self.get_server_info(self.server_id)['AccessToken'] return self.get_server_info(self.server_id)['AccessToken']
def get_server_info(self, server_id): def get_server_info(self, server_id):
@ -204,7 +204,7 @@ class ConnectionManager(object):
if server['Id'] == server_id: if server['Id'] == server_id:
return server return server
def get_public_users(self): ## Required in connect.py#L213 def get_public_users(self):
return self.client.jellyfin.get_public_users() return self.client.jellyfin.get_public_users()
def _server_discovery(self): def _server_discovery(self):
@ -264,7 +264,7 @@ class ConnectionManager(object):
return servers return servers
# TODO: Make IPv6 compatable # TODO: Make IPv6 compatable
def _convert_endpoint_address_to_manual_address(self, info): # Called once ^^ right there def _convert_endpoint_address_to_manual_address(self, info):
if info.get('Address') and info.get('EndpointAddress'): if info.get('Address') and info.get('EndpointAddress'):
address = info['EndpointAddress'].split(':')[0] address = info['EndpointAddress'].split(':')[0]

View file

@ -124,4 +124,4 @@ class Credentials(object):
# Known Kodi/python error # Known Kodi/python error
date_obj = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6])) date_obj = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6]))
return date_obj return date_obj

View file

@ -148,7 +148,6 @@ class Library(threading.Thread):
self.worker_notify() self.worker_notify()
if self.pending_refresh: if self.pending_refresh:
window('jellyfin_sync.bool', True) window('jellyfin_sync.bool', True)
if self.total_updates > self.progress_display: if self.total_updates > self.progress_display:
@ -195,8 +194,6 @@ class Library(threading.Thread):
if xbmc.getCondVisibility('Window.IsMedia'): if xbmc.getCondVisibility('Window.IsMedia'):
xbmc.executebuiltin('Container.Refresh') xbmc.executebuiltin('Container.Refresh')
def stop_client(self): def stop_client(self):
self.stop_thread = True self.stop_thread = True