Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IPv6 addressing with a protocol prefix #306

Closed
ghost opened this issue Jan 2, 2023 · 1 comment
Closed

Support IPv6 addressing with a protocol prefix #306

ghost opened this issue Jan 2, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jan 2, 2023

Describe the bug
Bare IPv6 addressing does not seem to work out of the box for me. Neither does prefixing it with a protocol, due to a too primitive regex.

To Reproduce
Try adding a IPv6 address as a server.

Expected behavior
Adds the server URL as expected

Desktop (please complete the following information):

  • OS: Linux
  • Version: develop

Error Messages

Server URL: https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443/
Username: 123
Password:
Traceback (most recent call last):
  File "jellyfin-mpv-shim/./run.py", line 23, in <module>
    main()
  File "jellyfin-mpv-shim/jellyfin_mpv_shim/mpv_shim.py", line 79, in main
    user_interface.login_servers()
  File "jellyfin-mpv-shim/jellyfin_mpv_shim/cli_mgr.py", line 11, in login_servers
    clientManager.cli_connect()
  File "jellyfin-mpv-shim/jellyfin_mpv_shim/clients.py", line 54, in cli_connect
    is_logged_in = self.login(server, username, password)
  File "jellyfin-mpv-shim/jellyfin_mpv_shim/clients.py", line 121, in login
    protocol, ipv6_host, ipv4_host, port, path = path_regex.match(server).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

Proposed Fix

diff --git a/jellyfin_mpv_shim/clients.py b/jellyfin_mpv_shim/clients.py
index cff9e93..cb9606e 100644
--- a/jellyfin_mpv_shim/clients.py
+++ b/jellyfin_mpv_shim/clients.py
@@ -15,7 +15,7 @@ import logging
 import re
 
 log = logging.getLogger("clients")
-path_regex = re.compile("^(https?://)?([^/:]+)(:[0-9]+)?(/.*)?$")
+path_regex = re.compile("^(https?://)?(?:(\[[^/]+\])|([^/:]+))(:[0-9]+)?(/.*)?$")
 
 from typing import Optional
 
@@ -118,7 +118,7 @@ class ClientManager(object):
         if server.endswith("/"):
             server = server[:-1]
         
-        protocol, host, port, path = path_regex.match(server).groups()
+        protocol, ipv6_host, ipv4_host, port, path = path_regex.match(server).groups()
 
         if not protocol:
             log.warning("Adding http:// because it was not provided.")
@@ -131,7 +131,7 @@ class ClientManager(object):
             )
             port = ":8096"
 
-        server = "".join(filter(bool, (protocol, host, port, path)))
+        server = "".join(filter(bool, (protocol, ipv6_host, ipv4_host, port, path)))
 
         client = self.client_factory()
         client.auth.connect_to_address(server)

This adds an outer capture group where the host previously was and first tries to match any url starting with [ (see https://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_network_resource_identifiers) until it encounters a / (compared to either / or : previously which would not work in the case of IPv6) or end of string. If the url does not start with [, then it falls back to previous hostname matching.

This works on my end as expected.

@ghost ghost added the bug Something isn't working label Jan 2, 2023
@iwalton3
Copy link
Member

iwalton3 commented Mar 4, 2023

This will be in the next release. You can download a CI build or install directly using pip to test if desirable.

@iwalton3 iwalton3 closed this as completed Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant