diff --git a/commands.beta/ytd-helper b/commands.beta/ytd-helper index cbdcaf8f9..754b9aebf 100755 --- a/commands.beta/ytd-helper +++ b/commands.beta/ytd-helper @@ -52,45 +52,54 @@ function ytd_helper() ( function help { cat <<-EOF >/dev/stderr ABOUT: - Helper for interacting with [youtube-dl] that provides some custom flags for common tasks. + Helper for interacting with [youtube-dl] and its clones. Wraps with custom flags for common tasks. USAGE: - ytd-helper [...options] + ytd-helper [...options] [-- [... tool options]] OPTIONS: - ... - Everything that [youtube-dl] supports, so refer to [youtube-dl --help], in addition to the flags document here. + + The URL to download the video from. + + --tool= + The tool to actually invoke, defaults to [ytd-dl] or [youtube-dl] based on avaliability. + + -- [... tool options] + Forward to the invoked . Refer to [youtube-dl --help]. --embed - Embed as much as possible into the video combo file. + Embed as much as possible into the video combo file. --archive - Download as much as possible, but do not use embed, as not all formats support embedding. + Download as much as possible, but do not use embed, as not all formats support embedding. --audio - Download only the best audio. + Download only the best audio. --audio+video - Download the audio, and also download the video combo as usual. + Download the audio, and also download the video combo as usual. --best - Download the best video combo. + Download the best video combo. --mp4 - Download the best video combo, preferring MP4 for video and M4A for audio. + Download the best video combo, preferring MP4 for video and M4A for audio. --free - Download the best video combo of royalty free codecs. + Download the best video combo of royalty free codecs. --vp9 - Download the best video combo of VP9 for video, Opus for audio, and WebM for container. + Download the best video combo of VP9 for video, Opus for audio, and WebM for container. --av1 - Download the best video combo of AV1 for video, Opus for audio, and MKV for container. + Download the best video combo of AV1 for video, Opus for audio, and MKV for container. --playlist - Download with each playlist in its own folder, and each video in its own folder. + Download with each playlist in its own folder, and each video in its own folder. EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } @@ -98,26 +107,18 @@ function ytd_helper() ( # Dependencies setup-util-jq --quiet - setup-util-ytd --quiet # ===================================== # Action - # prepare - local cmd=() - if command-exists 'yt-dlp'; then - cmd+=('yt-dlp') - elif command-exists 'youtube-dl'; then - cmd+=('youtube-dl') - fi - # arguments - local item + local item tool url='' while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; + '--tool='*) tool="${item#*--tool=}" ;; '--embed') cmd+=( --embed-subs @@ -195,12 +196,46 @@ function ytd_helper() ( --output '%(playlist_id)s -- %(playlist_title)s/%(playlist_index)s/%(id)s -- %(title)s.%(ext)s' ) ;; + '--') + cmd+=("$@") + shift $# + break + ;; + '--'*) help "An unrecognised flag was provided: $item" ;; *) - cmd+=("$item") + if test -z "$url"; then + url="$item" + else + help "An unrecognised argument was provided: $item" + fi ;; esac done + # handle tool + if test -z "$tool"; then + if command-exists 'yt-dlp'; then + tool='yt-dlp' + elif command-exists 'youtube-dl'; then + tool='youtube-dl' + else + get-installer --first-success --invoke --quiet -- ytd-dlp youtube-dl + if command-exists 'yt-dlp'; then + tool='yt-dlp' + elif command-exists 'youtube-dl'; then + tool='youtube-dl' + fi + fi + fi + if test -z "$tool" || command-missing "$tool"; then + echo-error "tool [$tool] is not available" + return 3 # ESRCH 3 No such process + fi + cmd=("$tool" "${cmd[@]}") + + # handle url + cmd+=("$url") + # ===================================== # Action diff --git a/commands/setup-util-lux b/commands/setup-util-lux new file mode 100755 index 000000000..14dabe0af --- /dev/null +++ b/commands/setup-util-lux @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +function setup_util_lux() ( + source "$DOROTHY/sources/bash.bash" + + # improve performance + if is-needle --quiet "$@" && ! is-needle --upgrade "$@" && ! is-needle --uninstall "$@" && command-exists lux; then + return 0 + fi + + # setup + local options=( + --cli='lux' + "$@" + GO='github.com/iawia002/lux' + ) + setup-util "${options[@]}" +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + setup_util_lux "$@" +fi diff --git a/commands/setup-util-youtube-dl b/commands/setup-util-youtube-dl new file mode 100755 index 000000000..8b56ce81c --- /dev/null +++ b/commands/setup-util-youtube-dl @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# https://github.com/ytdl-org/youtube-dl + +function setup_util_youtube_dl() ( + source "$DOROTHY/sources/bash.bash" + + # don't improve performance, as we want to ensure correct cli + + # only support pip, as others are buggy, so uninstall the rest + local options=( + --uninstall + --quiet + --name='youtube-dl' + BREW='youtube-dl' + ) + setup-util "${options[@]}" + + # only use pip + options=( + --optional + --cli='youtube-dl' + --name='youtube-dl' + "$@" + PIP='youtube-dl' + ) + setup-util "${options[@]}" + +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + setup_util_youtube_dl "$@" +fi diff --git a/commands/setup-util-yt-dlp b/commands/setup-util-yt-dlp new file mode 100755 index 000000000..39e694ee4 --- /dev/null +++ b/commands/setup-util-yt-dlp @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# https://github.com/yt-dlp/yt-dlp +# https://github.com/yt-dlp/yt-dlp/wiki/Installation + +function setup_util_ytd_dlp() ( + source "$DOROTHY/sources/bash.bash" + + # don't improve performance, as we want to ensure correct cli + + # only support pip, as others are buggy, so uninstall the rest + local options=( + --uninstall + --quiet + --name='yt-dlp' + BREW='yt-dlp' + AUR='yt-dlp' # ARCH + APT_REPO='ppa:yt-dlp/stable' + APT='yt-dlp' # UBUNTU + PORT='yt-dlp' + SCOOP='yt-dlp' + CHOCO='yt-dlp' + WINGET='yt-dlp' + PKG='yt-dlp' + ) + setup-util "${options[@]}" + + # only use pip + options=( + --optional + --cli='yt-dlp' + --name='yt-dlp' + "$@" + PIP='yt-dlp' + ) + setup-util "${options[@]}" +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + setup_util_ytd_dlp "$@" +fi diff --git a/commands/setup-util-ytd b/commands/setup-util-ytd deleted file mode 100755 index 1e9225332..000000000 --- a/commands/setup-util-ytd +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash - -# install the various youtube download utilities -# https://github.com/soimort/you-get - -function setup_util_wget() ( - source "$DOROTHY/sources/bash.bash" - - # --------------------------------- - # https://github.com/yt-dlp/yt-dlp - # https://github.com/yt-dlp/yt-dlp/wiki/Installation - # only support pip, as others are buggy - - # remove alternative methods - local options=( - --uninstall - --quiet - --name='yt-dlp' - BREW='yt-dlp' - AUR='yt-dlp' # ARCH - APT_REPO='ppa:yt-dlp/stable' - APT='yt-dlp' # UBUNTU - PORT='yt-dlp' - SCOOP='yt-dlp' - CHOCO='yt-dlp' - WINGET='yt-dlp' - PKG='yt-dlp' - ) - setup-util "${options[@]}" - - # only use pip - options=( - --optional - --cli='yt-dlp' - --name='yt-dlp' - "$@" - PIP='yt-dlp' - ) - setup-util "${options[@]}" - - # --------------------------------- - # https://github.com/ytdl-org/youtube-dl - # only support pip, as others are buggy - - # remove alternative methods - options=( - --uninstall - --quiet - --name='youtube-dl' - BREW='youtube-dl' - ) - setup-util "${options[@]}" - - # only use pip - options=( - --optional - --cli='youtube-dl' - --name='youtube-dl' - "$@" - PIP='youtube-dl' - ) - setup-util "${options[@]}" - - # --------------------------------- - # https://github.com/kkdai/youtube - - # failing with: package github.com/kkdai/youtube/v2 is not a main package - # local options=( - # --optional - # --cli='youtubedr' - # "$@" - # GO='github.com/kkdai/youtube/v2' - # # GO='github.com/kkdai/youtube/v2/cmd/youtubedr' - # ) - # setup-util "${options[@]}" - - # --------------------------------- - # https://github.com/iawia002/lux - - local options=( - --optional - --cli='lux' - "$@" - GO='github.com/iawia002/lux' - ) - setup-util "${options[@]}" -) - -# fire if invoked standalone -if test "$0" = "${BASH_SOURCE[0]}"; then - setup_util_wget "$@" -fi