From 29f39c5e830d05926fa489ff48f2152fd1e77826 Mon Sep 17 00:00:00 2001 From: Salt Date: Thu, 26 Sep 2019 16:58:37 -0500 Subject: [PATCH] Add Audacious support --- ptgdp | 28 +++++++++++++++++++++++++--- ptgdp.conf | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ptgdp b/ptgdp index 614b55c..220a13b 100755 --- a/ptgdp +++ b/ptgdp @@ -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 diff --git a/ptgdp.conf b/ptgdp.conf index cd2db61..70a50a5 100644 --- a/ptgdp.conf +++ b/ptgdp.conf @@ -4,7 +4,7 @@ # # The media player backend to use -# Supported: mpd +# Supported: mpd, audacious # Default: mpd backend=mpd