diff --git a/.vscode/settings.json b/.vscode/settings.json index d8e7fc7..ace0f19 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,6 +19,7 @@ "albumsort", "APIC", "Bandcamp", + "bitrate", "dotenv", "encyclopaedia", "ENDC", @@ -27,6 +28,7 @@ "metallum", "musify", "OKBLUE", + "OKGREEN", "pathvalidate", "Referer", "sponsorblock", diff --git a/music_kraken/audio/codec.py b/music_kraken/audio/codec.py index 9ec70e6..ccb7bb1 100644 --- a/music_kraken/audio/codec.py +++ b/music_kraken/audio/codec.py @@ -47,7 +47,7 @@ def correct_codec(target: Target, bitrate_kb: int = main_settings["bitrate"], au # run the ffmpeg command with a progressbar ff = FfmpegProgress(ffmpeg_command) - with tqdm(total=100, desc=f"removing {len(interval_list)} segments") as pbar: + with tqdm(total=100, desc=f"processing") as pbar: for progress in ff.run_command_with_progress(): pbar.update(progress-pbar.n) diff --git a/music_kraken/cli/main_downloader.py b/music_kraken/cli/main_downloader.py index f9321b4..7140ff3 100644 --- a/music_kraken/cli/main_downloader.py +++ b/music_kraken/cli/main_downloader.py @@ -166,9 +166,9 @@ class Downloader: self.genre = genre or get_genre() self.process_metadata_anyway = process_metadata_anyway - print() - print(f"Downloading to: \"{self.genre}\"") - print() + output() + output(f"Downloading to: \"{self.genre}\"", color=BColors.HEADER) + output() def print_current_options(self): self.page_dict = dict() @@ -312,10 +312,8 @@ class Downloader: def download(self, data_objects: List[DatabaseObject], **kwargs) -> bool: output() - if len(data_objects) == 1: - output(f"Downloading {data_objects[0].option_string}...", color=BColors.BOLD) - else: - output(f"Downloading {len(data_objects)} objects...", *("- " + o.option_string for o in data_objects), color=BColors.BOLD, sep="\n") + if len(data_objects) > 1: + output(f"Downloading {len(data_objects)} objects...", *("- " + o.option_string for o in data_objects), color=BColors.BOLD, sep="\n") _result_map: Dict[DatabaseObject, DownloadResult] = dict() diff --git a/music_kraken/pages/abstract.py b/music_kraken/pages/abstract.py index d846505..8d6dba9 100644 --- a/music_kraken/pages/abstract.py +++ b/music_kraken/pages/abstract.py @@ -29,7 +29,7 @@ from ..utils.config import main_settings from ..utils.support_classes.query import Query from ..utils.support_classes.download_result import DownloadResult from ..utils.string_processing import fit_to_file_system -from ..utils import trace +from ..utils import trace, output, BColors INDEPENDENT_DB_OBJECTS = Union[Label, Album, Artist, Song] INDEPENDENT_DB_TYPES = Union[Type[Song], Type[Album], Type[Artist], Type[Label]] @@ -328,7 +328,10 @@ class Page: naming_dict: NamingDict, **kwargs ) -> DownloadResult: - trace(f"downloading {type(music_object).__name__} [{music_object.option_string}]") + if isinstance(music_object, Song): + output(f"Downloading {music_object.option_string} to:", color=BColors.BOLD) + else: + output(f"Downloading {music_object.option_string}...", color=BColors.BOLD) # Skips all releases, that are defined in shared.ALBUM_TYPE_BLACKLIST, if download_all is False if isinstance(music_object, Album): @@ -377,32 +380,33 @@ class Page: if song.target_collection.empty: song.target_collection.append(new_target) - if not song.source_collection.has_source_page(self.SOURCE_TYPE): - return DownloadResult(error_message=f"No {self.__class__.__name__} source found for {song.option_string}.") - - sources = song.source_collection.get_sources(self.SOURCE_TYPE) - - temp_target: Target = Target.temp() - r = DownloadResult(1) + temp_target: Target = Target.temp() found_on_disc = False target: Target for target in song.target_collection: - if target.exists: + current_exists = target.exists + + if current_exists: + output(f'- {target.file_path} {BColors.OKGREEN.value}[already exists]', color=BColors.GREY) target.copy_content(temp_target) found_on_disc = True r.found_on_disk += 1 r.add_target(target) + else: + output(f'- {target.file_path}', color=BColors.GREY) - if found_on_disc: - self.LOGGER.info(f"Found {song.option_string} in the library.") + if not song.source_collection.has_source_page(self.SOURCE_TYPE): + return DownloadResult(error_message=f"No {self.__class__.__name__} source found for {song.option_string}.") + + sources = song.source_collection.get_sources(self.SOURCE_TYPE) skip_intervals = [] if not found_on_disc: for source in sources: - r = self.download_song_to_target(source=source, target=temp_target, desc=song.option_string) + r = self.download_song_to_target(source=source, target=temp_target, desc="downloading") if not r.is_fatal_error: skip_intervals = self.get_skip_intervals(song, source) @@ -419,12 +423,12 @@ class Page: return r def _post_process_targets(self, song: Song, temp_target: Target, interval_list: List, found_on_disc: bool) -> DownloadResult: - if found_on_disc and self.download_options.process_audio_if_found: + if not found_on_disc or self.download_options.process_audio_if_found: correct_codec(temp_target, interval_list=interval_list) self.post_process_hook(song, temp_target) - if found_on_disc and self.download_options.process_metadata_if_found: + if not found_on_disc or self.download_options.process_metadata_if_found: write_metadata_to_target(song.metadata, temp_target, song) r = DownloadResult() diff --git a/music_kraken/utils/shared.py b/music_kraken/utils/shared.py index 8f671f9..5f87876 100644 --- a/music_kraken/utils/shared.py +++ b/music_kraken/utils/shared.py @@ -12,7 +12,7 @@ if not load_dotenv(Path(__file__).parent.parent.parent / ".env"): __stage__ = os.getenv("STAGE", "prod") -DEBUG = (__stage__ == "dev") and True +DEBUG = (__stage__ == "dev") and False DEBUG_LOGGING = DEBUG and False DEBUG_TRACE = DEBUG and True DEBUG_OBJECT_TRACE = DEBUG and False