From e1ecb77d1961d1caec60a28e8ea25537dec7acff Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 19 Feb 2025 20:58:39 +0100 Subject: [PATCH] Fix some small typos and quirks --- music_assistant/constants.py | 14 ++++++-------- music_assistant/helpers/audio.py | 4 +++- music_assistant/helpers/ffmpeg.py | 15 ++++++++++++--- music_assistant/providers/airplay/provider.py | 16 ++++++++++------ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/music_assistant/constants.py b/music_assistant/constants.py index 9240fe01..3ce9aa13 100644 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -514,10 +514,8 @@ def create_sample_rates_config_entry( ) -> ConfigEntry: """Create sample rates config entry based on player specific helpers.""" assert CONF_ENTRY_SAMPLE_RATES.options - if supported_sample_rates is None: - supported_sample_rates = [] - if supported_bit_depths is None: - supported_bit_depths = [] + final_supported_sample_rates = supported_sample_rates or [] + final_supported_bit_depths = supported_bit_depths or [] conf_entry = ConfigEntry.from_dict(CONF_ENTRY_SAMPLE_RATES.to_dict()) conf_entry.hidden = hidden options: list[ConfigValueOption] = [] @@ -530,13 +528,13 @@ def create_sample_rates_config_entry( bit_depth = int(bit_depth_str) # if no supported sample rates are defined, we accept all within max_sample_rate if not supported_sample_rates and max_sample_rate and sample_rate <= max_sample_rate: - supported_sample_rates.append(sample_rate) + final_supported_sample_rates.append(sample_rate) if not supported_bit_depths and max_bit_depth and bit_depth <= max_bit_depth: - supported_bit_depths.append(bit_depth) + final_supported_bit_depths.append(bit_depth) - if sample_rate not in supported_sample_rates: + if sample_rate not in final_supported_sample_rates: continue - if bit_depth not in supported_bit_depths: + if bit_depth not in final_supported_bit_depths: continue options.append(option) if sample_rate <= safe_max_sample_rate and bit_depth <= safe_max_bit_depth: diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index c0d40711..5e2393c1 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -351,7 +351,9 @@ async def get_stream_details( streamdetails.prefer_album_loudness = prefer_album_loudness player_settings = await mass.config.get_player_config(streamdetails.queue_id) core_config = await mass.config.get_core_config("streams") - streamdetails.target_loudness = player_settings.get_value(CONF_VOLUME_NORMALIZATION_TARGET) + streamdetails.target_loudness = float( + player_settings.get_value(CONF_VOLUME_NORMALIZATION_TARGET) + ) streamdetails.volume_normalization_mode = _get_normalization_mode( core_config, player_settings, streamdetails ) diff --git a/music_assistant/helpers/ffmpeg.py b/music_assistant/helpers/ffmpeg.py index bc02ce3e..b19ffb4e 100644 --- a/music_assistant/helpers/ffmpeg.py +++ b/music_assistant/helpers/ffmpeg.py @@ -288,8 +288,8 @@ def get_ffmpeg_args( elif output_format.content_type == ContentType.WAV: pcm_format = ContentType.from_bit_depth(output_format.bit_depth) output_args = [ - # "-ar", - # str(output_format.sample_rate), + "-ar", + str(output_format.sample_rate), "-acodec", pcm_format.name.lower(), "-f", @@ -298,7 +298,16 @@ def get_ffmpeg_args( elif output_format.content_type == ContentType.FLAC: # use level 0 compression for fastest encoding sample_fmt = "s32" if output_format.bit_depth > 16 else "s16" - output_args += ["-sample_fmt", sample_fmt, "-f", "flac", "-compression_level", "0"] + output_args += [ + "-sample_fmt", + sample_fmt, + "-ar", + str(output_format.sample_rate), + "-f", + "flac", + "-compression_level", + "0", + ] elif output_format.content_type.is_pcm(): # use explicit format identifier for pcm formats output_args += [ diff --git a/music_assistant/providers/airplay/provider.py b/music_assistant/providers/airplay/provider.py index 58313353..2f566324 100644 --- a/music_assistant/providers/airplay/provider.py +++ b/music_assistant/providers/airplay/provider.py @@ -326,12 +326,16 @@ class AirplayProvider(PlayerProvider): provider = cast(PluginProvider, self.mass.get_provider(media.custom_data["provider"])) plugin_source = provider.get_source() assert plugin_source.audio_format is not None # for type checking - input_format = plugin_source.audio_format - audio_source = ( - provider.get_audio_stream(player_id) # type: ignore[assignment] - if plugin_source.stream_type == StreamType.CUSTOM - else cast(str, plugin_source.path) - ) + if plugin_source.stream_type == StreamType.CUSTOM: + input_format = plugin_source.audio_format + audio_source = provider.get_audio_stream(player_id) + else: + input_format = AIRPLAY_PCM_FORMAT + audio_source = get_ffmpeg_stream( + audio_input=media.uri, + input_format=plugin_source.audio_format, + output_format=AIRPLAY_PCM_FORMAT, + ) elif media.queue_id and media.queue_id.startswith("ugp_"): # special case: UGP stream ugp_provider = cast(PlayerGroupProvider, self.mass.get_provider("player_group")) -- 2.34.1