/
print_current_uri.py
44 lines (33 loc) · 1.06 KB
/
print_current_uri.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
import soco
from soco.snapshot import Snapshot
import sys
class UndiscoverablePlayerError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def discover_target_sonos_player(target_name):
zones = soco.discover()
if zones == None:
print "No Sonos players discovered on this network."
else:
for zone in zones:
if zone.player_name == target_name:
return zone
raise UndiscoverablePlayerError(target_name)
sonos_player_name = "Kitchen"
try:
player = discover_target_sonos_player(sonos_player_name)
except UndiscoverablePlayerError as e:
print "Can't find the target Sonos player " + e.value
sys.exit(0)
sonos = soco.SoCo(player.ip_address)
snap = Snapshot(sonos) # create snapshot class
snap.snapshot() # take a snapshot of current state
if snap.media_uri == "":
print "No media uri found - is the Sonos player playing something?"
else:
print 'media_uri: ', snap.media_uri
sys.exit(0)
if __name__ == "__main__":
main()