From f565c0afbf62fa23b466bf6da18ee8dfe862ebe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sat, 5 Oct 2019 04:44:24 +0200 Subject: [PATCH] ipaddress is not stdlib in Python 2 Let's copypaste from StackOverflow instead! https://www.xkcd.com/208/ Also, `localhost:///8096/emby/...` is not a valid HTTP(S) URL. --- resources/lib/dialogs/servermanual.py | 13 ++++++------- resources/lib/jellyfin/core/connection_manager.py | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/resources/lib/dialogs/servermanual.py b/resources/lib/dialogs/servermanual.py index 36388a73..7f1e8394 100644 --- a/resources/lib/dialogs/servermanual.py +++ b/resources/lib/dialogs/servermanual.py @@ -4,7 +4,7 @@ import logging import os -import ipaddress +import re import xbmcgui import xbmcaddon @@ -27,6 +27,9 @@ ERROR = { 'Empty': 2 } +# https://stackoverflow.com/a/17871737/1035647 +_IPV6_PATTERN = "^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$" +_IPV6_RE = re.compile(_IPV6_PATTERN) ################################################################################################## @@ -115,12 +118,8 @@ class ServerManual(xbmcgui.WindowXMLDialog): return control def _connect_to_server(self, server, port): - try: - addr = ipaddress.ip_address(server.decode('utf-8') if not isinstance(server, type(u'')) else server) - if addr.version == 6: - server = u"[%s]" % (addr.compressed) - except ValueError: - pass + if _IPV6_RE.match(server): + server = "[%s]" % (server) server_address = "%s:%s" % (server, port) if port else server self._message("%s %s..." % (_(30610), server_address)) diff --git a/resources/lib/jellyfin/core/connection_manager.py b/resources/lib/jellyfin/core/connection_manager.py index c9942863..3658ca63 100644 --- a/resources/lib/jellyfin/core/connection_manager.py +++ b/resources/lib/jellyfin/core/connection_manager.py @@ -476,6 +476,10 @@ class ConnectionManager(object): return None def _normalize_address(self, address): + # TODO: Try HTTPS first, then HTTP if that fails. + if '://' not in address: + address = 'http://' + address + # Attempt to correct bad input url = urllib3.util.parse_url(address.strip())