Fix some small typos and quirks
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 19 Feb 2025 19:58:39 +0000 (20:58 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 19 Feb 2025 19:58:39 +0000 (20:58 +0100)
music_assistant/constants.py
music_assistant/helpers/audio.py
music_assistant/helpers/ffmpeg.py
music_assistant/providers/airplay/provider.py

index 9240fe012277636754840bb5e7c8b6a5d637902a..3ce9aa13f42cd40c70af259142db7bc68b3ae406 100644 (file)
@@ -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:
index c0d40711fefbf39d990b7b233ee7dcb865adc9ca..5e2393c1f4dc13fe3383912d3f9dcf2d69386f48 100644 (file)
@@ -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
     )
index bc02ce3efd4172a1985e5e69fc9defbbd71ec58e..b19ffb4ebb355753b1b16ecb7657bca69b10ff50 100644 (file)
@@ -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 += [
index 58313353c34e41e9664880cd4ae0328b074e789b..2f5663243939ffb73d5364c4fc4f0c06416c075b 100644 (file)
@@ -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"))