Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pykodi/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ def get_kodi_connection(
)


def _url_host(host):
"""Return a host formatted for use in a URL.

Bare IPv6 literals must be bracketed in URLs (RFC 3986 section 3.2.2),
otherwise their colons are parsed as port separators.
"""
if ":" in host and not host.startswith("["):
return f"[{host}]"
return host


class KodiConnection:
"""A connection to Kodi interface."""

Expand All @@ -41,7 +52,7 @@ def __init__(self, host, port, username, password, ssl, timeout, session):

http_protocol = "https" if ssl else "http"

self._image_url = f"{http_protocol}://{image_auth_string}{host}:{port}/image"
self._image_url = f"{http_protocol}://{image_auth_string}{_url_host(host)}:{port}/image"

async def connect(self):
"""Connect to kodi."""
Expand Down Expand Up @@ -86,7 +97,7 @@ def __init__(self, host, port, username, password, ssl, timeout, session):

http_protocol = "https" if ssl else "http"

http_url = f"{http_protocol}://{host}:{port}/jsonrpc"
http_url = f"{http_protocol}://{_url_host(host)}:{port}/jsonrpc"

self._http_server = jsonrpc_async.Server(http_url, **self._kwargs)

Expand Down Expand Up @@ -114,7 +125,7 @@ def __init__(self, host, port, ws_port, username, password, ssl, timeout, sessio
super().__init__(host, port, username, password, ssl, timeout, session)

ws_protocol = "wss" if ssl else "ws"
ws_url = f"{ws_protocol}://{host}:{ws_port}/jsonrpc"
ws_url = f"{ws_protocol}://{_url_host(host)}:{ws_port}/jsonrpc"

self._ws_server = jsonrpc_websocket.Server(ws_url, **self._kwargs)

Expand Down