From 6f30ae6f92a8b1ec20c656737a67c999072c0cd3 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Thu, 30 Mar 2023 15:58:29 +0200 Subject: [PATCH] adding post process fixing the tagging part --- src/music_kraken/pages/abstract.py | 25 +++++++++++++++---------- src/music_kraken/tagging/id3.py | 23 ++++++++++++----------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index a79f9e9..2eb08b4 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -17,6 +17,7 @@ from ..objects import ( Collection, Label ) +from ..tagging import write_metadata LOGGER = logging.getLogger("this shouldn't be used") @@ -286,34 +287,34 @@ class Page: return cls.download_label(music_object, download_features=download_features) @classmethod - def download_label(cls, label: Label, download_features: bool = True): + def download_label(cls, label: Label, download_features: bool = True, override_existing: bool = False): for artist in label.current_artist_collection: - cls.download_artist(artist, download_features=download_features) + cls.download_artist(artist, download_features=download_features, override_existing=override_existing) for album in label.album_collection: - cls.download_album(album) + cls.download_album(album, override_existing=override_existing) @classmethod - def download_artist(cls, artist: Artist, download_features: bool = True): + def download_artist(cls, artist: Artist, download_features: bool = True, override_existing: bool = False): for album in artist.main_album_collection: - cls.download_album(album) + cls.download_album(album, override_existing=override_existing) if download_features: for song in artist.feature_album: - cls.download_song(song) + cls.download_song(song, override_existing=override_existing) @classmethod - def download_album(cls, album: Album): + def download_album(cls, album: Album, override_existing: bool = False): for song in album.song_collection: - cls.download_song(song) + cls.download_song(song, override_existing=override_existing) @classmethod - def download_song(cls, song: Song): + def download_song(cls, song: Song, override_existing: bool = False): if song.target_collection.empty: return target: Target - if any(target.exists for target in song.target_collection): + if any(target.exists for target in song.target_collection) and not override_existing: existing_target: Target for existing_target in song.target_collection: if existing_target.exists: @@ -330,6 +331,10 @@ class Page: return cls._download_song_to_targets(source=sources[0], target_list=song.target_collection.shallow_list) + + @classmethod + def _post_process_targets(cls, song: Song): + write_metadata(song) @classmethod diff --git a/src/music_kraken/tagging/id3.py b/src/music_kraken/tagging/id3.py index affd63d..9266859 100644 --- a/src/music_kraken/tagging/id3.py +++ b/src/music_kraken/tagging/id3.py @@ -7,9 +7,7 @@ import logging from ..utils.shared import ( TAGGING_LOGGER as logger ) -from ..database import ( - Song -) +from ..objects import Song, Target class AudioMetadata: @@ -50,15 +48,18 @@ class AudioMetadata: file_location = property(fget=lambda self: self._file_location, fset=set_file_location) -def write_metadata(song: Song, ignore_file_not_found: bool = False): - if not song.target.exists_on_disc: - if ignore_file_not_found: - return - raise ValueError(f"{song.target.file} not found") +def write_metadata(song: Song, ignore_file_not_found: bool = True): + target: Target + for target in song.target: + if not target.exists: + if ignore_file_not_found: + continue + else: + raise ValueError(f"{song.target.file} not found") - id3_object = AudioMetadata(file_location=song.target.file) - id3_object.add_song_metadata(song=song) - id3_object.save() + id3_object = AudioMetadata(file_location=target.file_path) + id3_object.add_song_metadata(song=song) + id3_object.save() def write_many_metadata(song_list: List[Song]):