summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-05-15 09:48:36 +0200
committerRobert Honz <exislow+github@gmail.com>2024-05-15 09:48:36 +0200
commita81015ab0279abdd9caaa80b15487b8b870618a7 (patch)
tree2862f6be8995aba8f3844c5f9aef45e61ef2ff2f
parenta41931f3bfbc740e66815ba33ebc506d34373f70 (diff)
downloadtidal-dl-ng-a81015ab0279abdd9caaa80b15487b8b870618a7.tar.gz
👷 Metadata write was moved / untied from download. Fixes #104
-rw-r--r--tidal_dl_ng/download.py33
1 files changed, 13 insertions, 20 deletions
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py
index 02c1120..1d71e33 100644
--- a/tidal_dl_ng/download.py
+++ b/tidal_dl_ng/download.py
@@ -87,7 +87,7 @@ class Download:
self,
media: Track | Video,
path_file: str,
- ) -> (str, pathlib.Path | None):
+ ) -> str:
media_name: str = name_builder_item(media)
urls: [str]
@@ -166,13 +166,7 @@ class Download:
else:
tmp_path_file_decrypted = path_file
- path_lyrics: pathlib.Path | None = None
-
- # Write metadata to file.
- if not isinstance(media, Video):
- result_write, path_lyrics = self.metadata_write(media, tmp_path_file_decrypted)
-
- return tmp_path_file_decrypted, path_lyrics
+ return tmp_path_file_decrypted
def item(
self,
@@ -265,7 +259,7 @@ class Download:
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp_path_dir:
tmp_path_file = os.path.join(tmp_path_dir, str(uuid4()))
# Download media.
- tmp_path_file, tmp_path_lyrics = self._download(media=media, path_file=tmp_path_file)
+ tmp_path_file = self._download(media=media, path_file=tmp_path_file)
# Convert video from TS to MP4
if isinstance(media, Video) and self.settings.data.video_convert_mp4:
@@ -274,7 +268,13 @@ class Download:
# Extract FLAC from MP4 container using ffmpeg
if isinstance(media, Track) and self.settings.data.extract_flac and do_flac_extract:
- tmp_path_file = self._extract_flac(tmp_path_file, media.isrc)
+ tmp_path_file = self._extract_flac(tmp_path_file)
+
+ tmp_path_lyrics: pathlib.Path | None = None
+
+ # Write metadata to file.
+ if not isinstance(media, Video):
+ result_metadata, tmp_path_lyrics = self.metadata_write(media, tmp_path_file)
# Move final file to the configured destination directory.
os.makedirs(os.path.dirname(path_media_dst), exist_ok=True)
@@ -331,7 +331,7 @@ class Download:
result: bool
# Build tmp lyrics filename
# Check if the file was downloaded
- if os.path.isfile(path_lyrics):
+ if path_lyrics and os.path.isfile(path_lyrics):
# Move it.
shutil.move(path_lyrics, os.path.splitext(file_media_dst)[0] + EXTENSION_LYRICS)
@@ -481,18 +481,11 @@ class Download:
return path_file_out
- def _extract_flac(self, path_media_src: str, isrc: str) -> str:
+ def _extract_flac(self, path_media_src: str) -> str:
path_media_out = path_media_src + AudioExtensions.FLAC
result, _ = (
ffmpeg.input(path_media_src)
- .output(
- path_media_out,
- map=0,
- movflags="use_metadata_tags",
- acodec="copy",
- map_metadata="0:g",
- metadata=f"isrc={isrc}",
- )
+ .output(path_media_out, map=0, movflags="use_metadata_tags", acodec="copy", map_metadata="0:g")
.run()
)