forked from kenzuya/unshackle
refactor(core)!: drop leading underscores from internal definitions
Renames 314 defs and 41 module/class-level constants. Keeps 11 names underscored where the stripped form collides in scope, plus 5.5.0 shims for the three symbols external service repos call.
This commit is contained in:
@@ -47,9 +47,9 @@ class MusicRenderer:
|
||||
kind = self.display_kind(music.kind)
|
||||
explicit = any(bool(getattr(song, "explicit", None)) for song in music)
|
||||
total_tracks = getattr(music, "total_tracks", None) or len(music)
|
||||
total_discs = getattr(music, "total_discs", None) or self._max_value(music, "disc")
|
||||
released = self._format_release_date(
|
||||
self._first_value(
|
||||
total_discs = getattr(music, "total_discs", None) or self.max_value(music, "disc")
|
||||
released = self.format_release_date(
|
||||
self.first_value(
|
||||
getattr(music, "released", None),
|
||||
getattr(music, "release_date", None),
|
||||
data.get("release_date"),
|
||||
@@ -58,23 +58,23 @@ class MusicRenderer:
|
||||
metadata.get("released_at"),
|
||||
)
|
||||
)
|
||||
length = self._format_total_duration(getattr(music, "total_duration", None) or self._sum_duration(music))
|
||||
quality = self._quality_summary(
|
||||
self._first_text(
|
||||
length = self.format_total_duration(getattr(music, "total_duration", None) or self.sum_duration(music))
|
||||
quality = self.quality_summary(
|
||||
self.first_text(
|
||||
getattr(music, "quality", None),
|
||||
data.get("quality"),
|
||||
metadata.get("quality"),
|
||||
metadata.get("quality_label"),
|
||||
),
|
||||
lossless=self._as_bool(self._first_value(data.get("lossless"), metadata.get("lossless"))),
|
||||
hires=self._as_bool(self._first_value(data.get("hires"), metadata.get("hires"))),
|
||||
lossless=self.as_bool(self.first_value(data.get("lossless"), metadata.get("lossless"))),
|
||||
hires=self.as_bool(self.first_value(data.get("hires"), metadata.get("hires"))),
|
||||
)
|
||||
|
||||
grid = self._metadata_grid()
|
||||
grid = self.metadata_grid()
|
||||
|
||||
grid.add_row(Text("Title", style="bright_black"), Text(str(title)))
|
||||
grid.add_row(Text("Artist", style="bright_black"), Text(str(artist)))
|
||||
grid.add_row(Text("Type", style="bright_black"), self._kind_text(kind, explicit=explicit))
|
||||
grid.add_row(Text("Type", style="bright_black"), self.kind_text(kind, explicit=explicit))
|
||||
if released:
|
||||
grid.add_row(Text("Released", style="bright_black"), Text(released))
|
||||
if year:
|
||||
@@ -103,8 +103,8 @@ class MusicRenderer:
|
||||
visible_songs = visible_songs[: self.COMPACT_TRACK_LIMIT]
|
||||
|
||||
for song in visible_songs:
|
||||
node = tree.add(self._song_line(song, music), guide_style="bright_black")
|
||||
option = self._option_from_song(song)
|
||||
node = tree.add(self.song_line(song, music), guide_style="bright_black")
|
||||
option = self.option_from_song(song)
|
||||
if option:
|
||||
node.add(option, guide_style="bright_black")
|
||||
|
||||
@@ -124,16 +124,16 @@ class MusicRenderer:
|
||||
for disc in plan.discs
|
||||
for song_plan in disc.songs
|
||||
)
|
||||
released = self._format_release_date(getattr(plan, "released", None) or getattr(plan, "release_date", None))
|
||||
length = self._format_total_duration(plan.total_duration)
|
||||
quality = self._quality_summary(plan.quality_requested)
|
||||
released = self.format_release_date(getattr(plan, "released", None) or getattr(plan, "release_date", None))
|
||||
length = self.format_total_duration(plan.total_duration)
|
||||
quality = self.quality_summary(plan.quality_requested)
|
||||
|
||||
grid = self._metadata_grid()
|
||||
grid = self.metadata_grid()
|
||||
if title:
|
||||
grid.add_row(Text("Title", style="bright_black"), Text(str(title)))
|
||||
if artist:
|
||||
grid.add_row(Text("Artist", style="bright_black"), Text(str(artist)))
|
||||
grid.add_row(Text("Type", style="bright_black"), self._kind_text(kind, explicit=explicit))
|
||||
grid.add_row(Text("Type", style="bright_black"), self.kind_text(kind, explicit=explicit))
|
||||
if released:
|
||||
grid.add_row(Text("Released", style="bright_black"), Text(released))
|
||||
if plan.year:
|
||||
@@ -163,12 +163,12 @@ class MusicRenderer:
|
||||
visible_songs = visible_songs[: self.COMPACT_TRACK_LIMIT]
|
||||
|
||||
for song_plan in visible_songs:
|
||||
node = tree.add(self._song_line(song_plan.song, plan), guide_style="bright_black")
|
||||
node = tree.add(self.song_line(song_plan.song, plan), guide_style="bright_black")
|
||||
if song_plan.skip_reason:
|
||||
node.add(f"[yellow]Skipped:[/] {escape(song_plan.skip_reason)}", guide_style="bright_black")
|
||||
continue
|
||||
for option in song_plan.options:
|
||||
node.add(self._option_line(option), guide_style="bright_black")
|
||||
node.add(self.option_line(option), guide_style="bright_black")
|
||||
|
||||
hidden = total - len(visible_songs)
|
||||
if hidden > 0:
|
||||
@@ -178,7 +178,7 @@ class MusicRenderer:
|
||||
return Panel(tree, title="Available Tracks", box=box.SQUARE, border_style="bright_black")
|
||||
|
||||
@staticmethod
|
||||
def _metadata_grid() -> Table:
|
||||
def metadata_grid() -> Table:
|
||||
grid = Table.grid(padding=(0, 2))
|
||||
grid.add_column(style="orchid1", no_wrap=True)
|
||||
grid.add_column()
|
||||
@@ -205,7 +205,7 @@ class MusicRenderer:
|
||||
return labels[key]
|
||||
return text.replace("_", " ").replace("-", " ").title()
|
||||
|
||||
def _song_line(self, song: Song, music: Music | MusicDownloadPlan) -> Text:
|
||||
def song_line(self, song: Song, music: Music | MusicDownloadPlan) -> Text:
|
||||
number = f"{song.disc}.{song.track:02}" if song.disc > 1 else f"{song.track:02}"
|
||||
line = Text()
|
||||
line.append(number, style="repr.number")
|
||||
@@ -217,13 +217,13 @@ class MusicRenderer:
|
||||
line.append(f" - {song.artist}", style="bright_black")
|
||||
return line
|
||||
|
||||
def _option_from_song(self, song: Song) -> Text | str:
|
||||
def option_from_song(self, song: Song) -> Text | str:
|
||||
data = song.data if isinstance(song.data, dict) else {}
|
||||
metadata = data.get("metadata") if isinstance(data.get("metadata"), dict) else {}
|
||||
|
||||
quality = self._first_text(data.get("quality"), metadata.get("quality"), metadata.get("quality_label"))
|
||||
duration = self._format_duration(self._first_value(data.get("duration"), metadata.get("duration")))
|
||||
reason = self._first_text(
|
||||
quality = self.first_text(data.get("quality"), metadata.get("quality"), metadata.get("quality_label"))
|
||||
duration = self.format_duration(self.first_value(data.get("duration"), metadata.get("duration")))
|
||||
reason = self.first_text(
|
||||
data.get("unavailable_reason"),
|
||||
data.get("skip_reason"),
|
||||
metadata.get("unavailable_reason"),
|
||||
@@ -235,9 +235,9 @@ class MusicRenderer:
|
||||
badges = []
|
||||
if song.explicit:
|
||||
badges.append(("E", "bold bright_red"))
|
||||
if self._as_bool(self._first_value(data.get("atmos"), metadata.get("atmos"))):
|
||||
if self.as_bool(self.first_value(data.get("atmos"), metadata.get("atmos"))):
|
||||
badges.append(("Atmos", "magenta"))
|
||||
if self._is_hires_quality(quality):
|
||||
if self.is_hires_quality(quality):
|
||||
badges.append(("Hi-Res", "gold1"))
|
||||
|
||||
details = []
|
||||
@@ -247,43 +247,43 @@ class MusicRenderer:
|
||||
details.append(duration)
|
||||
if not details and not badges:
|
||||
return ""
|
||||
return self._format_option_text(details, badges)
|
||||
return self.format_option_text(details, badges)
|
||||
|
||||
def _option_line(self, option: MusicTrackOption) -> Text:
|
||||
def option_line(self, option: MusicTrackOption) -> Text:
|
||||
parts = []
|
||||
codec = str(option.codec or "").strip()
|
||||
if codec:
|
||||
parts.append(f"[{codec}]")
|
||||
if option.quality_label:
|
||||
parts.extend(self._split_quality_label(option.quality_label, codec))
|
||||
parts.extend(self.split_quality_label(option.quality_label, codec))
|
||||
elif option.bit_depth and option.sample_rate:
|
||||
parts.append(f"{option.bit_depth}-bit/{self._format_sample_rate(option.sample_rate)}")
|
||||
parts.append(f"{option.bit_depth}-bit/{self.format_sample_rate(option.sample_rate)}")
|
||||
elif option.bitrate:
|
||||
parts.append(f"{int(option.bitrate / 1000)} kb/s")
|
||||
if option.channels:
|
||||
parts.append(self._format_channels(option.channels))
|
||||
parts.append(self.format_channels(option.channels))
|
||||
if option.duration:
|
||||
parts.append(self._format_duration(option.duration))
|
||||
parts.append(self.format_duration(option.duration))
|
||||
badges = []
|
||||
if option.explicit:
|
||||
badges.append(("E", "bold bright_red"))
|
||||
if option.atmos:
|
||||
badges.append(("Atmos", "magenta"))
|
||||
if self._is_cd_option(option):
|
||||
if self.is_cd_option(option):
|
||||
badges.append(("CD", "yellow1"))
|
||||
if option.hires:
|
||||
badges.append(("Hi-Res", "gold1"))
|
||||
return self._format_option_text(parts, badges)
|
||||
return self.format_option_text(parts, badges)
|
||||
|
||||
@staticmethod
|
||||
def _kind_text(kind: str, *, explicit: bool = False) -> Text:
|
||||
def kind_text(kind: str, *, explicit: bool = False) -> Text:
|
||||
text = Text(str(kind))
|
||||
if explicit:
|
||||
text.append(" Explicit", style="bold red")
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
def _format_option_text(parts: list[str], badges: list[tuple[str, str]]) -> Text:
|
||||
def format_option_text(parts: list[str], badges: list[tuple[str, str]]) -> Text:
|
||||
text = Text(style="text2")
|
||||
first = True
|
||||
for part in parts:
|
||||
@@ -301,13 +301,13 @@ class MusicRenderer:
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
def _format_option_parts(parts: list[str]) -> str:
|
||||
def format_option_parts(parts: list[str]) -> str:
|
||||
if not parts:
|
||||
return ""
|
||||
return " | ".join(escape(part) for part in parts if part)
|
||||
|
||||
@staticmethod
|
||||
def _split_quality_label(value: str, codec: str = "") -> list[str]:
|
||||
def split_quality_label(value: str, codec: str = "") -> list[str]:
|
||||
text = str(value or "").strip()
|
||||
if not text:
|
||||
return []
|
||||
@@ -316,7 +316,7 @@ class MusicRenderer:
|
||||
return [text] if text else []
|
||||
|
||||
@staticmethod
|
||||
def _is_cd_option(option: MusicTrackOption) -> bool:
|
||||
def is_cd_option(option: MusicTrackOption) -> bool:
|
||||
codec = str(option.codec or "").upper()
|
||||
if codec not in {"FLAC", "ALAC", "WAV", "AIFF"}:
|
||||
return False
|
||||
@@ -325,7 +325,7 @@ class MusicRenderer:
|
||||
return "16-bit/44.1" in str(option.quality_label or "").lower()
|
||||
|
||||
@staticmethod
|
||||
def _format_sample_rate(value: Any) -> str:
|
||||
def format_sample_rate(value: Any) -> str:
|
||||
try:
|
||||
sample_rate = float(value)
|
||||
except (TypeError, ValueError):
|
||||
@@ -337,7 +337,7 @@ class MusicRenderer:
|
||||
return f"{sample_rate:g} kHz"
|
||||
|
||||
@staticmethod
|
||||
def _format_channels(value: Any) -> str:
|
||||
def format_channels(value: Any) -> str:
|
||||
try:
|
||||
channels = float(value)
|
||||
except (TypeError, ValueError):
|
||||
@@ -351,7 +351,7 @@ class MusicRenderer:
|
||||
return f"{channels:g}"
|
||||
|
||||
@staticmethod
|
||||
def _first_text(*values: Any) -> str:
|
||||
def first_text(*values: Any) -> str:
|
||||
for value in values:
|
||||
if value is None:
|
||||
continue
|
||||
@@ -361,7 +361,7 @@ class MusicRenderer:
|
||||
if nested:
|
||||
return str(nested).strip()
|
||||
elif isinstance(value, (list, tuple)):
|
||||
text = MusicRenderer._first_text(*value)
|
||||
text = MusicRenderer.first_text(*value)
|
||||
if text:
|
||||
return text
|
||||
else:
|
||||
@@ -371,14 +371,14 @@ class MusicRenderer:
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def _first_value(*values: Any) -> Any:
|
||||
def first_value(*values: Any) -> Any:
|
||||
for value in values:
|
||||
if value is not None and value != "":
|
||||
return value
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _as_bool(value: Any) -> bool:
|
||||
def as_bool(value: Any) -> bool:
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, str):
|
||||
@@ -386,7 +386,7 @@ class MusicRenderer:
|
||||
return bool(value)
|
||||
|
||||
@staticmethod
|
||||
def _format_duration(value: Any) -> str:
|
||||
def format_duration(value: Any) -> str:
|
||||
if value in (None, ""):
|
||||
return ""
|
||||
try:
|
||||
@@ -400,7 +400,7 @@ class MusicRenderer:
|
||||
return f"{minutes}:{seconds:02}"
|
||||
|
||||
@staticmethod
|
||||
def _format_total_duration(value: Any) -> str:
|
||||
def format_total_duration(value: Any) -> str:
|
||||
if value in (None, ""):
|
||||
return ""
|
||||
try:
|
||||
@@ -416,7 +416,7 @@ class MusicRenderer:
|
||||
return f"{minutes}m {seconds:02}s"
|
||||
|
||||
@staticmethod
|
||||
def _format_release_date(value: Any) -> str:
|
||||
def format_release_date(value: Any) -> str:
|
||||
if value in (None, ""):
|
||||
return ""
|
||||
text = str(value).strip()
|
||||
@@ -450,7 +450,7 @@ class MusicRenderer:
|
||||
return f"{month_names[month - 1]} {day}, {year}"
|
||||
|
||||
@classmethod
|
||||
def _quality_summary(cls, value: Any, *, lossless: bool = False, hires: bool = False) -> str:
|
||||
def quality_summary(cls, value: Any, *, lossless: bool = False, hires: bool = False) -> str:
|
||||
text = str(value or "").strip()
|
||||
lowered = text.lower()
|
||||
if not text:
|
||||
@@ -462,7 +462,7 @@ class MusicRenderer:
|
||||
if "atmos" in lowered:
|
||||
return "Dolby Atmos"
|
||||
if any(codec in lowered for codec in ("flac", "alac", "wav", "aiff")):
|
||||
return "Hi-Res Lossless" if cls._is_hires_quality(text) else "Lossless"
|
||||
return "Hi-Res Lossless" if cls.is_hires_quality(text) else "Lossless"
|
||||
if "lossless" in lowered:
|
||||
return "Hi-Res Lossless" if "hi-res" in lowered or hires else "Lossless"
|
||||
if "aac" in lowered:
|
||||
@@ -472,7 +472,7 @@ class MusicRenderer:
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
def _is_hires_quality(value: str) -> bool:
|
||||
def is_hires_quality(value: str) -> bool:
|
||||
lowered = value.lower()
|
||||
bit_depth = None
|
||||
sample_rate = None
|
||||
@@ -488,12 +488,12 @@ class MusicRenderer:
|
||||
return bool((bit_depth and bit_depth > 16) or (sample_rate and sample_rate > 48))
|
||||
|
||||
@staticmethod
|
||||
def _sum_duration(music: Music) -> int:
|
||||
def sum_duration(music: Music) -> int:
|
||||
total = 0
|
||||
for song in music:
|
||||
data = song.data if isinstance(song.data, dict) else {}
|
||||
metadata = data.get("metadata") if isinstance(data.get("metadata"), dict) else {}
|
||||
value = MusicRenderer._first_value(data.get("duration"), metadata.get("duration"))
|
||||
value = MusicRenderer.first_value(data.get("duration"), metadata.get("duration"))
|
||||
try:
|
||||
total += int(float(value or 0))
|
||||
except (TypeError, ValueError):
|
||||
@@ -501,7 +501,7 @@ class MusicRenderer:
|
||||
return total
|
||||
|
||||
@staticmethod
|
||||
def _max_value(music: Music, attr: str) -> int:
|
||||
def max_value(music: Music, attr: str) -> int:
|
||||
values = [getattr(song, attr, 0) or 0 for song in music]
|
||||
return max(values, default=0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user