Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wrong determination of file extensions. Fixes tamland/python-ti… #305

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions tidalapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading