mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-11-13 20:06:36 +00:00
Increase amount of logging
This commit is contained in:
parent
c321b266f0
commit
9ae99de8dd
30 changed files with 641 additions and 620 deletions
|
|
@ -334,6 +334,3 @@ class API(object):
|
|||
return self._delete("Videos/ActiveEncodings", params={
|
||||
'DeviceId': device_id
|
||||
})
|
||||
|
||||
def delete_item(self, item_id):
|
||||
return self.items("/%s" % item_id, "DELETE")
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ LOG = logging.getLogger('JELLYFIN.'+__name__)
|
|||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
class Config(object):
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -25,6 +26,7 @@ class Config(object):
|
|||
self.http()
|
||||
|
||||
def __shortcuts__(self, key):
|
||||
LOG.debug("__shortcuts__(%r)", key)
|
||||
|
||||
if key == "auth":
|
||||
return self.auth
|
||||
|
|
@ -38,14 +40,16 @@ class Config(object):
|
|||
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):
|
||||
|
||||
LOG.info("Begin app constructor.")
|
||||
# import traceback
|
||||
# LOG.debug(''.join(['\n'] + traceback.format_stack()))
|
||||
|
||||
self.data['app.name'] = name
|
||||
self.data['app.version'] = version
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ class ConnectionManager(object):
|
|||
self.http = HTTP(client)
|
||||
|
||||
def __shortcuts__(self, key):
|
||||
LOG.debug("__shortcuts__(%r)", key)
|
||||
|
||||
if key == "clear":
|
||||
return self.clear_data
|
||||
|
|
@ -97,6 +98,7 @@ class ConnectionManager(object):
|
|||
return
|
||||
|
||||
def __getitem__(self, key):
|
||||
LOG.debug("__getitem__(%r)", key)
|
||||
return self.__shortcuts__(key)
|
||||
|
||||
def clear_data(self):
|
||||
|
|
@ -120,7 +122,7 @@ class ConnectionManager(object):
|
|||
self.config['auth.token'] = None
|
||||
|
||||
def get_available_servers(self):
|
||||
|
||||
|
||||
LOG.info("Begin getAvailableServers")
|
||||
|
||||
# Clone the credentials
|
||||
|
|
@ -163,12 +165,12 @@ class ConnectionManager(object):
|
|||
}
|
||||
|
||||
result = self._request_url(request, False)
|
||||
except Exception as error: # Failed to login
|
||||
LOG.error(error)
|
||||
except Exception as error: # Failed to login
|
||||
LOG.exception(error)
|
||||
return False
|
||||
else:
|
||||
self._on_authenticated(result, options)
|
||||
|
||||
|
||||
return result
|
||||
|
||||
def connect_to_address(self, address, options={}):
|
||||
|
|
@ -184,7 +186,8 @@ class ConnectionManager(object):
|
|||
|
||||
try:
|
||||
public_info = self._try_connect(address, options=options)
|
||||
except Exception:
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
return _on_fail()
|
||||
else:
|
||||
LOG.info("connectToAddress %s succeeded", address)
|
||||
|
|
@ -238,7 +241,7 @@ class ConnectionManager(object):
|
|||
return {}
|
||||
|
||||
servers = self.credentials.get_credentials()['Servers']
|
||||
|
||||
|
||||
for server in servers:
|
||||
if server['Id'] == server_id:
|
||||
return server
|
||||
|
|
@ -258,14 +261,14 @@ class ConnectionManager(object):
|
|||
try:
|
||||
return self.http.request(request)
|
||||
except Exception as error:
|
||||
LOG.error(error)
|
||||
LOG.exception(error)
|
||||
raise
|
||||
|
||||
def _add_app_info(self):
|
||||
return "%s/%s" % (self.config['app.name'], self.config['app.version'])
|
||||
|
||||
def _get_headers(self, request):
|
||||
|
||||
|
||||
headers = request.setdefault('headers', {})
|
||||
|
||||
if request.get('dataType') == "json":
|
||||
|
|
@ -350,9 +353,9 @@ class ConnectionManager(object):
|
|||
|
||||
try:
|
||||
result = self._try_connect(address, timeout, options)
|
||||
|
||||
|
||||
except Exception:
|
||||
LOG.error("test failed for connection mode %s with server %s", mode, server.get('Name'))
|
||||
LOG.exception("test failed for connection mode %s with server %s", mode, server.get('Name'))
|
||||
|
||||
if enable_retry:
|
||||
# TODO: wake on lan and retry
|
||||
|
|
@ -401,17 +404,17 @@ class ConnectionManager(object):
|
|||
|
||||
if a > b:
|
||||
return 1
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
def _string_equals_ignore_case(self, str1, str2):
|
||||
return (str1 or "").lower() == (str2 or "").lower()
|
||||
|
||||
def _server_discovery(self):
|
||||
|
||||
|
||||
MULTI_GROUP = ("<broadcast>", 7359)
|
||||
MESSAGE = "who is JellyfinServer?"
|
||||
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.settimeout(1.0) # This controls the socket.timeout exception
|
||||
|
||||
|
|
@ -419,7 +422,7 @@ class ConnectionManager(object):
|
|||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1)
|
||||
sock.setsockopt(socket.IPPROTO_IP, socket.SO_REUSEADDR, 1)
|
||||
|
||||
|
||||
LOG.debug("MultiGroup : %s", str(MULTI_GROUP))
|
||||
LOG.debug("Sending UDP Data: %s", MESSAGE)
|
||||
|
||||
|
|
@ -428,20 +431,20 @@ class ConnectionManager(object):
|
|||
try:
|
||||
sock.sendto(MESSAGE, MULTI_GROUP)
|
||||
except Exception as error:
|
||||
LOG.error(error)
|
||||
LOG.exception(error)
|
||||
return servers
|
||||
|
||||
while True:
|
||||
try:
|
||||
data, addr = sock.recvfrom(1024) # buffer size
|
||||
servers.append(json.loads(data))
|
||||
|
||||
|
||||
except socket.timeout:
|
||||
LOG.info("Found Servers: %s", servers)
|
||||
return servers
|
||||
|
||||
|
||||
except Exception as e:
|
||||
LOG.error("Error trying to find servers: %s", e)
|
||||
LOG.exception("Error trying to find servers: %s", e)
|
||||
return servers
|
||||
|
||||
def _get_last_used_server(self):
|
||||
|
|
@ -488,7 +491,7 @@ class ConnectionManager(object):
|
|||
return servers
|
||||
|
||||
def _convert_endpoint_address_to_manual_address(self, info):
|
||||
|
||||
|
||||
if info.get('Address') and info.get('EndpointAddress'):
|
||||
address = info['EndpointAddress'].split(':')[0]
|
||||
|
||||
|
|
@ -529,7 +532,7 @@ class ConnectionManager(object):
|
|||
|
||||
self.config['auth.user_id'] = server.pop('UserId', None)
|
||||
self.config['auth.token'] = server.pop('AccessToken', None)
|
||||
|
||||
|
||||
elif verify_authentication and server.get('AccessToken'):
|
||||
|
||||
if self._validate_authentication(server, connection_mode, options) is not False:
|
||||
|
|
@ -579,6 +582,7 @@ class ConnectionManager(object):
|
|||
})
|
||||
self._update_server_info(server, system_info)
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
|
||||
server['UserId'] = None
|
||||
server['AccessToken'] = None
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Credentials(object):
|
|||
if not isinstance(self.credentials, dict):
|
||||
raise ValueError("invalid credentials format")
|
||||
|
||||
except Exception as e: # File is either empty or missing
|
||||
except Exception as e: # File is either empty or missing
|
||||
LOG.warn(e)
|
||||
self.credentials = {}
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ class Credentials(object):
|
|||
|
||||
for existing in servers:
|
||||
if existing['Id'] == server['Id']:
|
||||
|
||||
|
||||
# Merge the data
|
||||
if server.get('DateLastAccessed'):
|
||||
if self._date_object(server['DateLastAccessed']) > self._date_object(existing['DateLastAccessed']):
|
||||
|
|
@ -133,5 +133,5 @@ class Credentials(object):
|
|||
# TypeError: attribute of type 'NoneType' is not callable
|
||||
# Known Kodi/python error
|
||||
date_obj = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6]))
|
||||
|
||||
|
||||
return date_obj
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ LOG = logging.getLogger('Jellyfin.'+__name__)
|
|||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
class HTTP(object):
|
||||
|
||||
session = None
|
||||
|
|
@ -26,6 +27,7 @@ class HTTP(object):
|
|||
self.config = client['config']
|
||||
|
||||
def __shortcuts__(self, key):
|
||||
LOG.debug("__shortcuts__(%r)", key)
|
||||
|
||||
if key == "request":
|
||||
return self.request
|
||||
|
|
@ -33,7 +35,7 @@ class HTTP(object):
|
|||
return
|
||||
|
||||
def start_session(self):
|
||||
|
||||
|
||||
self.session = requests.Session()
|
||||
|
||||
max_retries = self.config['http.max_retries']
|
||||
|
|
@ -41,7 +43,7 @@ class HTTP(object):
|
|||
self.session.mount("https://", requests.adapters.HTTPAdapter(max_retries=max_retries))
|
||||
|
||||
def stop_session(self):
|
||||
|
||||
|
||||
if self.session is None:
|
||||
return
|
||||
|
||||
|
|
@ -90,7 +92,7 @@ class HTTP(object):
|
|||
|
||||
try:
|
||||
r = self._requests(session or self.session or requests, data.pop('type', "GET"), **data)
|
||||
r.content # release the connection
|
||||
r.content # release the connection
|
||||
|
||||
if not self.keep_alive and self.session is not None:
|
||||
self.stop_session()
|
||||
|
|
@ -137,7 +139,7 @@ class HTTP(object):
|
|||
|
||||
raise HTTPException("Unauthorized", error)
|
||||
|
||||
elif r.status_code == 500: # log and ignore.
|
||||
elif r.status_code == 500: # log and ignore.
|
||||
LOG.error("--[ 500 response ] %s", error)
|
||||
|
||||
return
|
||||
|
|
@ -214,7 +216,7 @@ class HTTP(object):
|
|||
|
||||
def _authorization(self, data):
|
||||
|
||||
auth = "MediaBrowser "
|
||||
auth = "MediaBrowser "
|
||||
auth += "Client=%s, " % self.config['app.name'].encode('utf-8')
|
||||
auth += "Device=%s, " % self.config['app.device_name'].encode('utf-8')
|
||||
auth += "DeviceId=%s, " % self.config['app.device_id'].encode('utf-8')
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ class WSClient(threading.Thread):
|
|||
threading.Thread.__init__(self)
|
||||
|
||||
def __shortcuts__(self, key):
|
||||
LOG.debug("__shortcuts__(%r)", key)
|
||||
|
||||
if key == "send":
|
||||
return self.send
|
||||
|
|
@ -54,7 +55,7 @@ class WSClient(threading.Thread):
|
|||
server = self.client['config/auth.server']
|
||||
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)
|
||||
|
||||
|
||||
LOG.info("Websocket url: %s", wsc_url)
|
||||
|
||||
self.wsc = websocket.WebSocketApp(wsc_url,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue