-
Notifications
You must be signed in to change notification settings - Fork 4
/
player.py
executable file
·37 lines (28 loc) · 970 Bytes
/
player.py
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
from itertools import cycle, islice
from os import system
from subprocess import PIPE, run
from sys import argv
STATUS_MAP = {
"loop": ["None", "Track", "Playlist"],
"shuffle": ["On", "Off"],
}
def get_status(cmd: str) -> str:
return (
run(["playerctl", "-p", "spotify", cmd], stdout=PIPE).stdout.decode().rstrip()
)
def send_cmd(cmd: str, status: str = "") -> None:
system(f"playerctl -p spotify {cmd} {status}")
def send_notify(text: str) -> None:
system(f'notify-send "{text}"')
match argv:
case [_, ("play" | "pause")]:
send_cmd("play-pause")
case [_, ("previous" | "next") as direction]:
send_cmd(direction)
case [_, ("loop" | "shuffle") as cmd]:
status_list = STATUS_MAP[cmd]
next_status = next(
islice(cycle(status_list), status_list.index(get_status(cmd)) + 1, None)
)
send_cmd(cmd, next_status)
send_notify(f"{cmd.title()}: {next_status}")