-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
play_genre_artist
executable file
·89 lines (75 loc) · 2.19 KB
/
play_genre_artist
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#
# shellcheck disable=SC1090,SC2220
ROON=/usr/local/Roon
ROONAPI=${ROON}/api
ROONETC=${ROON}/etc
ROONCONF=${ROONETC}/pyroonconf
PLAY=play_genre_artist.py
GENRE=
ARTIST=
EXGENRE=
EXARTIST=
[ -d ${ROONAPI} ] || exit 1
cd ${ROONAPI} || exit 1
[ -f $PLAY ] || exit 2
ZONE=
# Parse the arguments to get the zone
while getopts "z:" flag; do
case $flag in
z)
ZONE="$OPTARG"
;;
esac
done
shift $(( OPTIND - 1 ))
# First argument is genre, second is artist (required)
# Third optional argument is genre exclusion string (optional)
# Fourth optional argument is artist exclusion string (optional)
[ "$1" ] && GENRE="$1"
[ "$2" ] && ARTIST="$2"
[ "$3" ] && EXGENRE="$3"
[ "$4" ] && EXARTIST="$4"
# Use a Python virtual environment
[ -f ${ROON}/venv/bin/activate ] && source ${ROON}/venv/bin/activate
[[ ":$PATH:" == *":/usr/local/Roon/venv/bin:"* ]] || {
export PATH=/usr/local/Roon/venv/bin:${PATH}
}
DEFZONE=$(grep ^DefaultZone ${ROONETC}/roon_api.ini | awk -F '=' ' { print $2 } ')
# Remove leading and trailing spaces in DEFZONE
DEFZONE="$(echo -e "${DEFZONE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Get the zone if it is set
if [ -f ${ROONCONF} ]
then
. ${ROONCONF}
else
${ROON}/bin/set_zone "${DEFZONE}"
. ${ROONCONF}
fi
[ "${ZONE}" ] && {
if [ "${ZONE}" == "default" ]; then
ROON_ZONE="${DEFZONE}"
else
[ "${ZONE}" == "last" ] || ROON_ZONE="${ZONE}"
fi
}
# Use all zones if no zone is specified or set
[ "${ROON_ZONE}" ] || ROON_ZONE="__all__"
# Get the default genre if one is not provided
[ "${GENRE}" ] || {
GENRE=$(grep ^DefaultGenre ${ROONETC}/roon_api.ini | awk -F '=' ' { print $2 } ')
# Remove leading and trailing spaces in GENRE
GENRE="$(echo -e "${GENRE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
}
[ "${ARTIST}" ] || ARTIST="__all__"
# Construct the exclusion args if passed
EXARGS=
[ "${EXARTIST}" ] && EXARGS="-X ${EXARTIST}"
[ "${EXGENRE}" ] && EXARGS="-x ${EXGENRE} ${EXARGS}"
have_python3=$(type -p python3)
if [ "${have_python3}" ]
then
python3 $PLAY -a "$ARTIST" -g "$GENRE" -z "$ROON_ZONE" $EXARGS
else
python $PLAY -a "$ARTIST" -g "$GENRE" -z "$ROON_ZONE" $EXARGS
fi