mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-12-13 02:23:18 +00:00
Most flake8 warnings corrected
This commit is contained in:
parent
e92d60f7c7
commit
00765c0a12
58 changed files with 1144 additions and 1262 deletions
|
|
@ -9,21 +9,25 @@ from helpers import has_attribute
|
|||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
print(self.format(record))
|
||||
|
||||
|
||||
loghandler = NullHandler
|
||||
LOG = logging.getLogger('Jellyfin')
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
def config(level=logging.INFO):
|
||||
|
||||
logger = logging.getLogger('Jellyfin')
|
||||
logger.addHandler(Jellyfin.loghandler())
|
||||
logger.setLevel(level)
|
||||
|
||||
|
||||
def ensure_client():
|
||||
|
||||
def decorator(func):
|
||||
|
|
@ -109,7 +113,7 @@ class Jellyfin(object):
|
|||
@ensure_client()
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.client[self.server_id], name)
|
||||
|
||||
|
||||
def construct(self):
|
||||
|
||||
self.client[self.server_id] = JellyfinClient()
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ from core.connection_manager import ConnectionManager, CONNECTION_STATE
|
|||
|
||||
#################################################################################################
|
||||
|
||||
LOG = logging.getLogger('JELLYFIN.'+__name__)
|
||||
LOG = logging.getLogger('JELLYFIN.' + __name__)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
def callback(message, data):
|
||||
|
||||
''' Callback function should received message, data
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -225,15 +225,15 @@ class API(object):
|
|||
|
||||
def get_themes(self, item_id):
|
||||
return self.items("/%s/ThemeMedia" % item_id, params={
|
||||
'UserId': "{UserId}",
|
||||
'InheritFromParent': True
|
||||
})
|
||||
'UserId': "{UserId}",
|
||||
'InheritFromParent': True
|
||||
})
|
||||
|
||||
def get_items_theme_song(self, parent_id):
|
||||
return self.users("/Items", params={
|
||||
'HasThemeSong': True,
|
||||
'ParentId': parent_id
|
||||
})
|
||||
'HasThemeSong': True,
|
||||
'ParentId': parent_id
|
||||
})
|
||||
|
||||
def get_plugins(self):
|
||||
return self._get("Plugins")
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import logging
|
|||
|
||||
DEFAULT_HTTP_MAX_RETRIES = 3
|
||||
DEFAULT_HTTP_TIMEOUT = 30
|
||||
LOG = logging.getLogger('JELLYFIN.'+__name__)
|
||||
LOG = logging.getLogger('JELLYFIN.' + __name__)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from http import HTTP
|
|||
|
||||
#################################################################################################
|
||||
|
||||
LOG = logging.getLogger('JELLYFIN.'+__name__)
|
||||
LOG = logging.getLogger('JELLYFIN.' + __name__)
|
||||
CONNECTION_STATE = {
|
||||
'Unavailable': 0,
|
||||
'ServerSelection': 1,
|
||||
|
|
@ -31,6 +31,7 @@ CONNECTION_MODE = {
|
|||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
def get_server_address(server, mode):
|
||||
|
||||
modes = {
|
||||
|
|
@ -86,7 +87,7 @@ class ConnectionManager(object):
|
|||
credentials = self.credentials.get_credentials()
|
||||
found_servers = self._find_servers(self._server_discovery())
|
||||
|
||||
if 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()
|
||||
|
||||
|
|
@ -178,7 +179,7 @@ class ConnectionManager(object):
|
|||
LOG.info("beginning connection tests")
|
||||
return self._test_next_connection_mode(tests, 0, server, options)
|
||||
|
||||
def get_server_address(self, server, mode): #TODO: De-duplicated (Duplicated from above when getting rid of shortcuts)
|
||||
def get_server_address(self, server, mode): # TODO: De-duplicated (Duplicated from above when getting rid of shortcuts)
|
||||
|
||||
modes = {
|
||||
CONNECTION_MODE['Local']: server.get('LocalAddress'),
|
||||
|
|
@ -239,8 +240,10 @@ class ConnectionManager(object):
|
|||
request.pop('dataType')
|
||||
|
||||
headers['X-Application'] = self._add_app_info()
|
||||
headers['Content-type'] = request.get('contentType',
|
||||
'application/x-www-form-urlencoded; charset=UTF-8')
|
||||
headers['Content-type'] = request.get(
|
||||
'contentType',
|
||||
'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
)
|
||||
|
||||
def _connect_to_servers(self, servers, options):
|
||||
|
||||
|
|
@ -379,7 +382,7 @@ class ConnectionManager(object):
|
|||
MESSAGE = "who is JellyfinServer?"
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.settimeout(1.0) # This controls the socket.timeout exception
|
||||
sock.settimeout(1.0) # This controls the socket.timeout exception
|
||||
|
||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
|
|
@ -399,7 +402,7 @@ class ConnectionManager(object):
|
|||
|
||||
while True:
|
||||
try:
|
||||
data, addr = sock.recvfrom(1024) # buffer size
|
||||
data, addr = sock.recvfrom(1024) # buffer size
|
||||
servers.append(json.loads(data))
|
||||
|
||||
except socket.timeout:
|
||||
|
|
@ -446,7 +449,7 @@ class ConnectionManager(object):
|
|||
'Id': found_server['Id'],
|
||||
'LocalAddress': server or found_server['Address'],
|
||||
'Name': found_server['Name']
|
||||
} #TODO
|
||||
} # TODO
|
||||
info['LastConnectionMode'] = CONNECTION_MODE['Manual'] if info.get('ManualAddress') else CONNECTION_MODE['Local']
|
||||
|
||||
servers.append(info)
|
||||
|
|
@ -461,7 +464,7 @@ class ConnectionManager(object):
|
|||
# Determine the port, if any
|
||||
parts = info['Address'].split(':')
|
||||
if len(parts) > 1:
|
||||
port_string = parts[len(parts)-1]
|
||||
port_string = parts[len(parts) - 1]
|
||||
|
||||
try:
|
||||
address += ":%s" % int(port_string)
|
||||
|
|
@ -496,7 +499,7 @@ class ConnectionManager(object):
|
|||
|
||||
def _after_connect_validated(self, server, credentials, system_info, connection_mode, verify_authentication, options):
|
||||
|
||||
if options.get('enableAutoLogin') == False:
|
||||
if not options.get('enableAutoLogin'):
|
||||
|
||||
self.config.data['auth.user_id'] = server.pop('UserId', None)
|
||||
self.config.data['auth.token'] = server.pop('AccessToken', None)
|
||||
|
|
@ -581,7 +584,8 @@ class ConnectionManager(object):
|
|||
if server['Id'] == result['ServerId']:
|
||||
found_server = server
|
||||
break
|
||||
else: return # No server found
|
||||
else:
|
||||
return # No server found
|
||||
|
||||
if options.get('updateDateLastAccessed') is not False:
|
||||
found_server['DateLastAccessed'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@ from datetime import datetime
|
|||
|
||||
#################################################################################################
|
||||
|
||||
LOG = logging.getLogger('JELLYFIN.'+__name__)
|
||||
LOG = logging.getLogger('JELLYFIN.' + __name__)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
class Credentials(object):
|
||||
|
||||
credentials = None
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
class HTTPException(Exception):
|
||||
# Jellyfin HTTP exception
|
||||
def __init__(self, status, message):
|
||||
self.status = status
|
||||
self.message = message
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from exceptions import HTTPException
|
|||
|
||||
#################################################################################################
|
||||
|
||||
LOG = logging.getLogger('Jellyfin.'+__name__)
|
||||
LOG = logging.getLogger('Jellyfin.' + __name__)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ class HTTP(object):
|
|||
raise HTTPException("AccessRestricted", error)
|
||||
else:
|
||||
self.client.callback("Unauthorized", {'ServerId': self.config.data['auth.server-id']})
|
||||
self.client.auth.revoke_token()
|
||||
self.client.auth.revoke_token()
|
||||
|
||||
raise HTTPException("Unauthorized", error)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from ..resources import websocket
|
|||
|
||||
##################################################################################################
|
||||
|
||||
LOG = logging.getLogger('JELLYFIN.'+__name__)
|
||||
LOG = logging.getLogger('JELLYFIN.' + __name__)
|
||||
|
||||
##################################################################################################
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ from uuid import uuid4
|
|||
|
||||
#################################################################################################
|
||||
|
||||
LOG = logging.getLogger('JELLYFIN.'+__name__)
|
||||
LOG = logging.getLogger('JELLYFIN.' + __name__)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
def generate_client_id():
|
||||
return str("%012X" % uuid4())
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -43,8 +43,6 @@ import base64
|
|||
import threading
|
||||
import time
|
||||
import logging
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
"""
|
||||
websocket python client.
|
||||
|
|
@ -89,12 +87,14 @@ class WebSocketConnectionClosedException(WebSocketException):
|
|||
"""
|
||||
pass
|
||||
|
||||
|
||||
class WebSocketTimeoutException(WebSocketException):
|
||||
"""
|
||||
WebSocketTimeoutException will be raised at socket timeout during read/write data.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
default_timeout = None
|
||||
traceEnabled = False
|
||||
|
||||
|
|
@ -135,8 +135,10 @@ def _wrap_sni_socket(sock, sslopt, hostname):
|
|||
|
||||
if sslopt.get('cert_reqs', ssl.CERT_NONE) != ssl.CERT_NONE:
|
||||
capath = ssl.get_default_verify_paths().capath
|
||||
context.load_verify_locations(cafile=sslopt.get('ca_certs', None),
|
||||
capath=sslopt.get('ca_cert_path', capath))
|
||||
context.load_verify_locations(
|
||||
cafile=sslopt.get('ca_certs', None),
|
||||
capath=sslopt.get('ca_cert_path', capath)
|
||||
)
|
||||
|
||||
return context.wrap_socket(
|
||||
sock,
|
||||
|
|
@ -217,9 +219,10 @@ def create_connection(url, timeout=None, **options):
|
|||
websock.connect(url, **options)
|
||||
return websock
|
||||
|
||||
_MAX_INTEGER = (1 << 32) -1
|
||||
|
||||
_MAX_INTEGER = (1 << 32) - 1
|
||||
_AVAILABLE_KEY_CHARS = range(0x21, 0x2f + 1) + range(0x3a, 0x7e + 1)
|
||||
_MAX_CHAR_BYTE = (1<<8) -1
|
||||
_MAX_CHAR_BYTE = (1 << 8) - 1
|
||||
|
||||
# ref. Websocket gets an update, and it breaks stuff.
|
||||
# http://axod.blogspot.com/2010/06/websocket-gets-update-and-it-breaks.html
|
||||
|
|
@ -233,7 +236,7 @@ def _create_sec_websocket_key():
|
|||
_HEADERS_TO_CHECK = {
|
||||
"upgrade": "websocket",
|
||||
"connection": "upgrade",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ABNF(object):
|
||||
|
|
@ -244,16 +247,16 @@ class ABNF(object):
|
|||
"""
|
||||
|
||||
# operation code values.
|
||||
OPCODE_CONT = 0x0
|
||||
OPCODE_TEXT = 0x1
|
||||
OPCODE_CONT = 0x0
|
||||
OPCODE_TEXT = 0x1
|
||||
OPCODE_BINARY = 0x2
|
||||
OPCODE_CLOSE = 0x8
|
||||
OPCODE_PING = 0x9
|
||||
OPCODE_PONG = 0xa
|
||||
OPCODE_CLOSE = 0x8
|
||||
OPCODE_PING = 0x9
|
||||
OPCODE_PONG = 0xa
|
||||
|
||||
# available operation code value tuple
|
||||
OPCODES = (OPCODE_CONT, OPCODE_TEXT, OPCODE_BINARY, OPCODE_CLOSE,
|
||||
OPCODE_PING, OPCODE_PONG)
|
||||
OPCODE_PING, OPCODE_PONG)
|
||||
|
||||
# opcode human readable string
|
||||
OPCODE_MAP = {
|
||||
|
|
@ -263,10 +266,10 @@ class ABNF(object):
|
|||
OPCODE_CLOSE: "close",
|
||||
OPCODE_PING: "ping",
|
||||
OPCODE_PONG: "pong"
|
||||
}
|
||||
}
|
||||
|
||||
# data length threashold.
|
||||
LENGTH_7 = 0x7d
|
||||
LENGTH_7 = 0x7d
|
||||
LENGTH_16 = 1 << 16
|
||||
LENGTH_63 = 1 << 63
|
||||
|
||||
|
|
@ -287,8 +290,8 @@ class ABNF(object):
|
|||
|
||||
def __str__(self):
|
||||
return "fin=" + str(self.fin) \
|
||||
+ " opcode=" + str(self.opcode) \
|
||||
+ " data=" + str(self.data)
|
||||
+ " opcode=" + str(self.opcode) \
|
||||
+ " data=" + str(self.data)
|
||||
|
||||
@staticmethod
|
||||
def create_frame(data, opcode):
|
||||
|
|
@ -318,9 +321,7 @@ class ABNF(object):
|
|||
if length >= ABNF.LENGTH_63:
|
||||
raise ValueError("data is too long")
|
||||
|
||||
frame_header = chr(self.fin << 7
|
||||
| self.rsv1 << 6 | self.rsv2 << 5 | self.rsv3 << 4
|
||||
| self.opcode)
|
||||
frame_header = chr(self.fin << 7 | self.rsv1 << 6 | self.rsv2 << 5 | self.rsv3 << 4 | self.opcode)
|
||||
if length < ABNF.LENGTH_7:
|
||||
frame_header += chr(self.mask << 7 | length)
|
||||
elif length < ABNF.LENGTH_16:
|
||||
|
|
@ -582,8 +583,7 @@ class WebSocket(object):
|
|||
if traceEnabled:
|
||||
logger.debug("send: " + repr(data))
|
||||
while data:
|
||||
l = self._send(data)
|
||||
data = data[l:]
|
||||
data = data[self._send(data):]
|
||||
return length
|
||||
|
||||
def send_binary(self, payload):
|
||||
|
|
@ -685,7 +685,6 @@ class WebSocket(object):
|
|||
self._frame_mask = None
|
||||
return ABNF(fin, rsv1, rsv2, rsv3, opcode, has_mask, payload)
|
||||
|
||||
|
||||
def send_close(self, status=STATUS_NORMAL, reason=""):
|
||||
"""
|
||||
send close data to the server.
|
||||
|
|
@ -709,7 +708,7 @@ class WebSocket(object):
|
|||
|
||||
try:
|
||||
self.sock.shutdown(socket.SHUT_RDWR)
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
|
||||
'''
|
||||
|
|
@ -766,7 +765,6 @@ class WebSocket(object):
|
|||
raise WebSocketConnectionClosedException()
|
||||
return bytes
|
||||
|
||||
|
||||
def _recv_strict(self, bufsize):
|
||||
shortage = bufsize - sum(len(x) for x in self._recv_buffer)
|
||||
while shortage > 0:
|
||||
|
|
@ -781,7 +779,6 @@ class WebSocket(object):
|
|||
self._recv_buffer = [unified[bufsize:]]
|
||||
return unified[:bufsize]
|
||||
|
||||
|
||||
def _recv_line(self):
|
||||
line = []
|
||||
while True:
|
||||
|
|
@ -844,7 +841,7 @@ class WebSocketApp(object):
|
|||
close websocket connection.
|
||||
"""
|
||||
self.keep_running = False
|
||||
if(self.sock != None):
|
||||
if self.sock is None:
|
||||
self.sock.close()
|
||||
|
||||
def _send_ping(self, interval):
|
||||
|
|
@ -890,7 +887,7 @@ class WebSocketApp(object):
|
|||
try:
|
||||
data = self.sock.recv()
|
||||
|
||||
if data is None or self.keep_running == False:
|
||||
if data is None or not self.keep_running:
|
||||
break
|
||||
self._callback(self.on_message, data)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue