From 6c71a0bb94e5403872214858109f202cd54be6f9 Mon Sep 17 00:00:00 2001 From: Salt Date: Thu, 26 Sep 2019 17:28:04 -0500 Subject: [PATCH] More log changes, add download-only option --- README.md | 6 +++--- ptgdp | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a0e16ea..b343a32 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ A tool to play a plaintext playlist composed entirely of youtube-dl search queri ## Installation -Put `ptgdp` somewhere in `$PATH` and install `youtube-dl`. +Put `ptgdp` somewhere in `$PATH` and install youtube-dl. Additionally, you need some implementation of `pgrep`, which is probably already on your system, and Bash. ## Quickstart Make a file containing a few download queries. For example: - myplaylist.gdp + myplaylist ``` alice in chains love hate love @@ -20,7 +20,7 @@ tool parabola Then invoke `ptgdp`: - ptgdp myplaylist.gdp + ptgdp myplaylist See below for more intricate usage. diff --git a/ptgdp b/ptgdp index 220a13b..d45069b 100755 --- a/ptgdp +++ b/ptgdp @@ -25,6 +25,7 @@ declare -A _config=( ) declare _optconfigfile="${XDG_CONFIG_HOME:-$HOME/.config}/${_name}.conf" declare -i _optautoplay=0 +declare -i _optdlonly declare -i _opthelp declare -i _optverbose # Working variables @@ -226,11 +227,13 @@ backend-execqueue() { fi ;; esac - for song in "${_queue[@]}"; do - backend-enqueue "$song" - done - if [ "$_optautoplay" != "0" ]; then - backend-play + if [ -z "$_optdlonly" ]; then + for song in "${_queue[@]}"; do + backend-enqueue "$song" + done + if [ "$_optautoplay" != "0" ]; then + backend-play + fi fi } @@ -242,6 +245,7 @@ Use youtube-dl and a music player to queue up or download a number of songs given plaintext files with only search queries -c [FILE] Load the given file in place of the usual config file + -d Download songs but don't queue them up -h Print this help text -p Play the queue after it's built -v Print more status messages. Stacks @@ -288,11 +292,14 @@ playlist() { # Main main() { # Getopts before anything else - while getopts ":c:hpv" opt; do + while getopts ":c:dhpv" opt; do case $opt in c) _optconfigfile="$OPTARG" ;; + d) + _optdlonly=1 + ;; h) _opthelp=1 ;; @@ -322,6 +329,8 @@ main() { log "Setting $varname to $value" 2 fi done < "$_optconfigfile" + else + warn "Could not find configuration file" 2 fi # Store arguments shift $((OPTIND - 1)) @@ -344,7 +353,7 @@ main() { error "Missing dependency for backend ${_config[backend]}: $_return" 50 ;; *) - error "Dependency error: $errorcode: $_return" 50 + error "Backend error: $errorcode: $_return" 50 ;; esac fi @@ -354,15 +363,15 @@ main() { # Do the do log "Validating dependencies" 2 - if ! has youtube-dl; then - error "Failed to validate dependency on program: $_return" 1 + if ! has youtube-dl pgrep; then + error "Failed to find program: $_return" 1 fi if [ -n "${_args[*]}" ]; then for arg in "${_args[@]}"; do playlist "$arg" done else - log "Nothing to do" + warn "Nothing to do" exit 0 fi }