Wrap Song in a broader Playback state object with stuff like volume and repeat mode
This commit is contained in:
parent
085bca7974
commit
68609f3d07
24 changed files with 765 additions and 245 deletions
3
src/mpd_now_playable/playback/__init__.py
Normal file
3
src/mpd_now_playable/playback/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from .playback import Playback
|
||||
|
||||
__all__ = ("Playback",)
|
||||
36
src/mpd_now_playable/playback/playback.py
Normal file
36
src/mpd_now_playable/playback/playback.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from ..song.song import Song
|
||||
from ..song.stopped import Stopped
|
||||
from ..tools.schema.define import schema
|
||||
from .queue import Queue
|
||||
from .settings import Settings
|
||||
|
||||
|
||||
@schema("https://static.00dani.me/m/schemata/mpd-now-playable/playback-v1.json")
|
||||
@dataclass(slots=True, kw_only=True)
|
||||
class Playback:
|
||||
#: The MPD partition this playback information came from. Essentially, MPD
|
||||
#: can act as multiple music player servers simultaneously, distinguished
|
||||
#: by name. For most users, this will always be "default".
|
||||
partition: str
|
||||
|
||||
#: Stats about MPD's song queue, including the current song and next song's
|
||||
#: indices in it.
|
||||
queue: Queue
|
||||
|
||||
#: Playback settings such as volume and repeat mode.
|
||||
settings: Settings
|
||||
|
||||
#: Information about the current song itself. MPD provides none of this
|
||||
#: information if its playback is currently stopped, so mpd-now-playable
|
||||
#: doesn't either and will give you a Stopped instead in that case.
|
||||
song: Song | Stopped = Field(discriminator="state")
|
||||
|
||||
@property
|
||||
def active_song(self) -> Song | None:
|
||||
if isinstance(self.song, Song):
|
||||
return self.song
|
||||
return None
|
||||
13
src/mpd_now_playable/playback/queue.py
Normal file
13
src/mpd_now_playable/playback/queue.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Queue:
|
||||
#: The zero-based index of the current song in MPD's queue.
|
||||
current: int
|
||||
#: The index of the next song to be played, taking into account random and
|
||||
#: repeat playback settings.
|
||||
next: int
|
||||
#: The total length of MPD's queue - the last song in the queue will have
|
||||
#: the index one less than this, since queue indices are zero-based.
|
||||
length: int
|
||||
48
src/mpd_now_playable/playback/settings.py
Normal file
48
src/mpd_now_playable/playback/settings.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
OneShotFlag = bool | Literal["oneshot"]
|
||||
|
||||
|
||||
def to_oneshot(value: str) -> OneShotFlag:
|
||||
match value:
|
||||
case "1":
|
||||
return True
|
||||
case "0":
|
||||
return False
|
||||
case "oneshot":
|
||||
return "oneshot"
|
||||
return False
|
||||
|
||||
|
||||
@dataclass(slots=True, kw_only=True)
|
||||
class Settings:
|
||||
#: The playback volume ranging from 0 to 100 - it will only be available if
|
||||
#: MPD has a volume mixer configured.
|
||||
volume: int | None
|
||||
|
||||
#: Repeat playback of the queued songs. This setting normally means the
|
||||
#: entire queue will be played on repeat, but its behaviour can be
|
||||
#: influenced by the other playback mode flags.
|
||||
repeat: bool
|
||||
|
||||
#: Play the queued songs in random order. This is distinct from shuffling
|
||||
#: the queue, which randomises the queue's order once when you send the
|
||||
#: shuffle command and will then play the queue in that new order
|
||||
#: repeatedly if asked. If MPD is asked to both repeat and randomise, the
|
||||
#: queue is effectively shuffled each time it loops.
|
||||
random: bool
|
||||
|
||||
#: Play only a single song. If MPD is asked to repeat, then the current
|
||||
#: song will be played repeatedly. Otherwise, when the current song ends
|
||||
#: MPD will simply stop playback. Like the consume flag, the single flag
|
||||
#: can also be set to "oneshot", which will cause the single flag to be
|
||||
#: switched off after it takes effect once (either the current song will
|
||||
#: repeat just once, or playback will stop but the single flag will be
|
||||
#: switched off).
|
||||
single: OneShotFlag
|
||||
|
||||
#: Remove songs from the queue as they're played. This flag can also be set
|
||||
#: to "oneshot", which means the currently playing song will be consumed,
|
||||
#: and then the flag will automatically be switched off.
|
||||
consume: OneShotFlag
|
||||
7
src/mpd_now_playable/playback/state.py
Normal file
7
src/mpd_now_playable/playback/state.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from enum import StrEnum
|
||||
|
||||
|
||||
class PlaybackState(StrEnum):
|
||||
play = "play"
|
||||
pause = "pause"
|
||||
stop = "stop"
|
||||
Loading…
Add table
Add a link
Reference in a new issue