Skip to content

Commit

Permalink
Merge pull request #310 from exislow/309-file-extension
Browse files Browse the repository at this point in the history
✨ Extended file extension detection to properly detect M4A files. Fixes #309
  • Loading branch information
tehkillerbee authored Dec 18, 2024
2 parents b17c8b2 + e848a5d commit 270d8ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion tidalapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 270d8ae

Please sign in to comment.