# HG changeset patch # User Reed Wade # Date 1595320770 -7200 # Tue Jul 21 10:39:30 2020 +0200 # Node ID 01647b78ca0c61b4304bbf8558d3ff394292e3b1 # Parent 8077f8abfa4182cda752493e9a3298a9ce9913fd handle max bit rate diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -20,20 +20,20 @@ ``` [multisonic] providers = - PROVIDER_NAME: PROTOCOL://USERNAME:PASSWORD@TARGET + PROVIDER_NAME: PROTOCOL://USERNAME:PASSWORD@TARGET?[option1=value1&option2=value2] [ANOTHER] ``` ``` [multisonic] providers = - banalisation: https://mr_banal:azerty@music.banalserver.com + banalisation: https://mr_banal:azerty@music.banalserver.com?max_bit_rate=320 ``` ``` [multisonic] providers = - banalisation: https://mr_banal:azerty@music.banalserver.com + banalisation: https://mr_banal:azerty@music.banalserver.com?max_bit_rate=320 decadence: http://h4ck3r:1213@toot.com ``` diff --git a/mopidy_multisonic/backend.py b/mopidy_multisonic/backend.py --- a/mopidy_multisonic/backend.py +++ b/mopidy_multisonic/backend.py @@ -10,21 +10,35 @@ from . import httpclient from . import uri_parser +def parse_raw_options(raw_options): + if not raw_options: + return {} + + options = {} + for raw_option in raw_options.split("&"): + key, value = raw_option.split("=") + options[key] = value + + return options def load_http_client_config(provider): - match = re.match(r'^([^:]+):(?: )?([^:]+)://([^:]+):([^@]+)@(.+)', provider) + match = re.match(r'^([^:]+):(?: )?([^:]+)://([^:]+):([^@]+)@([^?]+)(\?([^=]+=[^&]+)+)?', provider) name=match.group(1) protocol=match.group(2) username=match.group(3) password=match.group(4) url=match.group(5) + raw_options=match.group(7) + + options = parse_raw_options(raw_options) return httpclient.HttpClientConfig( name=name, url=protocol + "://" + url, username=username, - password=password + password=password, + max_bit_rate=options.get("max_bit_rate") ) def load_http_client_configs(config): diff --git a/mopidy_multisonic/httpclient.py b/mopidy_multisonic/httpclient.py --- a/mopidy_multisonic/httpclient.py +++ b/mopidy_multisonic/httpclient.py @@ -10,6 +10,7 @@ 'url', 'username', 'password', + 'max_bit_rate', ] ) @@ -89,6 +90,10 @@ params = { "id": id, } + + if client_config.max_bit_rate: + params["maxBitRate"] = client_config.max_bit_rate, + return get_request(client_config, "/rest/stream", params) def get_search(client_config, query):