-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpd_player.py
57 lines (43 loc) · 1.4 KB
/
mpd_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
import subprocess
log = logging.getLogger(__name__)
class Player:
def load_list(self, list_dir):
self.mpc_command('clear')
self.mpc_command('mpc ls {} | mpc --wait add'.format(list_dir), custom_command=True)
result = self.mpc_command('playlist')
log.info(result)
def play(self):
self.mpc_command('play')
self.current()
def next(self):
self.mpc_command('next')
self.current()
def prev(self):
self.mpc_command('prev')
self.current()
def stop(self):
self.mpc_command('stop')
def pause(self):
self.mpc_command('pause')
def toggle(self):
self.mpc_command('toggle')
self.current()
def current(self):
result = self.mpc_command('mpc current', custom_command=True)
log.info(result)
def is_playing(self):
result = self.mpc_command('mpc status | awk \'NR==2\'', custom_command=True)
return 'playing' in result
@staticmethod
def update():
Player.mpc_command('update')
@staticmethod
def mpc_command(command, custom_command=False):
if not custom_command:
mpc_prefix = 'mpc -q --wait'
mpc_command = ' '.join([mpc_prefix, command])
else:
mpc_command = command
result = subprocess.check_output(mpc_command, shell=True)
return result.decode('utf8')