-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubiPlay.py
More file actions
79 lines (66 loc) · 2.56 KB
/
SubiPlay.py
File metadata and controls
79 lines (66 loc) · 2.56 KB
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
#!/usr/bin/env python
#import os, sys, re, time
#import sqlite3
#import pandas as pd
#database_file = 'dbTools/subibox.sqlite.full'
#database_file = 'dbTools/subibox.sqlite'
#conn = sqlite3.connect(database_file)
import mpd
from mpd import MPDClient
mpd_host = "192.168.1.81"
mpd_port = "6600"
#client.close() # send the close command
#client.disconnect() # disconnect from the server
class Play():
def __init__(self):
self.client = MPDClient() # create client object
#client.timeout = 10 # network timeout in seconds (floats allowed), default: None
#client.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None
def connect(self):
try:
self.client.connect(mpd_host, mpd_port)
print("MPD Version: " + self.client.mpd_version) # print the MPD version
except OSError:
print("Error connecting to MPD")
except mpd.ConnectionError:
# Already connected?
pass
def current_track_info(self):
self.connect()
try:
return self.client.currentsong()
except mpd.ConnectionError:
print("[ERROR] current_track_info(): mpd.ConnectionError")
return None
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
return None
def next_track(self):
self.connect()
try:
self.client.next()
except mpd.ConnectionError:
print("[ERROR] next_track(): mpd.ConnectionError")
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
def pause(self):
self.connect()
try:
self.client.pause()
except mpd.ConnectionError:
print("[ERROR] pause(): mpd.ConnectionError")
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
def play_album(self, album_path):
self.connect()
# mpc -h 192.168.1.80 -p 6600 listall Yeah_Yeah_Yeahs/
# Maybe you need album_path[1:]?
print("Requesting mpd play album: {}".format(album_path[1:]))
try:
self.client.clear()
self.client.add(album_path) # [1:] to strip leading /
self.client.play()
except mpd.ConnectionError:
print("[ERROR] play_album(): mpd.ConnectionError")
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")