mirror of
https://github.com/beetbox/beets.git
synced 2026-01-09 01:15:38 +01:00
embyupdate: backwards compatible hostname
`host` takes `localhost`, `http://localhost` and `https://`.
This commit is contained in:
parent
a282d4abc5
commit
5592499b31
3 changed files with 38 additions and 7 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue