From 48ed8ad74cefade24a6940844bfa13a738acdf53 Mon Sep 17 00:00:00 2001
From: Abby Gourlay <abbygourlay98@gmail.com>
Date: Thu, 12 Mar 2020 22:12:06 +0000
Subject: [PATCH] Implemented Suggestions

---
 jellyfin_kodi/jellyfin/api.py                | 30 +++++---------------
 jellyfin_kodi/jellyfin/connection_manager.py | 14 ++++-----
 jellyfin_kodi/jellyfin/credentials.py        |  2 +-
 jellyfin_kodi/library.py                     |  3 --
 4 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/jellyfin_kodi/jellyfin/api.py b/jellyfin_kodi/jellyfin/api.py
index 8c704d27..f3042cbc 100644
--- a/jellyfin_kodi/jellyfin/api.py
+++ b/jellyfin_kodi/jellyfin/api.py
@@ -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 {}
diff --git a/jellyfin_kodi/jellyfin/connection_manager.py b/jellyfin_kodi/jellyfin/connection_manager.py
index b1d76eee..aa9c0f57 100644
--- a/jellyfin_kodi/jellyfin/connection_manager.py
+++ b/jellyfin_kodi/jellyfin/connection_manager.py
@@ -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]
diff --git a/jellyfin_kodi/jellyfin/credentials.py b/jellyfin_kodi/jellyfin/credentials.py
index a9cca5d5..4e28e2c4 100644
--- a/jellyfin_kodi/jellyfin/credentials.py
+++ b/jellyfin_kodi/jellyfin/credentials.py
@@ -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
\ No newline at end of file
+        return date_obj
diff --git a/jellyfin_kodi/library.py b/jellyfin_kodi/library.py
index a1ca26a0..5ca1bdd9 100644
--- a/jellyfin_kodi/library.py
+++ b/jellyfin_kodi/library.py
@@ -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