Skip to content

Commit

Permalink
Fix now_playing, add state to now_playing
Browse files Browse the repository at this point in the history
  • Loading branch information
ron.record committed May 26, 2024
1 parent 9b61ded commit f53c3cc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 34 deletions.
65 changes: 36 additions & 29 deletions api/now_playing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def signal_handler(sig, frame):

parser = argparse.ArgumentParser()
parser.add_argument("-z", "--zone", help="zone selection")
parser.add_argument("-p", "--playing", default=False, action='store_true',
help="display only zones in playing state")
parser.add_argument("-a", "--all", default=False, action='store_true',
help="display all zones regardless of state")
args = parser.parse_args()
Expand All @@ -36,10 +38,10 @@ def signal_handler(sig, frame):
target_zone = None
else:
target_zone = None
if args.all:
filterplaying = None
else:
if args.playing:
filterplaying = 1
else:
filterplaying = None

appinfo = {
"extension_id": "roon_command_line",
Expand Down Expand Up @@ -73,18 +75,22 @@ def signal_handler(sig, frame):
if filterplaying is not None and state != "playing":
continue
else:
zone_name = zone["display_name"]
print("\nNow playing in zone: %s" % zone_name)
track = json.dumps(zone["now_playing"]["three_line"]["line1"],
ensure_ascii=False).encode('utf8')
print("\tTrack:\t %s" % track.decode())
artist = json.dumps(zone["now_playing"]["three_line"]["line2"],
ensure_ascii=False).encode('utf8')
print("\tArtist:\t %s" % artist.decode())
album = json.dumps(zone["now_playing"]["three_line"]["line3"],
ensure_ascii=False).encode('utf8')
print("\tAlbum:\t %s" % album.decode())
print("\tState:\t %s" % state)
if "display_name" in zone:
zone_name = zone["display_name"]
else:
zone_name = "Unknown"
if "now_playing" in zone and zone["now_playing"] is not None:
print("\nNow playing in zone: %s" % zone_name)
track = json.dumps(zone["now_playing"]["three_line"]["line1"],
ensure_ascii=False).encode('utf8')
print("\tTrack:\t %s" % track.decode())
artist = json.dumps(zone["now_playing"]["three_line"]["line2"],
ensure_ascii=False).encode('utf8')
print("\tArtist:\t %s" % artist.decode())
album = json.dumps(zone["now_playing"]["three_line"]["line3"],
ensure_ascii=False).encode('utf8')
print("\tAlbum:\t %s" % album.decode())
print("\tState:\t %s" % state)
else:
for (k, v) in outputs.items():
if target_zone in v["display_name"]:
Expand All @@ -98,17 +104,18 @@ def signal_handler(sig, frame):
if filterplaying is not None and state != "playing":
continue
else:
print("\nNow playing in zone: %s" % zone_name)
track = json.dumps(
zone["now_playing"]["three_line"]["line1"],
ensure_ascii=False).encode('utf8')
print("\tTrack:\t %s" % track.decode())
artist = json.dumps(
zone["now_playing"]["three_line"]["line2"],
ensure_ascii=False).encode('utf8')
print("\tArtist:\t %s" % artist.decode())
album = json.dumps(
zone["now_playing"]["three_line"]["line3"],
ensure_ascii=False).encode('utf8')
print("\tAlbum:\t %s" % album.decode())
print("\tState:\t %s" % state)
if zone["now_playing"] is not None:
print("\nNow playing in zone: %s" % zone_name)
track = json.dumps(
zone["now_playing"]["three_line"]["line1"],
ensure_ascii=False).encode('utf8')
print("\tTrack:\t %s" % track.decode())
artist = json.dumps(
zone["now_playing"]["three_line"]["line2"],
ensure_ascii=False).encode('utf8')
print("\tArtist:\t %s" % artist.decode())
album = json.dumps(
zone["now_playing"]["three_line"]["line3"],
ensure_ascii=False).encode('utf8')
print("\tAlbum:\t %s" % album.decode())
print("\tState:\t %s" % state)
9 changes: 7 additions & 2 deletions api/zone_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ def signal_handler(sig, frame):
ensure_ascii=False).encode('utf8')
album = json.dumps(zone["now_playing"]["three_line"]["line3"],
ensure_ascii=False).encode('utf8')
state = "Unknown"
if zone["state"] is not None:
state = zone["state"]
if args.verbose:
print("\nNow playing: {")
print("\t\"Track\": %s," % track.decode())
print("\t\"Artist\": %s," % artist.decode())
print("\t\"Album\": %s\n}" % album.decode())
print("\t\"Album\": %s," % album.decode())
print("\t\"State\": \"%s\"\n}" % state)
else:
print("{\n\t\"Track\": %s," % track.decode())
print("\t\"Artist\": %s," % artist.decode())
print("\t\"Album\": %s\n}" % album.decode())
print("\t\"Album\": %s," % album.decode())
print("\t\"State\": \"%s\"\n}" % state)
10 changes: 7 additions & 3 deletions bin/now_playing
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ else
fi

aflag=
while getopts "az:" flag; do
pflag=
while getopts "apz:" flag; do
case $flag in
z)
ZONE="$OPTARG"
;;
a)
aflag="-a"
;;
p)
pflag="-p"
;;
esac
done

Expand All @@ -55,7 +59,7 @@ fi

have_rich=$(type -p rich)
if [ "${have_rich}" ]; then
${PYTHON} $NOWP ${aflag} -z "${ZONE}" | while read lin
${PYTHON} $NOWP ${aflag} ${pflag} -z "${ZONE}" | while read lin
do
if echo "${lin}" | grep : >/dev/null; then
key=$(echo "${lin}" | awk -F ':' '{ print $1 }')
Expand All @@ -82,5 +86,5 @@ if [ "${have_rich}" ]; then
fi
done
else
${PYTHON} $NOWP ${aflag} -z "${ZONE}"
${PYTHON} $NOWP ${aflag} ${pflag} -z "${ZONE}"
fi

0 comments on commit f53c3cc

Please sign in to comment.