From 3ba49366d1dda23aca0be6cb437253908a32e656 Mon Sep 17 00:00:00 2001 From: DavidRV00 <46629825+DavidRV00@users.noreply.github.com> Date: Tue, 15 Mar 2022 23:30:36 -0700 Subject: Switch `cast` userscript from youtube-dl to yt-dlp The `cast` userscript hasn't worked for me in a while, because it attempts to launch youtube-dl which has been replaced by yt-dlp for some time. Switching this one command gets `cast` working for me. --- misc/userscripts/cast | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/userscripts/cast b/misc/userscripts/cast index df74fe97e..30aa59639 100755 --- a/misc/userscripts/cast +++ b/misc/userscripts/cast @@ -144,7 +144,7 @@ fi pkill -f "${program_}" # start youtube download in stream mode (-o -) into temporary file -youtube-dl -qo - "$1" > "${file_to_cast}" & +yt-dlp -qo - "$1" > "${file_to_cast}" & ytdl_pid=$! msg info "Casting $1" >> "$QUTE_FIFO" -- cgit v1.2.3-54-g00ecf From e38b31af0bd857d2b504ff692e49fbda04359d50 Mon Sep 17 00:00:00 2001 From: David Vaughan Date: Wed, 16 Mar 2022 15:39:50 -0700 Subject: 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. --- misc/userscripts/cast | 38 +++++++++++++++++++++++++++++++++----- 1 file 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 @@ -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} -- cgit v1.2.3-54-g00ecf From 88aa165d480859aa5e0af12c010e468875be1e86 Mon Sep 17 00:00:00 2001 From: David Vaughan Date: Wed, 16 Mar 2022 16:46:12 -0700 Subject: Disable shellcheck on source line (cast) --- misc/userscripts/cast | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/userscripts/cast b/misc/userscripts/cast index efc3799f7..2530ffbc7 100755 --- a/misc/userscripts/cast +++ b/misc/userscripts/cast @@ -150,6 +150,7 @@ cast_program=$(command -v castnow) 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 -- cgit v1.2.3-54-g00ecf From 065edd67fa86f150272301b6f57ccddf3a06fc6d Mon Sep 17 00:00:00 2001 From: David Vaughan Date: Mon, 21 Mar 2022 21:06:36 -0700 Subject: Change cast configuration to use an env var Also some other small improvements / fixes. --- misc/userscripts/cast | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/misc/userscripts/cast b/misc/userscripts/cast index 2530ffbc7..ccbc78747 100755 --- a/misc/userscripts/cast +++ b/misc/userscripts/cast @@ -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 @@ -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" -- cgit v1.2.3-54-g00ecf From 0321577cc3d4b4d4e742158d271dd550681d9502 Mon Sep 17 00:00:00 2001 From: David Vaughan Date: Mon, 21 Mar 2022 21:13:56 -0700 Subject: Fix a couple tab lengths (cast) --- misc/userscripts/cast | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/userscripts/cast b/misc/userscripts/cast index ccbc78747..609a7d0db 100755 --- a/misc/userscripts/cast +++ b/misc/userscripts/cast @@ -145,8 +145,8 @@ 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 + ytdl_program=$(command -v -- "$p") + [ "$ytdl_program" == "" ] || break done if [[ "${cast_program}" == "" ]]; then @@ -154,7 +154,7 @@ if [[ "${cast_program}" == "" ]]; then 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 "\ + 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 -- cgit v1.2.3-54-g00ecf