fix(music): show a collection's own facts in the listing and over --remote

This commit is contained in:
imSp4rky
2026-11-30 13:33:31 -07:00
parent 70ace41201
commit 3634fc5686
18 changed files with 575 additions and 65 deletions
+19 -20
View File
@@ -10,8 +10,8 @@ from rich.text import Text
from rich.tree import Tree
from unshackle.core.console import listing_panel
from unshackle.core.music.extract import first_text, format_duration
from unshackle.core.titles.music import Music, Song
from unshackle.core.music.extract import first_number, first_text, format_duration
from unshackle.core.titles.music import Music, Song, release_song
class MusicRenderer:
@@ -33,12 +33,12 @@ class MusicRenderer:
if not music:
return None
first_song = music[0]
data = first_song.data if isinstance(first_song.data, dict) else {}
release = release_song(music)
data = release.data if release and isinstance(release.data, dict) else {}
metadata = m if isinstance(m := data.get("metadata"), dict) else {}
title = music.title or first_song.album
artist = music.artist or first_song.album_artist or first_song.artist
year = getattr(music, "year", None) or first_song.year
title = music.title or (release.album if release else None)
artist = music.artist or (release.album_artist or release.artist if release else None)
year = getattr(music, "year", None) or (release.year if release else None)
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)
@@ -70,8 +70,10 @@ class MusicRenderer:
grid.add_column()
# values are service data, so they stay Text and never get parsed as markup
grid.add_row("Title", Text(str(title)))
grid.add_row("Artist", Text(str(artist)))
if release or title:
grid.add_row("Title", Text(str(title)))
if release or artist:
grid.add_row("Artist", Text(str(artist)))
grid.add_row("Type", self.kind_text(kind, explicit=explicit))
if released:
grid.add_row("Released", Text(released))
@@ -84,10 +86,10 @@ class MusicRenderer:
grid.add_row("Length", Text(length))
if quality:
grid.add_row("Quality", Text(quality))
if first_song.genre:
grid.add_row("Genre", Text(first_song.genre))
if first_song.label:
grid.add_row("Label", Text(first_song.label))
if release and release.genre:
grid.add_row("Genre", Text(release.genre))
if release and release.label:
grid.add_row("Label", Text(release.label))
return grid
@@ -216,10 +218,10 @@ class MusicRenderer:
def format_total_duration(value: Any) -> str:
if value in (None, ""):
return ""
try:
total_seconds = int(float(value))
except (TypeError, ValueError):
number = first_number(value)
if number is None:
return str(value).strip()
total_seconds = int(number)
if total_seconds <= 0:
return ""
minutes, seconds = divmod(total_seconds, 60)
@@ -308,10 +310,7 @@ class MusicRenderer:
data = song.data if isinstance(song.data, dict) else {}
metadata = m if isinstance(m := data.get("metadata"), dict) else {}
value = MusicRenderer.first_value(data.get("duration"), metadata.get("duration"))
try:
total += int(float(value or 0))
except (TypeError, ValueError):
continue
total += int(first_number(value) or 0)
return total