Configurable ListenBrainz API endpoint for self-hosted instances
This commit is contained in:
parent
bbccd3524f
commit
aa93458ed3
5 changed files with 26 additions and 2 deletions
|
|
@ -202,6 +202,7 @@ class ConfigManager:
|
|||
}
|
||||
},
|
||||
"listenbrainz": {
|
||||
"base_url": "",
|
||||
"token": ""
|
||||
},
|
||||
"acoustid": {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,15 @@ class ListenBrainzClient:
|
|||
"""Client for interacting with ListenBrainz API"""
|
||||
|
||||
def __init__(self):
|
||||
self.base_url = "https://api.listenbrainz.org/1"
|
||||
custom_url = config_manager.get("listenbrainz.base_url", "")
|
||||
if custom_url:
|
||||
# Strip trailing slashes and ensure /1 API version suffix
|
||||
custom_url = custom_url.rstrip('/')
|
||||
if not custom_url.endswith('/1'):
|
||||
custom_url += '/1'
|
||||
self.base_url = custom_url
|
||||
else:
|
||||
self.base_url = "https://api.listenbrainz.org/1"
|
||||
self.token = config_manager.get("listenbrainz.token", "")
|
||||
self.username = None
|
||||
|
||||
|
|
|
|||
|
|
@ -3128,7 +3128,14 @@ def run_service_test(service, test_config):
|
|||
|
||||
try:
|
||||
# Test ListenBrainz API by validating the token
|
||||
url = "https://api.listenbrainz.org/1/validate-token"
|
||||
custom_base = test_config.get('base_url', '').rstrip('/')
|
||||
if custom_base:
|
||||
if not custom_base.endswith('/1'):
|
||||
custom_base += '/1'
|
||||
lb_api_base = custom_base
|
||||
else:
|
||||
lb_api_base = "https://api.listenbrainz.org/1"
|
||||
url = f"{lb_api_base}/validate-token"
|
||||
headers = {
|
||||
'Authorization': f'Token {token}'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3105,6 +3105,11 @@
|
|||
<!-- ListenBrainz Settings -->
|
||||
<div class="api-service-frame">
|
||||
<h4 class="service-title listenbrainz-title">ListenBrainz</h4>
|
||||
<div class="form-group">
|
||||
<label>API Base URL:</label>
|
||||
<input type="text" id="listenbrainz-base-url"
|
||||
placeholder="Leave empty for official (api.listenbrainz.org)">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>User Token:</label>
|
||||
<input type="password" id="listenbrainz-token"
|
||||
|
|
@ -3114,6 +3119,7 @@
|
|||
<div class="callback-help">Get your token from <a
|
||||
href="https://listenbrainz.org/profile/" target="_blank"
|
||||
style="color: #eb743b;">ListenBrainz Settings</a></div>
|
||||
<div class="callback-help">Self-hosted? Enter your server URL (e.g. http://localhost:8093)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -3898,6 +3898,7 @@ async function loadSettingsData() {
|
|||
document.getElementById('soulseek-search-timeout-buffer').value = settings.soulseek?.search_timeout_buffer || 15;
|
||||
|
||||
// Populate ListenBrainz settings
|
||||
document.getElementById('listenbrainz-base-url').value = settings.listenbrainz?.base_url || '';
|
||||
document.getElementById('listenbrainz-token').value = settings.listenbrainz?.token || '';
|
||||
|
||||
// Populate AcoustID settings
|
||||
|
|
@ -4607,6 +4608,7 @@ async function saveSettings(quiet = false) {
|
|||
search_timeout_buffer: parseInt(document.getElementById('soulseek-search-timeout-buffer').value) || 15
|
||||
},
|
||||
listenbrainz: {
|
||||
base_url: document.getElementById('listenbrainz-base-url').value,
|
||||
token: document.getElementById('listenbrainz-token').value
|
||||
},
|
||||
acoustid: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue