Add support for a config file
This commit is contained in:
parent
ec56861b40
commit
5546950fd5
10
README.md
10
README.md
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
A tool to play a plaintext playlist composed entirely of youtube-dl search queries
|
A tool to play a plaintext playlist composed entirely of youtube-dl search queries
|
||||||
|
|
||||||
## Setup
|
## Installation
|
||||||
|
|
||||||
|
Put `ptgdp` somewhere in `$PATH` and install `youtube-dl`.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
Make a file containing a few download queries. For example:
|
Make a file containing a few download queries. For example:
|
||||||
|
|
||||||
@ -20,6 +24,10 @@ Then invoke `ptgdp`:
|
|||||||
|
|
||||||
See below for more intricate usage.
|
See below for more intricate usage.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Move `ptgdp.conf` from this repo to `~/.config/ptgdp.conf` and change the values as you see fit.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
See `LICENSE` (hint: it's MIT, just like the header says).
|
See `LICENSE` (hint: it's MIT, just like the header says).
|
||||||
|
32
ptgdp
32
ptgdp
@ -9,7 +9,12 @@ set -e
|
|||||||
|
|
||||||
# Read-only set-once variables
|
# Read-only set-once variables
|
||||||
declare -r _name="$(basename -- "$0")"
|
declare -r _name="$(basename -- "$0")"
|
||||||
|
declare -ra _supportedbackends=("mpd")
|
||||||
# Options
|
# Options
|
||||||
|
declare -A _config=(
|
||||||
|
[backend]="mpd"
|
||||||
|
)
|
||||||
|
declare _optconfigfile="${XDG_CONFIG_HOME:-$HOME/.config}/${_name}.conf"
|
||||||
declare -i _opthelp
|
declare -i _opthelp
|
||||||
declare -i _optverbose=0
|
declare -i _optverbose=0
|
||||||
# Working variables
|
# Working variables
|
||||||
@ -54,6 +59,7 @@ Usage: $_name [OPTION]... [FILE]...
|
|||||||
Use youtube-dl and a music player to queue up or download a number of songs
|
Use youtube-dl and a music player to queue up or download a number of songs
|
||||||
given plaintext files with only search queries
|
given plaintext files with only search queries
|
||||||
|
|
||||||
|
-c [FILE] Load the given file in place of the usual config file
|
||||||
-h Print this help text
|
-h Print this help text
|
||||||
-v Print more status messages. Stacks
|
-v Print more status messages. Stacks
|
||||||
|
|
||||||
@ -65,8 +71,11 @@ EOF
|
|||||||
# Main
|
# Main
|
||||||
main() {
|
main() {
|
||||||
# Getopts before anything else
|
# Getopts before anything else
|
||||||
while getopts ":hv" opt; do
|
while getopts ":c:hv" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
|
c)
|
||||||
|
_optconfigfile="$OPTARG"
|
||||||
|
;;
|
||||||
h)
|
h)
|
||||||
_opthelp=1
|
_opthelp=1
|
||||||
;;
|
;;
|
||||||
@ -81,7 +90,26 @@ main() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
# Parse out a config file if it exists
|
||||||
|
if [ -f "$_optconfigfile" ]; then
|
||||||
|
log "Loading config file" 1
|
||||||
|
while read line; do
|
||||||
|
# If the line has an equals sign and isn't a comment
|
||||||
|
if [ "$line" != "${line#*=}" ] && [ "$line" = "${line#\#}" ]; then
|
||||||
|
local varname="${line%=*}"
|
||||||
|
local value="${line#*=}"
|
||||||
|
_config[$varname]="$value"
|
||||||
|
log "Setting $varname to $value" 1
|
||||||
|
fi
|
||||||
|
done < "$_optconfigfile"
|
||||||
|
fi
|
||||||
|
# Validate critical options
|
||||||
|
{
|
||||||
|
for backend in ${_supportedbackends[@]}; do
|
||||||
|
[ "$backend" = "${_config[backend]}" ] && return 0
|
||||||
|
done
|
||||||
|
error "Unsupported backend: ${_config[backend]}" 50
|
||||||
|
}
|
||||||
# Pre-really-do-stuff hooks like help text
|
# Pre-really-do-stuff hooks like help text
|
||||||
[ -n "$_opthelp" ] && printhelp && exit 0
|
[ -n "$_opthelp" ] && printhelp && exit 0
|
||||||
|
|
||||||
|
9
ptgdp.conf
Normal file
9
ptgdp.conf
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# ptgdp.conf
|
||||||
|
# Config file for Play the Goddamned Playlist
|
||||||
|
#
|
||||||
|
|
||||||
|
# The media player backend to use
|
||||||
|
# Supported: mpd
|
||||||
|
# Default: mpd
|
||||||
|
backend=mpd
|
Loading…
Reference in New Issue
Block a user