-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic.py
executable file
·37 lines (28 loc) · 1.06 KB
/
music.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 mpd import MPDClient
import time
def get_music(addr, port):
err = ''
try:
client = MPDClient()
client.connect(addr, port)
client.update()
status = client.status()
song = client.currentsong()
if bool(song):
if status["state"] == "pause":
toggle ="⏸️"
elif status["state"] == "stop":
toggle = "⏹️"
else:
toggle = f"▶️"
artist = song.get('artist', '')
title = song.get('title', '')
album = song.get('album', '')
duration_seconds = float(status['duration'])
elapsed_seconds = float(status['elapsed'])
time_left_unix_time = int(time.time()) + int(duration_seconds - elapsed_seconds)
else:
return ('', '', '', "No songs in queue")
except ConnectionError:
return ('', '', '', "MPD Offline")
return (title, artist, toggle, err, album, time_left_unix_time, int(duration_seconds - elapsed_seconds))