✨ File extension stored in an enum. File exists check refactored to explicit extension check.
This commit is contained in:
@@ -49,5 +49,5 @@ class AudioExtensions(Enum):
|
|||||||
MP4 = ".mp4"
|
MP4 = ".mp4"
|
||||||
|
|
||||||
|
|
||||||
class MediaExtensions(AudioExtensions):
|
class VideoExtensions(Enum):
|
||||||
TS = ".ts"
|
TS = ".ts"
|
||||||
|
|||||||
+11
-11
@@ -20,11 +20,12 @@ from tidalapi import Album, Mix, Playlist, Session, Track, UserPlaylist, Video
|
|||||||
from tidal_dl_ng.config import Settings
|
from tidal_dl_ng.config import Settings
|
||||||
from tidal_dl_ng.constants import (
|
from tidal_dl_ng.constants import (
|
||||||
REQUESTS_TIMEOUT_SEC,
|
REQUESTS_TIMEOUT_SEC,
|
||||||
|
AudioExtensions,
|
||||||
CoverDimensions,
|
CoverDimensions,
|
||||||
MediaExtensions,
|
|
||||||
MediaType,
|
MediaType,
|
||||||
SkipExisting,
|
SkipExisting,
|
||||||
StreamManifestMimeType,
|
StreamManifestMimeType,
|
||||||
|
VideoExtensions,
|
||||||
)
|
)
|
||||||
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
|
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.exceptions import MediaMissing, MediaUnknown, UnknownManifestFormat
|
||||||
@@ -222,7 +223,6 @@ class Download:
|
|||||||
tmp_path_file = self._download(fn_logger, media, progress, progress_gui, stream_manifest, tmp_path_file)
|
tmp_path_file = self._download(fn_logger, media, progress, progress_gui, stream_manifest, tmp_path_file)
|
||||||
|
|
||||||
if isinstance(media, Video) and self.settings.data.video_convert_mp4:
|
if isinstance(media, Video) and self.settings.data.video_convert_mp4:
|
||||||
# TODO: Make optional.
|
|
||||||
# Convert `*.ts` file to `*.mp4` using ffmpeg
|
# Convert `*.ts` file to `*.mp4` using ffmpeg
|
||||||
tmp_path_file = self._video_convert(tmp_path_file)
|
tmp_path_file = self._video_convert(tmp_path_file)
|
||||||
path_file = os.path.splitext(path_file)[0] + ".mp4"
|
path_file = os.path.splitext(path_file)[0] + ".mp4"
|
||||||
@@ -258,7 +258,7 @@ class Download:
|
|||||||
# TODO: Implement proper logging.
|
# TODO: Implement proper logging.
|
||||||
print(f"Could not retrieve lyrics for `{name_builder_item(track)}`.")
|
print(f"Could not retrieve lyrics for `{name_builder_item(track)}`.")
|
||||||
|
|
||||||
# TODO: Check if it is possible to pass "None" values.
|
# `None` values are not allowed.
|
||||||
m: Metadata = Metadata(
|
m: Metadata = Metadata(
|
||||||
path_file=path_file,
|
path_file=path_file,
|
||||||
lyrics=lyrics,
|
lyrics=lyrics,
|
||||||
@@ -363,9 +363,9 @@ class Download:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_file_extension(self, stream_url: str, stream_codec: str) -> str:
|
def get_file_extension(self, stream_url: str, stream_codec: str) -> str:
|
||||||
if MediaExtensions.FLAC.value in stream_url:
|
if AudioExtensions.FLAC.value in stream_url:
|
||||||
result: str = MediaExtensions.FLAC.value
|
result: str = AudioExtensions.FLAC.value
|
||||||
elif MediaExtensions.MP4.value in stream_url:
|
elif AudioExtensions.MP4.value in stream_url:
|
||||||
# TODO: Need to investigate, what the correct extension is.
|
# TODO: Need to investigate, what the correct extension is.
|
||||||
# if "ac4" in stream_codec or "mha1" in stream_codec:
|
# if "ac4" in stream_codec or "mha1" in stream_codec:
|
||||||
# result = ".mp4"
|
# result = ".mp4"
|
||||||
@@ -373,16 +373,16 @@ class Download:
|
|||||||
# result = ".flac"
|
# result = ".flac"
|
||||||
# else:
|
# else:
|
||||||
# result = ".m4a"
|
# result = ".m4a"
|
||||||
result: str = MediaExtensions.MP4.value
|
result: str = AudioExtensions.MP4.value
|
||||||
elif MediaExtensions.TS.value in stream_url:
|
elif VideoExtensions.TS.value in stream_url:
|
||||||
result: str = MediaExtensions.TS.value
|
result: str = VideoExtensions.TS.value
|
||||||
else:
|
else:
|
||||||
result: str = MediaExtensions.M4A.value
|
result: str = AudioExtensions.M4A.value
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _video_convert(self, path_file: str) -> str:
|
def _video_convert(self, path_file: str) -> str:
|
||||||
path_file_out = os.path.splitext(path_file)[0] + MediaExtensions.MP4.value
|
path_file_out = os.path.splitext(path_file)[0] + AudioExtensions.MP4.value
|
||||||
result, _ = ffmpeg.input(path_file).output(path_file_out, map=0, c="copy").run()
|
result, _ = ffmpeg.input(path_file).output(path_file_out, map=0, c="copy").run()
|
||||||
|
|
||||||
return path_file_out
|
return path_file_out
|
||||||
|
|||||||
Reference in New Issue
Block a user