Skip to content

Commit

Permalink
Improve/Fix "local" uri handling
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoCeruti committed Apr 11, 2024
1 parent 5f93005 commit 478da41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
18 changes: 3 additions & 15 deletions lisp/core/session_uri.py
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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
10 changes: 6 additions & 4 deletions lisp/plugins/gst_backend/settings/uri_input.py
Expand Up @@ -14,6 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with Linux Show Player. If not, see <http://www.gnu.org/licenses/>.

import os

from PyQt5.QtCore import Qt
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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))

0 comments on commit 478da41

Please sign in to comment.