Pàgines llista de reproducció
This commit is contained in:
@@ -79,6 +79,7 @@ class Set:
|
||||
@dataclasses.dataclass
|
||||
class Playlist:
|
||||
id: int
|
||||
name: str | None
|
||||
sets: list[Set]
|
||||
|
||||
def to_playlist_entries(self) -> Iterator[PlaylistEntry]:
|
||||
@@ -86,11 +87,12 @@ class Playlist:
|
||||
yield from set_entry.to_playlist_entries(playlist_id=self.id)
|
||||
|
||||
@classmethod
|
||||
def from_playlist_entries(cls, playlist_id: int, entries: list[PlaylistEntry]) -> Self:
|
||||
def from_playlist_entries(cls, playlist_id: int, name: str | None, entries: list[PlaylistEntry]) -> Self:
|
||||
if any(entry.playlist_id != playlist_id for entry in entries):
|
||||
raise ValueError("All PlaylistEntries must have the same playlist_id")
|
||||
return cls(
|
||||
id=playlist_id,
|
||||
name=name,
|
||||
sets=[
|
||||
Set.from_playlist_entries(set_id, set_entries)
|
||||
for set_id, set_entries in groupby(entries, key_fn=lambda e: e.set_id, group_fn=list)
|
||||
|
||||
Reference in New Issue
Block a user