adding post process fixing the tagging part

This commit is contained in:
Hellow2 2023-03-30 15:58:29 +02:00
parent fab76fc165
commit 6f30ae6f92
2 changed files with 27 additions and 21 deletions

View File

@ -17,6 +17,7 @@ from ..objects import (
Collection, Collection,
Label Label
) )
from ..tagging import write_metadata
LOGGER = logging.getLogger("this shouldn't be used") LOGGER = logging.getLogger("this shouldn't be used")
@ -286,34 +287,34 @@ class Page:
return cls.download_label(music_object, download_features=download_features) return cls.download_label(music_object, download_features=download_features)
@classmethod @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: 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: for album in label.album_collection:
cls.download_album(album) cls.download_album(album, override_existing=override_existing)
@classmethod @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: for album in artist.main_album_collection:
cls.download_album(album) cls.download_album(album, override_existing=override_existing)
if download_features: if download_features:
for song in artist.feature_album: for song in artist.feature_album:
cls.download_song(song) cls.download_song(song, override_existing=override_existing)
@classmethod @classmethod
def download_album(cls, album: Album): def download_album(cls, album: Album, override_existing: bool = False):
for song in album.song_collection: for song in album.song_collection:
cls.download_song(song) cls.download_song(song, override_existing=override_existing)
@classmethod @classmethod
def download_song(cls, song: Song): def download_song(cls, song: Song, override_existing: bool = False):
if song.target_collection.empty: if song.target_collection.empty:
return return
target: Target 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 existing_target: Target
for existing_target in song.target_collection: for existing_target in song.target_collection:
if existing_target.exists: if existing_target.exists:
@ -331,6 +332,10 @@ class Page:
cls._download_song_to_targets(source=sources[0], target_list=song.target_collection.shallow_list) 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 @classmethod
def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song: def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song:

View File

@ -7,9 +7,7 @@ import logging
from ..utils.shared import ( from ..utils.shared import (
TAGGING_LOGGER as logger TAGGING_LOGGER as logger
) )
from ..database import ( from ..objects import Song, Target
Song
)
class AudioMetadata: class AudioMetadata:
@ -50,13 +48,16 @@ class AudioMetadata:
file_location = property(fget=lambda self: self._file_location, fset=set_file_location) file_location = property(fget=lambda self: self._file_location, fset=set_file_location)
def write_metadata(song: Song, ignore_file_not_found: bool = False): def write_metadata(song: Song, ignore_file_not_found: bool = True):
if not song.target.exists_on_disc: target: Target
for target in song.target:
if not target.exists:
if ignore_file_not_found: if ignore_file_not_found:
return continue
else:
raise ValueError(f"{song.target.file} not found") raise ValueError(f"{song.target.file} not found")
id3_object = AudioMetadata(file_location=song.target.file) id3_object = AudioMetadata(file_location=target.file_path)
id3_object.add_song_metadata(song=song) id3_object.add_song_metadata(song=song)
id3_object.save() id3_object.save()