diff options
| author | EuAndreh <eu@euandre.org> | 2022-01-04 15:41:32 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2022-01-04 15:41:32 -0300 |
| commit | 8b9a649ac05469881e17a63112cef69bdc19ed08 (patch) | |
| tree | 8d75b443361d9dbb85ca2a26c54c9d32cc019034 /src/bin/yt | |
| parent | .gitignore: Remove /cron/generated/ (diff) | |
| download | dotfiles-8b9a649ac05469881e17a63112cef69bdc19ed08.tar.gz dotfiles-8b9a649ac05469881e17a63112cef69bdc19ed08.tar.xz | |
scripts/: Move executables to src/bin/, and add a proper CLI interface to them
Diffstat (limited to 'src/bin/yt')
| -rwxr-xr-x | src/bin/yt | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/bin/yt b/src/bin/yt new file mode 100755 index 00000000..0ef5932c --- /dev/null +++ b/src/bin/yt @@ -0,0 +1,90 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + yt [-f] URL... [PLAYLIST_COUNT:-15] + yt [-f] FILE... [PLAYLIST_COUNT:-15] + yt -h +EOF +} + +help() { + cat <<-'EOF' + + Options: + -f force to download a video already + in the archive + -h, --help show this message +EOF +} + +mkstemp() { + echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname." +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'fh:' flag; do + case "$flag" in + f) + FORCE=1 + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ -z "${1:-}" ]; then + echo 'Missing URL|FILE argument' >&2 + usage >&2 + exit 2 +fi + + +if [ ! -e "$1" ]; then + F="$(mkstemp)" + printf '%s\n' "$1" > "$F" +else + F="$1" +fi + + +DEFAULT_PLAYLIST_END=15 +YT_TEMPLATE="$HOME/Downloads/yt-dl/%(uploader)s/%(upload_date)s %(title)s.%(ext)s" + +if [ -z "${FORCE:-}" ]; then + ARCHIVE_OPTION="--download-archive $HOME/archive/youtube-dl-seen.conf" +fi + +youtube-dl \ + --batch-file "$F" \ + --format best \ + --prefer-free-formats \ + --playlist-end "${2:-$DEFAULT_PLAYLIST_END}" \ + --write-description \ + --output "$YT_TEMPLATE" \ + ${ARCHIVE_OPTION:-} |
