Merge pull request #235 from exislow/201-feature-add-downloaded-songname-to-stdout

✨ Finished items will be written to log output. Minor refactoring.
This commit is contained in:
exislow
2024-11-15 09:57:37 +01:00
committed by GitHub
2 changed files with 16 additions and 17 deletions
+12 -15
View File
@@ -244,10 +244,8 @@ class Download:
self.progress.advance(p_task)
result = True
except Exception as e:
error = e
except Exception:
self.progress.advance(p_task)
self.fn_logger.exception(e)
# To send the progress to the GUI, we need to emit the percentage.
if not progress_to_stdout:
@@ -397,9 +395,13 @@ class Download:
self._move_lyrics(tmp_path_lyrics, path_media_dst)
# Move cover file
# TODO: Cover is downloaded with every track of the album. Needs refactoring, so cover is only
# dowloaded for an album once.
if self.settings.data.cover_album_file and tmp_path_cover:
self._move_cover(tmp_path_cover, path_media_dst)
self.fn_logger.info(f"Downloaded item '{name_builder_item(media)}'.")
# Move final file to the configured destination directory.
shutil.move(tmp_path_file, path_media_dst)
@@ -590,29 +592,22 @@ class Download:
file_name_relative = format_path_media(file_template, media)
# Get the name of the list and check, if videos should be included.
videos_include: bool = True
if isinstance(media, Mix):
list_media_name = media.title[:30]
elif video_download:
list_media_name = name_builder_title(media)[:30]
else:
videos_include = False
list_media_name = name_builder_title(media)[:30]
list_media_name: str = name_builder_title(media)
list_media_name_short: str = list_media_name[:30]
# Get all items of the list.
items = items_results_all(media, videos_include=videos_include)
items = items_results_all(media, videos_include=video_download)
# Determine where to redirect the progress information.
if self.progress_gui is None:
progress_stdout: bool = True
else:
progress_stdout: bool = False
self.progress_gui.list_name.emit(list_media_name[:30])
self.progress_gui.list_name.emit(list_media_name_short[:30])
# Create the list progress task.
p_task1: TaskID = self.progress.add_task(
f"[green]List '{list_media_name}'", total=len(items), visible=progress_stdout
f"[green]List '{list_media_name_short}'", total=len(items), visible=progress_stdout
)
is_album: bool = isinstance(media, Album)
@@ -636,6 +631,8 @@ class Download:
if not progress_stdout:
self.progress_gui.list_item.emit(self.progress.tasks[p_task1].percentage)
self.fn_logger.info(f"Finished list '{list_media_name}'.")
def _video_convert(self, path_file: pathlib.Path) -> pathlib.Path:
path_file_out: pathlib.Path = path_file.with_suffix(AudioExtensions.MP4)
result, _ = (
+4 -2
View File
@@ -25,8 +25,10 @@ def name_builder_album_artist(media: Track | Album) -> str:
return ", ".join(artists_tmp)
def name_builder_title(media: Track | Video) -> str:
result: str = media.full_name if hasattr(media, "full_name") else media.name
def name_builder_title(media: Track | Video | Mix | Playlist | Album | Video) -> str:
result: str = (
media.title if isinstance(media, Mix) else media.full_name if hasattr(media, "full_name") else media.name
)
return result