-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpd.py
79 lines (54 loc) · 1.79 KB
/
mpd.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import sys
import commands
global track_data
global status_lines
def init():
global track_data
global status_lines
track_data = ''
mpc_status_output = commands.getoutput('mpc status -f "[[%artist% / %title% / %album%]|[%file%]]"');
status_lines = mpc_status_output.split(os.linesep)
if(len(status_lines) > 1):
track_data = status_lines[0].split("/")
def get_title():
title = ''
if(len(status_lines) > 1):
if(len(track_data) == 3):
title = track_data[1].strip()
if(len(track_data) == 2):
title = track_data[1].strip()
return title
def get_artist():
artist = ''
if(len(status_lines) > 1):
if(len(track_data) == 3):
title = track_data[0].strip()
if(len(track_data) == 2):
title = track_data[0].strip()
return artist
def get_album():
album = ''
if(len(status_lines) > 1):
if(len(track_data) == 3):
title = track_data[0].strip()
if(len(track_data) == 2):
title = track_data[0].strip()
return album
def get_duration():
total_duration = 0
if(len(status_lines) > 1):
player_details = status_lines[1].split(" ")
track_duration = player_details[-2].split("/")[1]
time_split = track_duration.split(":")
if(len(time_split) == 2):
total_duration = int(time_split[0]) * 60 + int(time_split[1])
else:
total_duration = int(time_split[0]) * 60 + int(time_split[1]) * 60 + int(time_split[2])
return total_duration
def get_player_state():
player_state = 'stopped'
if(len(status_lines) > 1):
player_details = status_lines[1].split(" ")
player_state = player_details[0].strip("[]")
return player_state