diff options
| author | Robert Honz <exislow+github@gmail.com> | 2024-01-17 22:08:39 +0100 |
|---|---|---|
| committer | Robert Honz <exislow+github@gmail.com> | 2024-01-17 22:08:39 +0100 |
| commit | 62c75e6c972eed4aadaba3dd03e60d63c31eb995 (patch) | |
| tree | e71f22c5757a0e81cf157016d8f9de26234054f3 /tidal_dl_ng/download.py | |
| parent | bdccb8be37fd941cd5c681950a7e25085efbabb0 (diff) | |
| download | tidal-dl-ng-62c75e6c972eed4aadaba3dd03e60d63c31eb995.tar.gz | |
✨ File extension stored in an enum. File exists check refactored to explicit extension check.
Diffstat (limited to 'tidal_dl_ng/download.py')
| -rw-r--r-- | tidal_dl_ng/download.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py index 5d219de..2f54138 100644 --- a/tidal_dl_ng/download.py +++ b/tidal_dl_ng/download.py @@ -18,7 +18,14 @@ from rich.progress import Progress, TaskID from tidalapi import Album, Mix, Playlist, Session, Track, UserPlaylist, Video from tidal_dl_ng.config import Settings -from tidal_dl_ng.constants import REQUESTS_TIMEOUT_SEC, CoverDimensions, MediaType, SkipExisting, StreamManifestMimeType +from tidal_dl_ng.constants import ( + REQUESTS_TIMEOUT_SEC, + CoverDimensions, + MediaExtensions, + MediaType, + SkipExisting, + StreamManifestMimeType, +) from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token from tidal_dl_ng.helper.exceptions import MediaMissing, MediaUnknown, UnknownManifestFormat from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize @@ -203,7 +210,6 @@ class Download: # Compute if and how downloads need to be skipped. if self.skip_existing.value: extension_ignore = self.skip_existing == SkipExisting.ExtensionIgnore - # TODO: Check if extension is already in `path_file` or not. download_skip = check_file_exists(path_file, extension_ignore=extension_ignore) else: download_skip = False @@ -357,9 +363,9 @@ class Download: return result def get_file_extension(self, stream_url: str, stream_codec: str) -> str: - if ".flac" in stream_url: - result: str = ".flac" - elif ".mp4" in stream_url: + if MediaExtensions.FLAC.value in stream_url: + result: str = MediaExtensions.FLAC.value + elif MediaExtensions.MP4.value in stream_url: # TODO: Need to investigate, what the correct extension is. # if "ac4" in stream_codec or "mha1" in stream_codec: # result = ".mp4" @@ -367,16 +373,16 @@ class Download: # result = ".flac" # else: # result = ".m4a" - result: str = ".mp4" - elif ".ts" in stream_url: - result: str = ".ts" + result: str = MediaExtensions.MP4.value + elif MediaExtensions.TS.value in stream_url: + result: str = MediaExtensions.TS.value else: - result: str = ".m4a" + result: str = MediaExtensions.M4A.value return result def _video_convert(self, path_file: str) -> str: - path_file_out = os.path.splitext(path_file)[0] + ".mp4" + path_file_out = os.path.splitext(path_file)[0] + MediaExtensions.MP4.value result, _ = ffmpeg.input(path_file).output(path_file_out, map=0, c="copy").run() return path_file_out |
