Simplify `Tracks.__add__` method, support Chapter(s) & Track objects

This commit is contained in:
rlaphoenix 2024-02-29 23:19:05 +00:00
parent 97efb59e5f
commit be0ed0b0fb
1 changed files with 6 additions and 5 deletions

View File

@ -51,11 +51,12 @@ class Tracks:
def __len__(self) -> int: def __len__(self) -> int:
return len(self.videos) + len(self.audio) + len(self.subtitles) return len(self.videos) + len(self.audio) + len(self.subtitles)
def __add__(self, other: Tracks) -> Tracks: def __add__(
if not isinstance(other, Tracks): self,
raise TypeError(f"Cannot only add {Tracks} objects with one another, not {type(other)}") other: Union[Tracks, Sequence[Union[AnyTrack, Chapter, Chapters]], Track, Chapter, Chapters]
) -> Tracks:
return Tracks(list(self) + list(other)) self.add(other)
return self
def __repr__(self) -> str: def __repr__(self) -> str:
return "{name}({items})".format( return "{name}({items})".format(