Add minimal ptgdp script

This commit is contained in:
Salt 2019-09-26 03:34:42 -05:00
parent 27d3f3e4d5
commit 871841a7fa

97
ptgdp Executable file
View File

@ -0,0 +1,97 @@
#! /bin/bash
#
# ptgdp - Play the Goddamned Playlist
# Copyright (C) 2019 Vintage Salt <rehashedsalt@cock.li>
#
# Distributed under terms of the MIT license.
#
set -e
# Read-only set-once variables
declare -r _name="$(basename -- "$0")"
# Options
declare -i _opthelp
declare -i _optverbose=0
# Working variables
declare _return
# Helper Functions
log() {
# Print a line to the terminal if _optverbose is greater than $2
# $2 defaults to 0
[ -z "$1" ] && return 1
if [ "$_optverbose" -ge "${2:-0}" ]; then
printf "%s\\n" "$1"
fi
}
error() {
# Print a red line to the terminal, exit if $2 is specified
[ -z "$1" ] && return 1
if [ -t 2 ]; then
printf "\\e[31m%s\\e[0m\\n" "$1" 1>&2
else
printf "ERROR: %s\\n" "$1" 1>&2
fi
[ -n "$2" ] && exit "${2:-1}"
}
has() {
# Parse out all arguments and try to find them in path
# If an argument cannot be found, set _return and fail
[ -z "$@" ] && return 0
for prog in $@; do
if ! command -v "$prog" > /dev/null 2>&1; then
_return="$prog"
return 1
fi
done
return 0
}
# Core program functions
printhelp() {
cat << EOF
Usage: $_name [OPTION]... [FILE]...
Use youtube-dl and a music player to queue up or download a number of songs
given plaintext files with only search queries
-h Print this help text
-v Print more status messages. Stacks
Copyright (c) 2019 rehashedsalt@cock.li
Licensed under the MIT license
EOF
}
# Main
main() {
# Getopts before anything else
while getopts ":hv" opt; do
case $opt in
h)
_opthelp=1
;;
v)
_optverbose+=1
;;
:)
error "Option requires argument: -$OPTARG" 2
;;
*)
error "Invalid option: -$OPTARG" 2
;;
esac
done
# Pre-really-do-stuff hooks like help text
[ -n "$_opthelp" ] && printhelp && exit 0
# Do the do
log "Validating dependencies" 1
if ! has youtube-dl; then
error "Failed to validate dependency on program: $_return" 1
fi
exit 0
}
main "$@"