♻️ Formatting

This commit is contained in:
Oskar Dudziński
2026-05-05 21:13:29 +02:00
parent e45628e15f
commit b0ed7bd208
2 changed files with 54 additions and 21 deletions
+43 -15
View File
@@ -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
+11 -6
View File
@@ -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(