summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vaughan <david@davidv.xyz>2022-03-16 15:39:50 -0700
committerDavid Vaughan <david@davidv.xyz>2022-03-16 16:39:57 -0700
commite38b31af0bd857d2b504ff692e49fbda04359d50 (patch)
treefffc10c2b3e5b828ff0d4d11039de453ce4d2972
parent3ba49366d1dda23aca0be6cb437253908a32e656 (diff)
downloadqutebrowser-e38b31af0bd857d2b504ff692e49fbda04359d50.tar.gz
qutebrowser-e38b31af0bd857d2b504ff692e49fbda04359d50.zip
Make cast dl program configurable (default yt-dlp)
I am making the yt-dl program used in the `cast` userscript configurable, via a pattern borrowed from some of the other userscripts here (e.g. `password_fill` and `kodi`): we look for an optional "cast_rc" file in the qutebrowser config directory and source it if it exists. (Technically this allows for overriding any variables used in `cast`, but this is in line with how the pattern works in the other scripts already.) If the config file is not found, we default to yt-dlp, and if that doesn't exist then youtube-dl. If after all this no program is available, we emit an error message (note, the error messaging function as currently written in the cast script seems broken and doesn't display the full error message, but fixing this existing bug is outside of the scope of this change. May be good for a followup). I recognize there's some danger of breakage for some users by switching the default to yt-dlp, but I think it's reasonable to assume that almost everybody who has yt-dlp installed would prefer it to be used anyway. Those who don't will experience no difference.
-rwxr-xr-xmisc/userscripts/cast38
1 files changed, 33 insertions, 5 deletions
diff --git a/misc/userscripts/cast b/misc/userscripts/cast
index 30aa59639..efc3799f7 100755
--- a/misc/userscripts/cast
+++ b/misc/userscripts/cast
@@ -20,6 +20,17 @@
#
# 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 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
#
# Author
# Simon Désaulniers <sim.desaulniers@gmail.com>
@@ -133,23 +144,40 @@ echo "jseval -q $(printjs)" >> "$QUTE_FIFO"
tmpdir=$(mktemp -d)
file_to_cast=${tmpdir}/qutecast
-program_=$(command -v castnow)
+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
+ 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")
+ [ "$ytdl_program" == "" ] || break
+done
-if [[ "${program_}" == "" ]]; then
+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..."
+ 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
-yt-dlp -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}