diff --git a/beetsplug/embyupdate.py b/beetsplug/embyupdate.py index 4da124dbb..3af285973 100644 --- a/beetsplug/embyupdate.py +++ b/beetsplug/embyupdate.py @@ -3,7 +3,7 @@ """Updates the Emby Library whenever the beets library is changed. emby: - host: http://localhost + host: localhost port: 8096 username: user password: password @@ -34,7 +34,22 @@ def api_url(host, port, endpoint): :returns: Full API url :rtype: str """ - joined = urljoin('{0}:{1}'.format(host, port), endpoint) + # check if http or https is defined as host and create hostname + hostname_list = [host] + if host.startswith('http://') or host.startswith('https://'): + hostname = ''.join(hostname_list) + else: + hostname_list.insert(0, 'http://') + hostname = ''.join(hostname_list) + + joined = urljoin( + '{hostname}:{port}'.format( + hostname=hostname, + port=port + ), + endpoint + ) + scheme, netloc, path, query_string, fragment = urlsplit(joined) query_params = parse_qs(query_string) diff --git a/docs/plugins/embyupdate.rst b/docs/plugins/embyupdate.rst index 339f0c818..8dbb7c1db 100644 --- a/docs/plugins/embyupdate.rst +++ b/docs/plugins/embyupdate.rst @@ -6,7 +6,7 @@ EmbyUpdate Plugin To use ``embyupdate`` plugin, enable it in your configuration (see :ref:`using-plugins`). Then, you'll probably want to configure the specifics of your Emby server. You can do that using an ``emby:`` section in your ``config.yaml``, which looks like this:: emby: - host: http://localhost + host: localhost port: 8096 username: user apikey: apikey @@ -25,8 +25,8 @@ Configuration The available options under the ``emby:`` section are: -- **host**: The Emby server host. You have to include ``http://`` or ``https://``. - Default: ``http://localhost`` +- **host**: The Emby server host. You also can include ``http://`` or ``https://``. + Default: ``localhost`` - **port**: The Emby server port. Default: 8096 - **username**: A username of a Emby user that is allowed to refresh the library. diff --git a/test/test_embyupdate.py b/test/test_embyupdate.py index 905766f7a..17e82c73e 100644 --- a/test/test_embyupdate.py +++ b/test/test_embyupdate.py @@ -14,7 +14,7 @@ class EmbyUpdateTest(unittest.TestCase, TestHelper): self.load_plugins('embyupdate') self.config['emby'] = { - u'host': u'http://localhost', + u'host': u'localhost', u'port': 8096, u'username': u'username', u'password': u'password' @@ -24,7 +24,7 @@ class EmbyUpdateTest(unittest.TestCase, TestHelper): self.teardown_beets() self.unload_plugins() - def test_api_url(self): + def test_api_url_only_name(self): self.assertEqual( embyupdate.api_url(self.config['emby']['host'].get(), self.config['emby']['port'].get(), @@ -32,6 +32,22 @@ class EmbyUpdateTest(unittest.TestCase, TestHelper): 'http://localhost:8096/Library/Refresh?format=json' ) + def test_api_url_http(self): + self.assertEqual( + embyupdate.api_url(u'http://localhost', + self.config['emby']['port'].get(), + '/Library/Refresh'), + 'http://localhost:8096/Library/Refresh?format=json' + ) + + def test_api_url_https(self): + self.assertEqual( + embyupdate.api_url(u'https://localhost', + self.config['emby']['port'].get(), + '/Library/Refresh'), + 'https://localhost:8096/Library/Refresh?format=json' + ) + def test_password_data(self): self.assertEqual( embyupdate.password_data(self.config['emby']['username'].get(),