-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.py
More file actions
42 lines (31 loc) · 1.04 KB
/
Copy pathqueue.py
File metadata and controls
42 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""queue.py - Track queue management with navigation and autoplay."""
from dataclasses import dataclass, field
@dataclass
class Queue:
tracks: list[dict] = field(default_factory=list)
index: int = 0
autoplay: bool = True
# --- navigation ---
def current(self) -> dict | None:
if 0 <= self.index < len(self.tracks):
return self.tracks[self.index]
return None
def next(self) -> dict | None:
if self.index + 1 < len(self.tracks):
self.index += 1
return self.current()
return None
def prev(self) -> dict | None:
if self.index > 0:
self.index -= 1
return self.current()
return None
def has_next(self) -> bool:
return self.index + 1 < len(self.tracks)
# --- mutation ---
def set_tracks(self, tracks: list[dict], start: int = 0) -> None:
self.tracks = tracks
self.index = start
def toggle_autoplay(self) -> bool:
self.autoplay = not self.autoplay
return self.autoplay