From 478da4179d4656693c4b8e240e745f25a846632e Mon Sep 17 00:00:00 2001 From: Francesco Ceruti Date: Thu, 11 Apr 2024 22:40:45 +0200 Subject: [PATCH] Improve/Fix "local" uri handling --- lisp/core/session_uri.py | 18 +++--------------- lisp/plugins/gst_backend/settings/uri_input.py | 10 ++++++---- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lisp/core/session_uri.py b/lisp/core/session_uri.py index 980501bc6..55a0b667e 100644 --- a/lisp/core/session_uri.py +++ b/lisp/core/session_uri.py @@ -20,20 +20,11 @@ class SessionURI: - LOCAL_SCHEMES = ("", "file") - def __init__(self, uri: str = ""): split = urlsplit(uri) - self._is_local = self.is_local_scheme(split.scheme) - if self._is_local: - # If the path doesn't start with "/" the first part is interpreted - # as "netloc", older session have this problem. - rel_path = split.netloc + split.path - # We need the absolute path - path = self.path_to_absolute(rel_path) - # For local schemes, we assume the URI path is unquoted. - self._uri = urlunsplit(("file", "", quote(path), "", "")) + if split.scheme == "": + self._uri = urlunsplit(("file", "", quote(self.path_to_absolute(uri)), "", "")) else: self._uri = uri @@ -63,7 +54,7 @@ def unquoted_uri(self): @property def is_local(self): """True if the URI point to a local file.""" - return self._is_local + return urlsplit(self._uri).scheme == "file" @classmethod def path_to_relative(cls, path): @@ -77,6 +68,3 @@ def path_to_absolute(cls, path): return Application().session.abs_path(path) - @classmethod - def is_local_scheme(cls, scheme): - return scheme in cls.LOCAL_SCHEMES diff --git a/lisp/plugins/gst_backend/settings/uri_input.py b/lisp/plugins/gst_backend/settings/uri_input.py index 42a71de61..a3c7e3822 100644 --- a/lisp/plugins/gst_backend/settings/uri_input.py +++ b/lisp/plugins/gst_backend/settings/uri_input.py @@ -14,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with Linux Show Player. If not, see . + import os from PyQt5.QtCore import Qt @@ -31,6 +32,7 @@ ) from lisp.application import Application +from lisp.core.session_uri import SessionURI from lisp.plugins.gst_backend import GstBackend from lisp.plugins.gst_backend.elements.uri_input import UriInput from lisp.ui.settings.pages import SettingsPage @@ -116,10 +118,10 @@ def enableCheck(self, enabled): def select_file(self): directory = "" - current = self.filePath.text() + current = SessionURI(self.filePath.text()) - if current.startswith("file://"): - directory = Application().session.abs_path(current[7:]) + if current.is_local: + directory = current.absolute_path if not os.path.exists(directory): directory = GstBackend.Config.get("mediaLookupDir", "") if not os.path.exists(directory): @@ -133,4 +135,4 @@ def select_file(self): ) if os.path.exists(path): - self.filePath.setText("file://" + path) + self.filePath.setText(Application().session.rel_path(path))