forked from DRMTalks/devine
Simplify str representation of Sorted title containers
This commit is contained in:
parent
389fa6e979
commit
92774dcfe6
|
@ -1,6 +1,5 @@
|
|||
import re
|
||||
from abc import ABC
|
||||
from collections import Counter
|
||||
from typing import Any, Iterable, Optional, Union
|
||||
|
||||
from langcodes import Language
|
||||
|
@ -177,19 +176,7 @@ class Series(SortedKeyList, ABC):
|
|||
def __str__(self) -> str:
|
||||
if not self:
|
||||
return super().__str__()
|
||||
|
||||
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)
|
||||
return self[0].title + (f" ({self[0].year})" if self[0].year else "")
|
||||
|
||||
|
||||
__ALL__ = (Episode, Series)
|
||||
|
|
|
@ -133,23 +133,8 @@ class Movies(SortedKeyList, ABC):
|
|||
def __str__(self) -> str:
|
||||
if not self:
|
||||
return super().__str__()
|
||||
|
||||
if len(self) > 1:
|
||||
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)
|
||||
# TODO: Assumes there's only one movie
|
||||
return self[0].name + (f" ({self[0].year})" if self[0].year else "")
|
||||
|
||||
|
||||
__ALL__ = (Movie, Movies)
|
||||
|
|
|
@ -129,20 +129,7 @@ class Album(SortedKeyList, ABC):
|
|||
def __str__(self) -> str:
|
||||
if not self:
|
||||
return super().__str__()
|
||||
|
||||
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)
|
||||
return f"{self[0].artist} - {self[0].album} ({self[0].year or '?'})"
|
||||
|
||||
|
||||
__ALL__ = (Song, Album)
|
||||
|
|
Loading…
Reference in New Issue