Merge remote-tracking branch 'origin/pr/7074'

This commit is contained in:
Florian Bruhin 2022-03-31 11:27:36 +02:00
commit 08fa205560
1 changed files with 25 additions and 6 deletions

View File

@ -20,6 +20,14 @@
#
# Dependencies
# - castnow, https://github.com/xat/castnow
# - youtube-dl (https://youtube-dl.org/) or a drop-in replacement such as
# yt-dlp (https://github.com/yt-dlp/yt-dlp).
#
# Configuration:
# 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>
@ -133,23 +141,34 @@ echo "jseval -q $(printjs)" >> "$QUTE_FIFO"
tmpdir=$(mktemp -d)
file_to_cast=${tmpdir}/qutecast
program_=$(command -v castnow)
cast_program=$(command -v castnow)
if [[ "${program_}" == "" ]]; then
msg error "castnow can't be found..."
# 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"
exit 1
fi
if [[ "${ytdl_program}" == "" ]]; then
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 "${program_}"
pkill -f -- "${cast_program}"
# start youtube download in stream mode (-o -) into temporary file
youtube-dl -qo - "$1" > "${file_to_cast}" &
"${ytdl_program}" -qo - "$1" > "${file_to_cast}" &
ytdl_pid=$!
msg info "Casting $1" >> "$QUTE_FIFO"
# start castnow in stream mode to cast on ChromeCast
tail -F "${file_to_cast}" | ${program_} -
tail -F "${file_to_cast}" | ${cast_program} -
# cleanup remaining background process and file on disk
kill ${ytdl_pid}