From b0ed7bd2084b4e4c25a53a52442ef97b4e1dfb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Dudzi=C5=84ski?= Date: Tue, 5 May 2026 21:13:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiddl/cli/commands/download/__init__.py | 58 +++++++++++++++++------ tiddl/cli/commands/download/downloader.py | 17 ++++--- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/tiddl/cli/commands/download/__init__.py b/tiddl/cli/commands/download/__init__.py index 7950127..03bf778 100644 --- a/tiddl/cli/commands/download/__init__.py +++ b/tiddl/cli/commands/download/__init__.py @@ -145,7 +145,9 @@ def download_callback( with open(lrc_file_path, "w", encoding="utf-8") as f: f.write(lyrics) except Exception as e: - log.error(f"Failed to write LRC file for track {track.title} (ID: {track.id}): {e}") + log.error( + f"Failed to write LRC file for track {track.title} (ID: {track.id}): {e}" + ) def save_m3u( resource_type: VALID_M3U_RESOURCE_LITERAL, @@ -346,7 +348,9 @@ def download_callback( track_metadata=Metadata( cover=cover, date=str(album.releaseDate), - artist=album.artist.name if album.artist else "", + artist=( + album.artist.name if album.artist else "" + ), credits=album_item.credits, album_review=album_review, ), @@ -355,9 +359,11 @@ def download_callback( except ApiError as e: item = album_item.item track_info = f"Track: {getattr(item, 'title', 'Unknown')} (ID: {item.id})" - if hasattr(item, 'album') and item.album: + if hasattr(item, "album") and item.album: track_info += f", Album ID: {item.album.id}" - ctx.obj.console.print(f"[red]API Error:[/] {e} ({track_info})") + ctx.obj.console.print( + f"[red]API Error:[/] {e} ({track_info})" + ) if RAISE_ERRORS: raise except Exception as e: @@ -441,7 +447,11 @@ def download_callback( video = ctx.obj.api.get_video(resource.id) template = TEMPLATE or CONFIG.templates.video - if "{album" in template and video.album and video.album.id is not None: + if ( + "{album" in template + and video.album + and video.album.id is not None + ): album = ctx.obj.api.get_album(video.album.id) else: album = None @@ -489,13 +499,17 @@ def download_callback( except ApiError as e: item = mix_item.item track_info = f"Track: {getattr(item, 'title', 'Unknown')} (ID: {item.id})" - ctx.obj.console.print(f"[red]API Error:[/] {e} ({track_info})") + ctx.obj.console.print( + f"[red]API Error:[/] {e} ({track_info})" + ) if RAISE_ERRORS: raise except Exception as e: item = mix_item.item track_info = f"Track: {getattr(item, 'title', 'Unknown')} (ID: {item.id})" - ctx.obj.console.print(f"[red]Error:[/] {e} ({track_info})") + ctx.obj.console.print( + f"[red]Error:[/] {e} ({track_info})" + ) if RAISE_ERRORS: raise @@ -526,11 +540,15 @@ def download_callback( try: await download_album(album) except ApiError as e: - ctx.obj.console.print(f"[red]API Error:[/] {e} (Album: {album.title}, ID: {album.id})") + ctx.obj.console.print( + f"[red]API Error:[/] {e} (Album: {album.title}, ID: {album.id})" + ) if RAISE_ERRORS: raise except Exception as e: - ctx.obj.console.print(f"[red]Error:[/] {e} (Album: {album.title}, ID: {album.id})") + ctx.obj.console.print( + f"[red]Error:[/] {e} (Album: {album.title}, ID: {album.id})" + ) if RAISE_ERRORS: raise @@ -580,11 +598,15 @@ def download_callback( ) ) except ApiError as e: - ctx.obj.console.print(f"[red]API Error:[/] {e} (Video: {video.title}, ID: {video.id})") + ctx.obj.console.print( + f"[red]API Error:[/] {e} (Video: {video.title}, ID: {video.id})" + ) if RAISE_ERRORS: raise except Exception as e: - ctx.obj.console.print(f"[red]Error:[/] {e} (Video: {video.title}, ID: {video.id})") + ctx.obj.console.print( + f"[red]Error:[/] {e} (Video: {video.title}, ID: {video.id})" + ) if RAISE_ERRORS: raise @@ -637,7 +659,9 @@ def download_callback( album=album, playlist=playlist, playlist_index=playlist_index, - quality=get_item_quality(playlist_item.item), + quality=get_item_quality( + playlist_item.item + ), ), track_metadata=Metadata(), ) @@ -645,15 +669,19 @@ def download_callback( except ApiError as e: item = playlist_item.item track_info = f"Track: {getattr(item, 'title', 'Unknown')} (ID: {item.id})" - if hasattr(item, 'album') and item.album: + if hasattr(item, "album") and item.album: track_info += f", Album ID: {item.album.id}" - ctx.obj.console.print(f"[red]API Error:[/] {e} ({track_info})") + ctx.obj.console.print( + f"[red]API Error:[/] {e} ({track_info})" + ) if RAISE_ERRORS: raise except Exception as e: item = playlist_item.item track_info = f"Track: {getattr(item, 'title', 'Unknown')} (ID: {item.id})" - ctx.obj.console.print(f"[red]Error:[/] {e} ({track_info})") + ctx.obj.console.print( + f"[red]Error:[/] {e} ({track_info})" + ) if RAISE_ERRORS: raise diff --git a/tiddl/cli/commands/download/downloader.py b/tiddl/cli/commands/download/downloader.py index 484cede..3528671 100644 --- a/tiddl/cli/commands/download/downloader.py +++ b/tiddl/cli/commands/download/downloader.py @@ -144,7 +144,9 @@ class Downloader: stream = self.api.get_track_stream( track_id=item.id, quality=self.track_quality ) - log.debug(f"{stream.trackId=}, {stream.audioQuality}, {stream.audioMode}") + log.debug( + f"{stream.trackId=}, {stream.audioQuality}, {stream.audioMode}" + ) except ApiError as e: log.error(f"{item.id=} {e=}") self.rich_output.console.print( @@ -157,12 +159,15 @@ class Downloader: quality_string = track_qualities_color[stream.audioQuality] - if stream.audioQuality in ["HI_RES_LOSSLESS", "LOSSLESS"] and stream.audioMode == "STEREO": + if ( + stream.audioQuality in ["HI_RES_LOSSLESS", "LOSSLESS"] + and stream.audioMode == "STEREO" + ): quality_string = f"{quality_string} {stream.bitDepth}-bit, {(stream.sampleRate or 0) / 1000:.1f} kHz" should_extract_flac = True else: download_path = download_path.with_suffix(".m4a") - + if stream.audioMode == "DOLBY_ATMOS": quality_string = "[blue]Dolby Atmos[/]" @@ -172,9 +177,9 @@ class Downloader: ) urls, ext = parse_video_stream(stream), ".ts" - download_path = self.get_path( - self.download_path, filename - ).with_suffix(ext) + download_path = self.get_path(self.download_path, filename).with_suffix( + ext + ) quality_string = video_qualities_color[stream.videoQuality] task_id = self.rich_output.download_start(