-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetplaylistid.py
28 lines (22 loc) · 933 Bytes
/
getplaylistid.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
#!/usr/bin/env python3
import argparse
import soco
# Defaults
SPEAKER_NAME = "Playroom"
PLAYLIST_NAME = ""
# Define and parse command line arguments
parser = argparse.ArgumentParser(description="Get Sonos Playlist ID")
parser.add_argument("-p", "--playlist", help="name of the Sonos playlist to search for")
parser.add_argument("-s", "--speaker", help="speaker to be used as output device")
# Eventually override the defaults with command line arguments
args = parser.parse_args()
if args.playlist:
PLAYLIST_NAME = args.playlist
if args.speaker:
SPEAKER_NAME = args.speaker
speaker = soco.discovery.by_name(SPEAKER_NAME)
print("Found speaker: " + speaker.player_name + " (" + speaker.ip_address + ")")
# Get playlist by title
print("Getting ID for Sonos playlist " + PLAYLIST_NAME)
playlist = speaker.get_sonos_playlist_by_attr('title', PLAYLIST_NAME)
print("Sonos playlist " + PLAYLIST_NAME + " has ID " + playlist.item_id)