-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpdinfo
executable file
·76 lines (66 loc) · 2.07 KB
/
mpdinfo
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
#!/usr/bin/env python3
from os import path, environ, chdir
from subprocess import Popen
from glob import glob
from mpd import MPDClient
def get_albumart(file_path):
chdir(path.split(file_path)[0])
cover_paths = glob(
'[C|c]over.*',
recursive=True
)
if cover_paths:
return path.join(path.split(file_path)[0], cover_paths[0])
else:
return path.join(environ['HOME'], 'scripts/cover.png')
def get_sticker(client, song, sticker):
try:
return int(client.sticker_get('song', song, sticker))
except:
return 0
def get_rating(case):
rating = {
0: '六 六 六 六 六 ',
1: '留 六 六 六 六 ',
2: '留 留 六 六 六 ',
3: '留 留 留 六 六 ',
4: '留 留 留 留 六 ',
5: '留 留 留 留 留 '
}
return rating.get(case, '?')
def get_favourite(case):
favourite = {
0: ' ',
1: ' '
}
return favourite.get(case, ' ')
def get_dunst_title(song):
return ' {}'.format(song.get('title', '?'))
def get_dunst_description(song, stars, favourite):
return '\n {}\n by {}\n {}{}'.format(
song.get('album', '?'),
song.get('artist', '?'),
get_rating(stars),
get_favourite(favourite)
)
def main(host='localhost', port=6600, dunst_id=99000):
client = MPDClient()
client.connect(host, port)
current_song = client.currentsong()
stars = get_sticker(client, current_song['file'], 'stars')
favourite = get_sticker(client, current_song['file'], 'favourite')
client.close()
client.disconnect()
if not current_song:
exit()
else:
file_path = path.join(environ['MUSIC'], current_song['file'])
dunst_cmd = 'dunstify -u normal -i "{}" "{}" "{}" -r {}'.format(
get_albumart(file_path),
get_dunst_title(current_song),
get_dunst_description(current_song, stars, favourite),
dunst_id
)
Popen(dunst_cmd, shell=True)
if __name__ == '__main__':
main()