diff --git a/custom_components/ytube_music_player/config_flow.py b/custom_components/ytube_music_player/config_flow.py index 7752e0e..dbcd6fc 100644 --- a/custom_components/ytube_music_player/config_flow.py +++ b/custom_components/ytube_music_player/config_flow.py @@ -206,8 +206,8 @@ async def async_create_form(hass, user_input, page=1): data_schema[vol.Optional(CONF_LEGACY_RADIO, default=user_input[CONF_LEGACY_RADIO])] = vol.Coerce(bool) # default radio generation typ data_schema[vol.Optional(CONF_SORT_BROWSER, default=user_input[CONF_SORT_BROWSER])] = vol.Coerce(bool) # sort browser results data_schema[vol.Optional(CONF_INIT_EXTRA_SENSOR, default=user_input[CONF_INIT_EXTRA_SENSOR])] = vol.Coerce(bool) # default radio generation typ - data_schema[vol.Optional(CONF_TRACK_LIMIT, default=user_input[CONF_TRACK_LIMIT])] = vol.Coerce(int) + data_schema[vol.Optional(CONF_MAX_DATARATE, default=user_input[CONF_MAX_DATARATE])] = vol.Coerce(int) data_schema[vol.Optional(CONF_BRAND_ID, default=user_input[CONF_BRAND_ID])] = str # brand id data_schema[vol.Optional(CONF_SELECT_SPEAKERS, default=user_input[CONF_SELECT_SPEAKERS])] = str # drop down to select remote_player data_schema[vol.Optional(CONF_SELECT_SOURCE, default=user_input[CONF_SELECT_SOURCE])] = str # drop down to select playlist / playlist-radio diff --git a/custom_components/ytube_music_player/const.py b/custom_components/ytube_music_player/const.py index 3b7acdb..324f769 100644 --- a/custom_components/ytube_music_player/const.py +++ b/custom_components/ytube_music_player/const.py @@ -120,6 +120,7 @@ CONF_LEGACY_RADIO = 'legacy_radio' CONF_SORT_BROWSER = 'sort_browser' CONF_INIT_EXTRA_SENSOR = 'extra_sensor' +CONF_MAX_DATARATE = 'max_datarate' CONF_TRACK_LIMIT = 'track_limit' CONF_PROXY_URL = 'proxy_url' @@ -143,6 +144,7 @@ PROXY_FILENAME = "ytube_proxy.mp4" DEFAULT_TRACK_LIMIT = 25 +DEFAULT_MAX_DATARATE = 0 DEFAULT_LEGACY_RADIO = True DEFAULT_SORT_BROWSER = True DEFAULT_SHUFFLE_MODE = 1 @@ -329,6 +331,7 @@ def ensure_config(user_input): out[CONF_LEGACY_RADIO] = DEFAULT_LEGACY_RADIO out[CONF_SORT_BROWSER] = DEFAULT_SORT_BROWSER out[CONF_INIT_EXTRA_SENSOR] = DEFAULT_INIT_EXTRA_SENSOR + out[CONF_MAX_DATARATE] = DEFAULT_MAX_DATARATE if user_input is not None: out.update(user_input) diff --git a/custom_components/ytube_music_player/media_player.py b/custom_components/ytube_music_player/media_player.py index 9343313..651d6d2 100644 --- a/custom_components/ytube_music_player/media_player.py +++ b/custom_components/ytube_music_player/media_player.py @@ -85,6 +85,7 @@ def __init__(self, hass, config, name_add): self._org_name = config.data.get(CONF_NAME, DOMAIN + name_add) self._attr_name = self._org_name self._init_extra_sensor = config.data.get(CONF_INIT_EXTRA_SENSOR, DEFAULT_INIT_EXTRA_SENSOR) + self._maxDatarate = config.data.get(CONF_MAX_DATARATE,DEFAULT_MAX_DATARATE) # confgurations can be either the full entity_id or just the name self._select_playlist = input_select.DOMAIN + "." + config.data.get(CONF_SELECT_PLAYLIST, DEFAULT_SELECT_PLAYLIST).replace(input_select.DOMAIN + ".", "") @@ -123,6 +124,7 @@ def __init__(self, hass, config, name_add): self.log_me('debug', "- like_in_name: " + str(self._like_in_name)) self.log_me('debug', "- track_limit: " + str(self._trackLimit)) self.log_me('debug', "- legacy_radio: " + str(self._legacyRadio)) + self.log_me('debug', "- max_dataRate: " + str(self._maxDatarate)) self._brand_id = str(config.data.get(CONF_BRAND_ID, "")) self._api = None @@ -1438,6 +1440,17 @@ async def async_get_url(self, videoId=None, retry=60): # try to find best audio only stream, but accept lower quality if we have to valid_streams.sort(key=lambda x: x['bitrate'], reverse=True) + self.log_me('debug', "found "+str(len(valid_streams))+" streams") + # remove all streams with too high bitrates + if(self._maxDatarate>0): + for stream in valid_streams: + if(stream['bitrate']>self._maxDatarate): + if(len(valid_streams)>1): + valid_streams.remove(stream) + self.log_me('debug', '- removed stream with too high bitrate of '+str(stream['bitrate'])) + else: + self.log_me('debug', '- preseved stream, too high quality but last available stream') + if(retry<20): streamId = min(3,len(valid_streams)) elif(retry<30): @@ -1447,7 +1460,7 @@ async def async_get_url(self, videoId=None, retry=60): else: streamId = 0 - self.log_me('debug', 'Using stream '+str(streamId)+"/"+str(len(valid_streams))) + self.log_me('debug', 'Using stream '+str(streamId)+"/"+str(len(valid_streams))+", bitrate:"+str(valid_streams[streamId]['bitrate'])) # self.log_me('debug', '- using stream ' + str(streamId)) if(valid_streams[streamId].get('url') is None): sigCipher_ch = valid_streams[streamId]['signatureCipher'] diff --git a/custom_components/ytube_music_player/translations/en.json b/custom_components/ytube_music_player/translations/en.json index 183dad8..fae053a 100644 --- a/custom_components/ytube_music_player/translations/en.json +++ b/custom_components/ytube_music_player/translations/en.json @@ -32,6 +32,7 @@ "debug_as_error": "Show all debug output as ERROR in the log", "shuffle": "Turn on shuffle on startup", "track_limit": "Limit of simultaneously loaded tracks", + "max_datarate": "Limit the maximum bit rate", "legacy_radio": "Create radio as watchlist of random playlist track", "sort_browser": "Sort results in the media browser", "extra_sensor": "Create sensor that provide extra information" @@ -74,6 +75,7 @@ "debug_as_error": "Show all debug output as ERROR in the log", "shuffle": "Turn on shuffle on startup", "track_limit": "Limit of simultaneously loaded tracks", + "max_datarate": "Limit the maximum bit rate, 0 to disable", "legacy_radio": "Create radio as watchlist of random playlist track", "sort_browser": "Sort results in the media browser", "extra_sensor": "Create sensor that provide extra information"