From 56ac6438c70b16649fdb1a63496340578ed0b0f5 Mon Sep 17 00:00:00 2001
From: CrazyBoy <xspeed1989@gmail.com>
Date: Sun, 9 Mar 2025 23:37:41 +0800
Subject: [PATCH 1/2] URL standardization

URL standardization to solve dav davs http https path substitution problems
---
 jellyfin_kodi/helper/api.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/jellyfin_kodi/helper/api.py b/jellyfin_kodi/helper/api.py
index 5ec3736c..1513e717 100644
--- a/jellyfin_kodi/helper/api.py
+++ b/jellyfin_kodi/helper/api.py
@@ -6,7 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
 from . import settings, LazyLogger
 from .utils import translate_path
 import json
-
+import urllib.parse
 ##################################################################################################
 
 LOG = LazyLogger(__name__)
@@ -245,7 +245,20 @@ class API(object):
         for local_path in self.path_data.keys():
             if local_path in path:
                 path = path.replace(local_path, self.path_data[local_path])
-
+        # URL standardization
+        if (
+            "davs://" in path.lower()
+            or "dav://" in path.lower()
+            or "http://" in path.lower()
+            or "https://" in path.lower()
+        ):
+            protocol, rest = path.split("://", 1)
+            if "/" in rest:
+                host, path_part = rest.split("/", 1)
+                path_part = "/".join(
+                    urllib.parse.quote(segment) for segment in path_part.split("/")
+                )
+                path = f"{protocol}://{host}/{path_part}"
         return path
 
     def get_user_artwork(self, user_id):

From d96c22a9e92db577664038a147f40556b12f0bfa Mon Sep 17 00:00:00 2001
From: CrazyBoy <xspeed1989@gmail.com>
Date: Mon, 10 Mar 2025 09:39:32 +0800
Subject: [PATCH 2/2] When the path is a directory, append / after path
 normalization.

---
 jellyfin_kodi/helper/api.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/jellyfin_kodi/helper/api.py b/jellyfin_kodi/helper/api.py
index 1513e717..eba1f130 100644
--- a/jellyfin_kodi/helper/api.py
+++ b/jellyfin_kodi/helper/api.py
@@ -7,6 +7,7 @@ from . import settings, LazyLogger
 from .utils import translate_path
 import json
 import urllib.parse
+
 ##################################################################################################
 
 LOG = LazyLogger(__name__)
@@ -253,12 +254,15 @@ class API(object):
             or "https://" in path.lower()
         ):
             protocol, rest = path.split("://", 1)
+            ends_with_slash = rest.endswith("/")  # 记录是否以/结尾
             if "/" in rest:
                 host, path_part = rest.split("/", 1)
                 path_part = "/".join(
                     urllib.parse.quote(segment) for segment in path_part.split("/")
                 )
                 path = f"{protocol}://{host}/{path_part}"
+                if ends_with_slash and not path.endswith("/"):
+                    path += "/"
         return path
 
     def get_user_artwork(self, user_id):