Skip to content

Commit 92059a7

Browse files
committed
Add list_playlist_tracks to list a playlist's tracks
1 parent f6c4bc4 commit 92059a7

40 files changed

+426
-37
lines changed

api/list_playlist_tracks.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import argparse
2+
import configparser
3+
from os import path
4+
import sys
5+
6+
config = configparser.ConfigParser()
7+
config.read('/usr/local/Roon/etc/roon_api.ini')
8+
9+
# Set to IP address of your Roon Core
10+
server = config['DEFAULT']['RoonCoreIP']
11+
# Set to Port of your Roon Core
12+
port = config['DEFAULT']['RoonCorePort']
13+
# Name of the file that holds a Roon API token
14+
tokenfile = config['DEFAULT']['TokenFileName']
15+
16+
parser = argparse.ArgumentParser()
17+
parser.add_argument("-t", "--track", help="track search term")
18+
parser.add_argument("-p", "--playlist", help="playlist search term")
19+
parser.add_argument("-X", "--extrack", help="track exclude search term")
20+
parser.add_argument("-x", "--explaylist", help="playlist exclude search term")
21+
parser.add_argument("-z", "--zone", help="zone selection")
22+
args = parser.parse_args()
23+
24+
if args.track:
25+
tracksearch = args.track
26+
else:
27+
tracksearch = "__all__"
28+
if args.playlist:
29+
playlistsearch = args.playlist
30+
else:
31+
playlistsearch = config['DEFAULT']['DefaultArtist']
32+
if args.extrack:
33+
extracksearch = args.extrack
34+
else:
35+
extracksearch = None
36+
if args.explaylist:
37+
explaylistsearch = args.explaylist
38+
else:
39+
explaylistsearch = None
40+
if args.zone:
41+
target_zone = args.zone
42+
else:
43+
target_zone = config['DEFAULT']['DefaultZone']
44+
45+
version = config['DEFAULT']['RoonCommandLineVersion']
46+
release = config['DEFAULT']['RoonCommandLineRelease']
47+
fullver = version + "-" + release
48+
49+
from roonapi import RoonApi
50+
appinfo = {
51+
"extension_id": "roon_command_line",
52+
"display_name": "Python library for Roon",
53+
"display_version": fullver,
54+
"publisher": "RoonCommandLine",
55+
"email": "roon@ronrecord.com",
56+
"website": "https://gitlab.com/doctorfree/RoonCommandLine",
57+
}
58+
59+
# Can be None if you don't yet have a token
60+
if path.exists(tokenfile):
61+
token = open(tokenfile).read()
62+
else:
63+
token = "None"
64+
65+
roonapi = RoonApi(appinfo, token, server, port)
66+
67+
# get target zone output_id
68+
outputs = roonapi.outputs
69+
70+
output_id = None
71+
for (k, v) in outputs.items():
72+
if target_zone in v["display_name"]:
73+
output_id = k
74+
75+
if output_id is None:
76+
err = "No zone found matching " + target_zone
77+
sys.exit(err)
78+
79+
# List matching playlists
80+
playlists = roonapi.list_media(output_id, ["Playlists", playlistsearch])
81+
82+
if playlists:
83+
found = None
84+
for playlist in playlists:
85+
if explaylistsearch is not None:
86+
if explaylistsearch in playlist:
87+
continue
88+
# Search through this playlist's tracks for specified track
89+
tracks = roonapi.list_media(output_id, ["Playlists", playlist, tracksearch])
90+
if tracks:
91+
if "Play Playlist" in tracks:
92+
tracks.remove("Play Playlist")
93+
# List matching tracks
94+
if extracksearch is not None and tracks:
95+
tracks = [chktrack for chktrack in tracks if not extracksearch in chktrack]
96+
if tracks:
97+
if "Play Playlist" in tracks:
98+
tracks.remove("Play Playlist")
99+
found = tracks[0]
100+
if tracksearch == "__all__":
101+
print("\nTrack titles on playlist", playlist, ":\n")
102+
else:
103+
print("\nTrack titles on playlist", playlist, "matching", tracksearch, ":\n")
104+
print(*tracks, sep = "\n")
105+
if found is None:
106+
print("No tracks found matching", tracksearch)
107+
else:
108+
print("No playlists found matching ", playlistsearch)
109+
110+
# save the token for next time
111+
with open(tokenfile, "w") as f:
112+
f.write(str(roonapi.token))

bin/list_playlist_tracks

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
ROON=/usr/local/Roon
4+
ROONAPI=${ROON}/api
5+
ROONETC=${ROON}/etc
6+
ROONCONF=${ROONETC}/pyroonconf
7+
LIST=list_playlist_tracks.py
8+
PLAYLIST=
9+
TRACK=
10+
EXPLAYLIST=
11+
EXTRACK=
12+
13+
[ -d ${ROONAPI} ] || exit 1
14+
15+
cd ${ROONAPI}
16+
17+
[ -f $LIST ] || exit 2
18+
19+
# First argument is playlist, second is track
20+
# Third optional argument is playlist exclusion string (optional)
21+
# Fourth optional argument is track exclusion string (optional)
22+
[ "$1" ] && PLAYLIST="$1"
23+
[ "$2" ] && TRACK="$2"
24+
[ "$3" ] && EXPLAYLIST="$3"
25+
[ "$4" ] && EXTRACK="$4"
26+
27+
# Get the zone if it is set
28+
if [ -f ${ROONCONF} ]
29+
then
30+
. ${ROONCONF}
31+
else
32+
DEFZONE=`grep ^DefaultZone ${ROONETC}/roon_api.ini | awk -F '=' ' { print $2 } '`
33+
${ROON}/bin/set_zone $DEFZONE
34+
. ${ROONCONF}
35+
fi
36+
37+
# Get the default playlist if one is not provided
38+
[ "${PLAYLIST}" ] || {
39+
PLAYLIST=`grep ^DefaultPlaylist ${ROONETC}/roon_api.ini | awk -F '=' ' { print $2 } '`
40+
# Remove leading and trailing spaces in PLAYLIST
41+
PLAYLIST="$(echo -e "${PLAYLIST}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
42+
}
43+
44+
[ "${TRACK}" ] || TRACK="__all__"
45+
46+
# Construct the exclusion args if passed
47+
EXARGS=
48+
[ "${EXTRACK}" ] && EXARGS="-X ${EXTRACK}"
49+
[ "${EXPLAYLIST}" ] && EXARGS="-x ${EXPLAYLIST} ${EXARGS}"
50+
51+
have_python3=`type -p python3`
52+
if [ "${have_python3}" ]
53+
then
54+
python3 $LIST -t "$TRACK" -p "$PLAYLIST" -z "$ROON_ZONE" $EXARGS
55+
else
56+
python $LIST -t "$TRACK" -p "$PLAYLIST" -z "$ROON_ZONE" $EXARGS
57+
fi

bin/roon

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ zonelist=
6767
usage() {
6868
[ "${showusage}" ] && {
6969
printf "\nUsage: roon -A album -a artist -C composer -g genre -G zone_group -i"
70-
printf "\n\t-l [albums|artists|artalbums|arttracks|composers|comalbums|genres|genalbums|genartists|playlists|tags|zones]"
70+
printf "\n\t-l [albums|artists|artalbums|arttracks|composers|comalbums|genres|genalbums|genartists|playlists|playtracks|tags|zones]"
7171
printf "\n\t-c [group|ungroup|play|play_all|pause|pause_all|stop|stop_all|next|previous|shuffle|repeat|mute|mute_all]"
7272
printf "\n\t-s search -p playlist -T track -t tag -z zone -L -S -r radio"
7373
printf "\n\t-X ex_album -x ex_artist [-EuU]"
@@ -83,7 +83,7 @@ usage() {
8383
printf "\n\t-G zone_group specifies a zone grouping specified in roon_api.ini"
8484
printf "\n\t-L setup roon to execute local commands rather than remote via SSH"
8585
printf "\n\t-S Set Roon defaults in roon_api.ini"
86-
printf "\n\t-l [albums|artists|artalbums|arttracks|composers|comalbums|genres|genalbums|genartists|playlists|tags|zones]"
86+
printf "\n\t-l [albums|artists|artalbums|arttracks|composers|comalbums|genres|genalbums|genartists|playlists|playtracks|tags|zones]"
8787
printf "\n\t\tindicates list albums, artists, albums by artist, composers, albums by composers, genres, albums in genre, artists in genre, playlists, tags, or Roon zones"
8888
printf "\n\t-r radio selects a live radio stream to play"
8989
printf "\n\t-s search specifies a term to search for in the lists retrieved with -l"
@@ -971,6 +971,9 @@ while getopts A:a:c:C:g:G:inp:T:t:z:l:s:LSr:v:x:X:EuU flag; do
971971
elif [ "$listname" == "arttracks" ] || [ "$listname" == "arttrack" ]
972972
then
973973
arttracklist=1
974+
elif [ "$listname" == "playtracks" ] || [ "$listname" == "playtrack" ]
975+
then
976+
playtracklist=1
974977
elif [ "$listname" == "composers" ] || [ "$listname" == "composer" ]
975978
then
976979
composerlist=1
@@ -1222,6 +1225,23 @@ done
12221225
track=
12231226
artist=
12241227
}
1228+
[ "$playtracklist" ] && {
1229+
[ "$playlist" ] || {
1230+
[ "$search" ] && playlist=$search
1231+
}
1232+
[ "$track" ] || track="__all__"
1233+
[ "${extrack}" ] && {
1234+
[ "${explaylist}" ] || explaylist="None"
1235+
}
1236+
if [ "${LOCAL}" = true ]
1237+
then
1238+
list_playlist_tracks "$playlist" "$track" "$explaylist" "$extrack"
1239+
else
1240+
ssh $user@$server "bash -l -c \"${ROON}/bin/list_playlist_tracks $playlist $track $explaylist $extrack\""
1241+
fi
1242+
track=
1243+
playlist=
1244+
}
12251245
[ "$comalbumlist" ] && {
12261246
[ "$composer" ] || {
12271247
[ "$search" ] && composer=$search

man/man1/clone_pyroon.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

man/man1/get_core_ip.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

man/man1/get_zone_info.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

man/man1/get_zones.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

man/man1/list_albums.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

man/man1/list_artist_albums.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

man/man1/list_artist_tracks.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" Automatically generated by Pandoc 2.17.1.1
1+
.\" Automatically generated by Pandoc 2.19.2
22
.\"
33
.\" Define V font for inline verbatim, using C font in formats
44
.\" that render this, and otherwise B font.

0 commit comments

Comments
 (0)