Skip to content

Commit 4397acf

Browse files
author
ron.record
committed
Add support for shuffled artist and genre playback
1 parent 1598339 commit 4397acf

File tree

9 files changed

+108
-1035
lines changed

9 files changed

+108
-1035
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dist/*
22
releases/*
33
test/__pycache__/*
4+
test/*.py
45
tmp/*
56
# vim files
67
.*.sw[a-z]

api/play_artist.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
parser = argparse.ArgumentParser()
1818
parser.add_argument("-a", "--artist", help="artist selection")
19+
parser.add_argument(
20+
"-s",
21+
"--shuffled",
22+
default=False,
23+
action="store_true",
24+
help="play artist in shuffled order",
25+
)
1926
parser.add_argument("-x", "--exartist", help="artist exclude search term")
2027
parser.add_argument("-z", "--zone", help="zone selection")
2128
args = parser.parse_args()
@@ -28,6 +35,10 @@
2835
exartistsearch = args.exartist
2936
else:
3037
exartistsearch = None
38+
if args.shuffled:
39+
shuffled = True
40+
else:
41+
shuffled = False
3142
if args.zone:
3243
target_zone = args.zone
3344
else:
@@ -82,8 +93,10 @@
8293
# Play artist from Library
8394
artist = artists[0]
8495
print("Playing artist name", artist)
85-
roonapi.play_media(output_id,
86-
["Library", "Artists", artist], None, False)
96+
if shuffled:
97+
roonapi.play_media(output_id, ["Library", "Artists", artist], "Shuffle", False)
98+
else:
99+
roonapi.play_media(output_id, ["Library", "Artists", artist], None, False)
87100
if len(artists) > 1:
88101
print("\nArtist names partially matching", artistsearch, ":\n")
89102
print(*artists, sep="\n")

api/play_genre.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
parser = argparse.ArgumentParser()
1818
parser.add_argument("-g", "--genre", help="genre selection")
19+
parser.add_argument(
20+
"-s",
21+
"--shuffled",
22+
default=False,
23+
action="store_true",
24+
help="play genre in shuffled order",
25+
)
1926
parser.add_argument("-x", "--exgenre", help="genre exclude search term")
2027
parser.add_argument("-z", "--zone", help="zone selection")
2128
args = parser.parse_args()
@@ -28,6 +35,10 @@
2835
exgenresearch = args.exgenre
2936
else:
3037
exgenresearch = None
38+
if args.shuffled:
39+
shuffled = True
40+
else:
41+
shuffled = False
3142
if args.zone:
3243
target_zone = args.zone
3344
else:
@@ -80,7 +91,10 @@
8091
# Play genre from Library
8192
genre = genres[0]
8293
print("Playing genre title", genre)
83-
roonapi.play_media(output_id, ["Genres", genre], None, False)
94+
if shuffled:
95+
roonapi.play_media(output_id, ["Genres", genre], "Shuffle", False)
96+
else:
97+
roonapi.play_media(output_id, ["Genres", genre], None, False)
8498
if len(genres) > 1:
8599
print("\nGenre titles partially matching", genresearch, ":\n")
86100
print(*genres, sep="\n")

bin/play_artist

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ cd ${ROONAPI} || exit 1
1616

1717
[ -f $PLAY ] || exit 2
1818

19+
SHUFFLED=
1920
ZONE=
20-
# Parse the arguments to get the zone
21-
while getopts "z:" flag; do
21+
# Parse the arguments to get the play order and zone
22+
while getopts "sz:" flag; do
2223
case $flag in
2324
z)
2425
ZONE="$OPTARG"
2526
;;
27+
s)
28+
SHUFFLED="-s"
29+
;;
2630
esac
2731
done
2832
shift $(( OPTIND - 1 ))
@@ -56,8 +60,8 @@ fi
5660
ARTIST="$(echo -e "${ARTIST}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
5761
}
5862
# Construct the exclusion args if passed
59-
EXARGS=
60-
[ "${EXARTIST}" ] && EXARGS="-x ${EXARTIST}"
63+
EXARGS="${SHUFFLED}"
64+
[ "${EXARTIST}" ] && EXARGS="-x ${EXARTIST} ${EXARGS}"
6165

6266
have_python3=$(type -p python3)
6367
if [ "${have_python3}" ]

bin/play_genre

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ cd ${ROONAPI} || exit 1
1616

1717
[ -f $PLAY ] || exit 2
1818

19+
SHUFFLED=
1920
ZONE=
20-
# Parse the arguments to get the zone
21-
while getopts "z:" flag; do
21+
# Parse the arguments to get the play order and zone
22+
while getopts "sz:" flag; do
2223
case $flag in
2324
z)
2425
ZONE="$OPTARG"
2526
;;
27+
s)
28+
SHUFFLED="-s"
29+
;;
2630
esac
2731
done
2832
shift $(( OPTIND - 1 ))
@@ -57,8 +61,8 @@ fi
5761
}
5862

5963
# Construct the exclusion args if passed
60-
EXARGS=
61-
[ "${EXGENRE}" ] && EXARGS="-x ${EXGENRE}"
64+
EXARGS="${SHUFFLED}"
65+
[ "${EXGENRE}" ] && EXARGS="-x ${EXGENRE} ${EXARGS}"
6266

6367
have_python3=$(type -p python3)
6468
if [ "${have_python3}" ]

bin/roon

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ done
16171617
esac
16181618
}
16191619

1620-
# Shuffle action only supported in Playlist playback for now
1620+
# Shuffle action only supported in Artist, Genre, and Playlist playback for now
16211621
shuffled=
16221622
[ "${comm}" == "shuffle" ] && shuffled="-s"
16231623

@@ -1735,15 +1735,15 @@ shuffled=
17351735
[ "${artist}" == "default" ] && artist=
17361736
if [ "${LOCAL}" = true ]; then
17371737
if [ "$zone" ]; then
1738-
play_artist -z "$zone" "$artist" "$exartist"
1738+
play_artist $shuffled -z "$zone" "$artist" "$exartist"
17391739
else
1740-
play_artist "$artist" "$exartist"
1740+
play_artist $shuffled "$artist" "$exartist"
17411741
fi
17421742
else
17431743
if [ "$zone" ]; then
1744-
ssh $user@$server "bash -l -c \"${ROON}/bin/play_artist -z $zone $artist $exartist\""
1744+
ssh $user@$server "bash -l -c \"${ROON}/bin/play_artist $shuffled -z $zone $artist $exartist\""
17451745
else
1746-
ssh $user@$server "bash -l -c \"${ROON}/bin/play_artist $artist $exartist\""
1746+
ssh $user@$server "bash -l -c \"${ROON}/bin/play_artist $shuffled $artist $exartist\""
17471747
fi
17481748
fi
17491749
}
@@ -1767,15 +1767,15 @@ shuffled=
17671767
[ "${genre}" == "default" ] && genre=
17681768
if [ "${LOCAL}" = true ]; then
17691769
if [ "$zone" ]; then
1770-
play_genre -z "$zone" "$genre" "$exalbum"
1770+
play_genre $shuffled -z "$zone" "$genre" "$exalbum"
17711771
else
1772-
play_genre "$genre" "$exalbum"
1772+
play_genre $shuffled "$genre" "$exalbum"
17731773
fi
17741774
else
17751775
if [ "$zone" ]; then
1776-
ssh $user@$server "bash -l -c \"${ROON}/bin/play_genre -z $zone $genre $exalbum\""
1776+
ssh $user@$server "bash -l -c \"${ROON}/bin/play_genre $shuffled -z $zone $genre $exalbum\""
17771777
else
1778-
ssh $user@$server "bash -l -c \"${ROON}/bin/play_genre $genre $exalbum\""
1778+
ssh $user@$server "bash -l -c \"${ROON}/bin/play_genre $shuffled $genre $exalbum\""
17791779
fi
17801780
fi
17811781
}

0 commit comments

Comments
 (0)