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

View File

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