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
import requests
import json
@ -43,7 +44,6 @@ class API(object):
self.config = client.config
self.default_timeout = 5
def _http(self, action, url, request={}):
request.update({'type': action, 'handler': url})
@ -353,12 +353,6 @@ class API(object):
'DeviceId': device_id
})
#################################################################################################
# New API calls
#################################################################################################
def get_default_headers(self):
auth = "MediaBrowser "
auth += "Client=%s, " % self.config.data['app.name'].encode('utf-8')
@ -376,17 +370,7 @@ class API(object):
"x-emby-authorization": auth
}
def send_request(self, url, path, method=None, timeout=None, headers=None, 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
def send_request(self, url, path, method="get", timeout=self.default_timeout, headers=self.get_default_headers(), data=None):
request_method = getattr(requests, method.lower())
url = "%s/%s" % (url, path)
request_settings = {
@ -405,11 +389,11 @@ class API(object):
return request_method(url, **request_settings)
def login(self, server_url, username, password):
def login(self, server_url, username, password=""):
path = "Users/AuthenticateByName"
authData = {
"username": username,
"Pw": password or ""
"Pw": password
}
headers = self.get_default_headers()
@ -422,12 +406,12 @@ class API(object):
if response.status_code == 200:
return response.json()
else:
LOG.error("Failed to login to server with status code: "+str(response.status_code))
LOG.error("Server Response:\n"+str(response.content))
LOG.error("Failed to login to server with status code: " + str(response.status_code))
LOG.error("Server Response:\n" + str(response.content))
LOG.debug(headers)
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)
return {}

View file

@ -44,7 +44,7 @@ class ConnectionManager(object):
self.API = API(client)
def revoke_token(self): #Called once in http#L130
def revoke_token(self):
LOG.info("revoking token")
@ -67,7 +67,7 @@ class ConnectionManager(object):
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:
try:
self.credentials.add_update_server(servers, found_server)
@ -95,7 +95,7 @@ class ConnectionManager(object):
return {}
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()
self.config.data['auth.user_id'] = data['User']['Id']
@ -179,7 +179,7 @@ class ConnectionManager(object):
servers = self.get_available_servers()
LOG.info("connect has %s servers", len(servers))
if not (len(servers)): #No servers provided
if not (len(servers)): # No servers provided
return {
'State': ['ServerSelection']
}
@ -189,7 +189,7 @@ class ConnectionManager(object):
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']
def get_server_info(self, server_id):
@ -204,7 +204,7 @@ class ConnectionManager(object):
if server['Id'] == server_id:
return server
def get_public_users(self): ## Required in connect.py#L213
def get_public_users(self):
return self.client.jellyfin.get_public_users()
def _server_discovery(self):
@ -264,7 +264,7 @@ class ConnectionManager(object):
return servers
# 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'):
address = info['EndpointAddress'].split(':')[0]

View file

@ -124,4 +124,4 @@ class Credentials(object):
# Known Kodi/python error
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()
if self.pending_refresh:
window('jellyfin_sync.bool', True)
if self.total_updates > self.progress_display:
@ -195,8 +194,6 @@ class Library(threading.Thread):
if xbmc.getCondVisibility('Window.IsMedia'):
xbmc.executebuiltin('Container.Refresh')
def stop_client(self):
self.stop_thread = True