summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-03-31 11:27:36 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-03-31 11:27:36 +0200
commit08fa205560f7267acf3ebe37294bc67666385324 (patch)
tree79f30e287407a73ec1d36bad125f0cad674e99c5
parent4786e1edfa7e18453f99d4a748e0271c0f7970fb (diff)
parent0321577cc3d4b4d4e742158d271dd550681d9502 (diff)
downloadqutebrowser-08fa205560f7267acf3ebe37294bc67666385324.tar.gz
qutebrowser-08fa205560f7267acf3ebe37294bc67666385324.zip
Merge remote-tracking branch 'origin/pr/7074'
-rwxr-xr-xmisc/userscripts/cast31
1 files changed, 25 insertions, 6 deletions
diff --git a/misc/userscripts/cast b/misc/userscripts/cast
index df74fe97e..609a7d0db 100755
--- a/misc/userscripts/cast
+++ b/misc/userscripts/cast
@@ -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)
+
+# 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 [[ "${program_}" == "" ]]; then
- msg error "castnow can't be found..."
+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}