mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
Merge pull request #951 from sundermann/browser-dialog
Use file browser dialog for local path
This commit is contained in:
commit
87556da208
2 changed files with 43 additions and 4 deletions
|
@ -10,7 +10,7 @@ import sys
|
||||||
import re
|
import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus, urlparse, urlunparse
|
||||||
|
|
||||||
from dateutil import tz, parser
|
from dateutil import tz, parser
|
||||||
|
|
||||||
|
@ -157,6 +157,7 @@ def dialog(dialog_type, *args, **kwargs):
|
||||||
"select": d.select,
|
"select": d.select,
|
||||||
"numeric": d.numeric,
|
"numeric": d.numeric,
|
||||||
"multi": d.multiselect,
|
"multi": d.multiselect,
|
||||||
|
"browse": d.browse,
|
||||||
}
|
}
|
||||||
return types[dialog_type](*args, **kwargs)
|
return types[dialog_type](*args, **kwargs)
|
||||||
|
|
||||||
|
@ -487,6 +488,13 @@ def set_addon_mode():
|
||||||
LOG.info("Add-on playback: %s", settings("useDirectPaths") == "0")
|
LOG.info("Add-on playback: %s", settings("useDirectPaths") == "0")
|
||||||
|
|
||||||
|
|
||||||
|
def strip_credentials(url):
|
||||||
|
parsed = urlparse(url)
|
||||||
|
netloc = parsed.netloc.split("@")[-1] # Remove credentials
|
||||||
|
stripped_url = urlunparse(parsed._replace(netloc=netloc))
|
||||||
|
return stripped_url
|
||||||
|
|
||||||
|
|
||||||
def path_replacements():
|
def path_replacements():
|
||||||
# UI to display and manage path replacements for native mode
|
# UI to display and manage path replacements for native mode
|
||||||
from ..database import get_credentials, save_credentials
|
from ..database import get_credentials, save_credentials
|
||||||
|
@ -509,7 +517,9 @@ def path_replacements():
|
||||||
if selected_path == 1:
|
if selected_path == 1:
|
||||||
# Add a new path replacement
|
# Add a new path replacement
|
||||||
remote_path = dialog("input", translate(33206))
|
remote_path = dialog("input", translate(33206))
|
||||||
local_path = dialog("input", translate(33207))
|
local_path = strip_credentials(
|
||||||
|
dialog("browse", type=0, heading=translate(33207), shares="")
|
||||||
|
)
|
||||||
if remote_path and local_path:
|
if remote_path and local_path:
|
||||||
paths[remote_path] = local_path
|
paths[remote_path] = local_path
|
||||||
elif selected_path > 1:
|
elif selected_path > 1:
|
||||||
|
@ -520,7 +530,15 @@ def path_replacements():
|
||||||
del paths[edit_remote_path]
|
del paths[edit_remote_path]
|
||||||
# Prepopulate the text box with the existing value
|
# Prepopulate the text box with the existing value
|
||||||
remote_path = dialog("input", translate(33206), defaultt=edit_remote_path)
|
remote_path = dialog("input", translate(33206), defaultt=edit_remote_path)
|
||||||
local_path = dialog("input", translate(33207), defaultt=edit_local_path)
|
local_path = strip_credentials(
|
||||||
|
dialog(
|
||||||
|
"browse",
|
||||||
|
type=0,
|
||||||
|
heading=translate(33207),
|
||||||
|
shares="",
|
||||||
|
defaultt=edit_local_path,
|
||||||
|
)
|
||||||
|
)
|
||||||
if remote_path and local_path:
|
if remote_path and local_path:
|
||||||
paths[remote_path] = local_path
|
paths[remote_path] = local_path
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ else:
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jellyfin_kodi.helper.utils import values, convert_to_local
|
from jellyfin_kodi.helper.utils import values, convert_to_local, strip_credentials
|
||||||
|
|
||||||
item1 = {"foo": 123, "bar": 456, "baz": 789}
|
item1 = {"foo": 123, "bar": 456, "baz": 789}
|
||||||
|
|
||||||
|
@ -77,3 +77,24 @@ def test_values(item, keys, expected):
|
||||||
)
|
)
|
||||||
def test_convert_to_local(utctime, timezone, expected):
|
def test_convert_to_local(utctime, timezone, expected):
|
||||||
assert convert_to_local(utctime, timezone=zoneinfo.ZoneInfo(timezone)) == expected
|
assert convert_to_local(utctime, timezone=zoneinfo.ZoneInfo(timezone)) == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url,expected",
|
||||||
|
[
|
||||||
|
("smb://user:pass@server.test/media", "smb://server.test/media"),
|
||||||
|
("smb://server.test/media", "smb://server.test/media"),
|
||||||
|
("smb://user:pass@192.0.2.1/media", "smb://192.0.2.1/media"),
|
||||||
|
("smb://user@192.0.2.1/media", "smb://192.0.2.1/media"),
|
||||||
|
("nfs://server.test/media", "nfs://server.test/media"),
|
||||||
|
("sftp://user:pass@server.test/media", "sftp://server.test/media"),
|
||||||
|
("file://media/movies", "file://media/movies"),
|
||||||
|
("/media/movies", "/media/movies"),
|
||||||
|
("http://user:pass@server.test/media", "http://server.test/media"),
|
||||||
|
("https://user:pass@server.test/media", "https://server.test/media"),
|
||||||
|
("http://server.test/media", "http://server.test/media"),
|
||||||
|
("https://server.test/media", "https://server.test/media"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_strip_credentials(url, expected):
|
||||||
|
assert strip_credentials(url) == expected
|
||||||
|
|
Loading…
Reference in a new issue