Skip to content

Commit

Permalink
ytd-helper/setup-util-ytd: extract into individual installers, enable…
Browse files Browse the repository at this point in the history
… tool section
  • Loading branch information
balupton committed Nov 3, 2023
1 parent 7daaa9e commit 6cef923
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 117 deletions.
85 changes: 60 additions & 25 deletions commands.beta/ytd-helper
Original file line number Diff line number Diff line change
Expand Up @@ -52,72 +52,73 @@ 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] <url> [-- [... tool options]]
OPTIONS:
...
Everything that [youtube-dl] supports, so refer to [youtube-dl --help], in addition to the flags document here.
<url>
The URL to download the video from.
--tool=<tool>
The tool to actually invoke, defaults to [ytd-dl] or [youtube-dl] based on avaliability.
-- [... tool options]
Forward to the invoked <tool>. 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
}

# =====================================
# 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
Expand Down Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions commands/setup-util-lux
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions commands/setup-util-youtube-dl
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions commands/setup-util-yt-dlp
Original file line number Diff line number Diff line change
@@ -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
92 changes: 0 additions & 92 deletions commands/setup-util-ytd

This file was deleted.

0 comments on commit 6cef923

Please sign in to comment.