Change cast configuration to use an env var

Also some other small improvements / fixes.
This commit is contained in:
David Vaughan 2022-03-21 21:06:36 -07:00
parent 88aa165d48
commit 065edd67fa
1 changed files with 12 additions and 22 deletions

View File

@ -24,13 +24,10 @@
# yt-dlp (https://github.com/yt-dlp/yt-dlp).
#
# Configuration:
# This script loads the bash script ~/.config/qutebrowser/cast_rc (if
# it exists) or whatever file is specified in QUTE_CAST_CONFIG, so you can
# override the program used for downloading videos.
#
# For example:
#
# ytdl_program=yt-dlp
# This script looks at the optional QUTE_CAST_YTDL_PROGRAM environment
# variable (if it exists) to decide which program to use for downloading
# videos. If specified, this should be youtube-dl or a drop-in replacement
# for it.
#
# Author
# Simon Désaulniers <sim.desaulniers@gmail.com>
@ -146,34 +143,27 @@ tmpdir=$(mktemp -d)
file_to_cast=${tmpdir}/qutecast
cast_program=$(command -v castnow)
# load optional config
QUTE_CONFIG_DIR=${QUTE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/qutebrowser/}
QUTE_CAST_CONFIG=${QUTE_CAST_CONFIG:-${QUTE_CONFIG_DIR}/cast_rc}
if [ -f "$QUTE_CAST_CONFIG" ] ; then
# shellcheck source=/dev/null
source "$QUTE_CAST_CONFIG"
fi
# if ytdl_program wasn't specified in config, use a fallback
for p in "$ytdl_program" yt-dlp youtube-dl; do
ytdl_program=$(command -v "$p")
# pick a ytdl program
for p in "$QUTE_CAST_YTDL_PROGRAM" yt-dlp youtube-dl; do
ytdl_program=$(command -v -- "$p")
[ "$ytdl_program" == "" ] || break
done
if [[ "${cast_program}" == "" ]]; then
msg error "castnow can't be found..."
msg error "castnow can't be found"
exit 1
fi
if [[ "${ytdl_program}" == "" ]]; then
msg error "youtube-dl (or a drop-in replacement) can't be found..."
msg error "youtube-dl or a drop-in replacement can't be found in PATH, and no installed program "\
"specified in QUTE_CAST_YTDL_PROGRAM (currently \\\"$QUTE_CAST_YTDL_PROGRAM\\\")"
exit 1
fi
# kill any running instance of castnow
pkill -f "${cast_program}"
pkill -f -- "${cast_program}"
# start youtube download in stream mode (-o -) into temporary file
${ytdl_program} -qo - "$1" > "${file_to_cast}" &
"${ytdl_program}" -qo - "$1" > "${file_to_cast}" &
ytdl_pid=$!
msg info "Casting $1" >> "$QUTE_FIFO"