From b9a556eded7efaeaeb749fbec19652243165f780 Mon Sep 17 00:00:00 2001 From: warwickh Date: Mon, 11 Oct 2021 12:50:10 +1100 Subject: [PATCH] Handle subfolder in server setting --- lib/libsonic/connection.py | 16 +++++++++++++--- lib/simpleplugin/simpleplugin.py | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/libsonic/connection.py b/lib/libsonic/connection.py index 07ab583..4920e6e 100644 --- a/lib/libsonic/connection.py +++ b/lib/libsonic/connection.py @@ -20,6 +20,7 @@ from netrc import netrc from hashlib import md5 import urllib.request import urllib.error +import urllib.parse from http import client as http_client from urllib.parse import urlencode from io import StringIO @@ -154,8 +155,18 @@ class Connection(object): request. This is not recommended as request URLs can get very long with some API calls """ - self._baseUrl = baseUrl - self._hostname = baseUrl.split('://')[1].strip() + + self._baseUrl = baseUrl.rstrip('/') + self._hostname = self._baseUrl.split('://')[1] + if len(self._hostname.split('/'))>1: + print(len(self._hostname.split('/'))) + xbmc.log("Got a folder %s"%(self._hostname.split('/')[1]),xbmc.LOGDEBUG) + parts = urllib.parse.urlparse(self._baseUrl) + self._baseUrl = "%s://%s" % (parts.scheme, parts.hostname) + self._hostname = parts.hostname + self._serverPath = parts.path.strip('/') + '/rest' + else: + self._serverPath = serverPath.strip('/') self._username = username self._rawPass = password self._legacyAuth = legacyAuth @@ -172,7 +183,6 @@ class Connection(object): self._port = int(port) self._apiVersion = apiVersion self._appName = appName - self._serverPath = serverPath.strip('/') self._insecure = insecure self._opener = self._getOpener(self._username, self._rawPass) diff --git a/lib/simpleplugin/simpleplugin.py b/lib/simpleplugin/simpleplugin.py index b1d5efa..52d4dd6 100644 --- a/lib/simpleplugin/simpleplugin.py +++ b/lib/simpleplugin/simpleplugin.py @@ -58,7 +58,7 @@ def _format_vars(variables): :return: formatted string with sorted ``var = val`` pairs :rtype: str """ - var_list = [(var, val) for var, val in iteritems(variables)] + var_list = [(var, val) for var, val in iter(variables.items())] lines = [] for var, val in sorted(var_list, key=lambda i: i[0]): if not (var.startswith('__') or var.endswith('__')):