Add Audacious support

This commit is contained in:
Salt 2019-09-26 16:58:37 -05:00
parent 25b12e5398
commit 29f39c5e83
2 changed files with 26 additions and 4 deletions

28
ptgdp
View File

@ -15,7 +15,7 @@ unset _xdguserdirs
declare -r _name="$(basename -- "$0")"
declare -r _musicdir="${XDG_MUSIC_DIR:-$HOME/Music}"
declare -r _ptgdpmusicdir="$_musicdir/PTGDP Songs"
declare -ra _supportedbackends=("mpd")
declare -ra _supportedbackends=("mpd" "audacious")
# May-need-amended variables
declare _mpdroot="$_musicdir"
# Options
@ -44,6 +44,13 @@ log() {
printf "%s\\n" "$1"
fi
}
warn() {
# Print a yellow line to the terminal, respecting _optverbose
[ -z "$1" ] && return 1
if (( _optverbose >= ${2:-0} )); then
printf "\\e[33m%s\\e[0m\\n" "$1"
fi
}
error() {
# Print a red line to the terminal, exit if $2 is specified
[ -z "$1" ] && return 1
@ -161,6 +168,9 @@ backend-validate() {
) || return $?
# Backend-specific checks
case ${_config[backend]} in
audacious)
has audacious audtool || return 1
;;
mpd)
has mpd mpc || return 1
pgrep mpd > /dev/null 2>&1 || return 2
@ -172,6 +182,10 @@ backend-enqueue() { # Enqueues a song
# Note: mpd will assume you've updated the library since!
[ -z "$1" ] && return 1
case ${_config[backend]} in
audacious)
audtool --playlist-addurl "$1"
return 0
;;
mpd)
file=${1##$_mpdroot/}
if ! mpc add "$file"; then
@ -185,6 +199,9 @@ backend-enqueue() { # Enqueues a song
backend-play() {
# Plays a set up queue
case ${_config[backend]} in
audacious)
audtool --playback-play
;;
mpd)
if ! mpc play > /dev/null 2>&1; then
error "Could not play queue ($?)"
@ -198,6 +215,11 @@ backend-play() {
backend-execqueue() {
# Executes a queue, enqueueing files and autoplaying if configured
case ${_config[backend]} in
audacious)
if ! pgrep audacious > /dev/null 2>&1; then
warn "Audacious is not running; songs will be downloaded but not enqueued"
fi
;;
mpd)
if ! mpc update --wait > /dev/null 2>&1; then
error "Failed to update mpd library" 51
@ -335,8 +357,8 @@ main() {
if ! has youtube-dl; then
error "Failed to validate dependency on program: $_return" 1
fi
if [ -n "${_args[@]}" ]; then
for arg in ${_args[@]}; do
if [ -n "${_args[*]}" ]; then
for arg in "${_args[@]}"; do
playlist "$arg"
done
else

View File

@ -4,7 +4,7 @@
#
# The media player backend to use
# Supported: mpd
# Supported: mpd, audacious
# Default: mpd
backend=mpd