dj-embe/entity/queue.py

44 lines
1.1 KiB
Python
Raw Normal View History

2023-04-27 23:19:18 +00:00
from .entry import Entry
from .playlist import Playlist
2023-04-23 22:48:31 +00:00
class Queue:
def __init__(self) -> None:
2023-04-27 23:19:18 +00:00
self._entries: list[Entry] = []
2023-04-23 22:48:31 +00:00
self.cursor = 0
2023-04-27 23:19:18 +00:00
def add(self, entry: Entry) -> None:
self._entries.append(entry)
2023-04-23 22:48:31 +00:00
2023-04-27 23:19:18 +00:00
def addPlalist(self, playlist: Playlist) -> None:
for entry in playlist:
self._entries.append(entry)
def remove(self, index: int, recursive: bool) -> None:
if not 0 < index < len(self._entries):
return
# if recursive and self[index].playlist is not None:
# first_entry = ""
# else:
self._entries.pop()
2023-04-23 22:48:31 +00:00
def move(self, frm: int, to: int) -> None:
2023-04-27 23:19:18 +00:00
if (
not 0 < frm < len(self._entries)
or not 0 < to < len(self._entries)
or frm == to
):
return
self._entries.insert(to, self._entries.pop(frm))
2023-04-23 22:48:31 +00:00
def __getitem__(self, index: int) -> Entry | None:
2023-04-27 23:19:18 +00:00
if not 0 < index < len(self._entries):
return
return self._entries[index]
def __len__(self) -> int:
return len(self._entries)