Simplify str representation of Sorted title containers

This commit is contained in:
rlaphoenix 2023-02-25 12:54:37 +00:00
parent 389fa6e979
commit 92774dcfe6
3 changed files with 4 additions and 45 deletions

View File

@ -1,6 +1,5 @@
import re import re
from abc import ABC from abc import ABC
from collections import Counter
from typing import Any, Iterable, Optional, Union from typing import Any, Iterable, Optional, Union
from langcodes import Language from langcodes import Language
@ -177,19 +176,7 @@ class Series(SortedKeyList, ABC):
def __str__(self) -> str: def __str__(self) -> str:
if not self: if not self:
return super().__str__() return super().__str__()
return self[0].title + (f" ({self[0].year})" if self[0].year else "")
lines = [
f"Series: {self[0].title} ({self[0].year or '?'})",
f"Episodes: ({len(self)})",
*[
f"├─ S{season:02}: {episodes} episodes"
for season, episodes in Counter(x.season for x in self).items()
]
]
last_line = lines.pop(-1)
lines.append(last_line.replace("", ""))
return "\n".join(lines)
__ALL__ = (Episode, Series) __ALL__ = (Episode, Series)

View File

@ -133,23 +133,8 @@ class Movies(SortedKeyList, ABC):
def __str__(self) -> str: def __str__(self) -> str:
if not self: if not self:
return super().__str__() return super().__str__()
# TODO: Assumes there's only one movie
if len(self) > 1: return self[0].name + (f" ({self[0].year})" if self[0].year else "")
lines = [
f"Movies: ({len(self)})",
*[
f"├─ {movie.name} ({movie.year or '?'})"
for movie in self
]
]
last_line = lines.pop(-1)
lines.append(last_line.replace("", ""))
else:
lines = [
f"Movie: {self[0].name} ({self[0].year or '?'})"
]
return "\n".join(lines)
__ALL__ = (Movie, Movies) __ALL__ = (Movie, Movies)

View File

@ -129,20 +129,7 @@ class Album(SortedKeyList, ABC):
def __str__(self) -> str: def __str__(self) -> str:
if not self: if not self:
return super().__str__() return super().__str__()
return f"{self[0].artist} - {self[0].album} ({self[0].year or '?'})"
lines = [
f"Album: {self[0].album} ({self[0].year or '?'})",
f"Artist: {self[0].artist}",
f"Tracks: ({len(self)})",
*[
f"├─ {song.track:02}. {song.name}"
for song in self
]
]
last_line = lines.pop(-1)
lines.append(last_line.replace("", ""))
return "\n".join(lines)
__ALL__ = (Song, Album) __ALL__ = (Song, Album)