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
|
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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue