diff --git a/tests/test_media.py b/tests/test_media.py index 59d5c5d..e9c823d 100644 --- a/tests/test_media.py +++ b/tests/test_media.py @@ -550,3 +550,14 @@ def validate_stream_manifest(manifest, is_hi_res_lossless: bool = False): def test_reset_session_quality(session): # HACK: Make sure to reset audio quality to default value for remaining tests session.audio_quality = Quality.default + + +def test_track_extension(session): + track = session.track(65119559) + # Set session as MPD/DASH type (i.e. HI_RES_LOSSLESS Quality). + session.audio_quality = Quality.low_320k + # Attempt to get stream and manifest + stream = track.get_stream() + manifest = stream.get_stream_manifest() + # Assert extension + assert manifest.file_extension == AudioExtensions.M4A diff --git a/tidalapi/media.py b/tidalapi/media.py index 4b9ceda..24e5df9 100644 --- a/tidalapi/media.py +++ b/tidalapi/media.py @@ -620,7 +620,11 @@ def get_file_extension(stream_url: str, stream_codec: Optional[str] = None) -> s if AudioExtensions.FLAC in stream_url: # If the file extension within the URL is '*.flac', this is simply a FLAC file. result: str = AudioExtensions.FLAC - elif AudioExtensions.MP4 in stream_url: + elif ( + AudioExtensions.MP4 in stream_url + or AudioExtensions.M4A in stream_url + or stream_codec == Codec.MP4A + ): # MPEG-4 is simply a container format for different audio / video encoded lines, like FLAC, AAC, M4A etc. # '*.m4a' is usually used as file extension, if the container contains only audio lines # See https://en.wikipedia.org/wiki/MP4_file_format