From 767af7cf549e92d3a040d3d96247d03d68bca3b2 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Thu, 14 Nov 2024 11:13:10 +0100 Subject: [PATCH 1/2] Fixed wrong determination of file extensions. Fixes tamland/python-tidal#304 --- tidalapi/media.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tidalapi/media.py b/tidalapi/media.py index 1aaadad..4b9ceda 100644 --- a/tidalapi/media.py +++ b/tidalapi/media.py @@ -618,21 +618,19 @@ def get_mimetype(stream_codec, stream_url: Optional[str] = None) -> str: @staticmethod def get_file_extension(stream_url: str, stream_codec: Optional[str] = None) -> str: 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: - if stream_codec: - if Codec.AC4 is stream_codec: - result: str = AudioExtensions.MP4 - elif Codec.FLAC is stream_codec: - result: str = AudioExtensions.FLAC - else: - result: str = AudioExtensions.M4A - else: - result: str = AudioExtensions.MP4 + # 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 + result: str = AudioExtensions.M4A elif VideoExtensions.TS in stream_url: + # Video are streamed as '*.ts' files by TIDAL. result: str = VideoExtensions.TS else: - result: str = AudioExtensions.M4A + # If everything fails it might be an '*.mp4' file + result: str = AudioExtensions.MP4 return result From 2a8fc9dde3eb3b559b28bfb07f2250e74775be37 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Thu, 14 Nov 2024 13:57:01 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Fixed=20file=20extension=20vali?= =?UTF-8?q?dation=20test.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_media.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_media.py b/tests/test_media.py index 7a1b532..59d5c5d 100644 --- a/tests/test_media.py +++ b/tests/test_media.py @@ -539,7 +539,7 @@ def validate_stream_manifest(manifest, is_hi_res_lossless: bool = False): assert manifest.dash_info is not None assert manifest.encryption_key is None assert manifest.encryption_type == "NONE" - assert manifest.file_extension == AudioExtensions.FLAC + assert manifest.file_extension == AudioExtensions.M4A assert manifest.is_encrypted == False assert manifest.manifest_mime_type == ManifestMimeType.MPD assert manifest.mime_type == MimeType.audio_mp4