Skip to content

Instantly share code, notes, and snippets.

@jonlong
Created December 16, 2023 04:35
Show Gist options
  • Save jonlong/1fdd6519e18cc2e76bf0f324d83d7f99 to your computer and use it in GitHub Desktop.
Save jonlong/1fdd6519e18cc2e76bf0f324d83d7f99 to your computer and use it in GitHub Desktop.
ripcity: a CLI to rip audio/video with yt-dlp
# ripcity
# CLI to rip audio/video with yt-dlp
#
## Usage:
#
# ripcity <VIDEO_ID>
#
# Setup:
# - change <PATH_TO_YOUR_VIDEO_DIR>
# - change <PATH_TO_YOUR_AUDIO_DIR>
# - add to your .zshrc
#
## Examples:
#
## Download a video
# $ ripcity boKihmOqypc
#
## Download part of a video
# $ ripcity boKihmOqypc --start 5:41 --end 7:09
#
## Download audio only
# $ ripcity boKihmOqypc -a
#
## Change the filename
# $ ripcity boKihmOqypc --name "WMTSS"
function ripcity() {
zparseopts -D -E -A opts -dir: -start: -end: -name: a=flag_audio -audio=flag_audio
local video_dir="${opts[--dir]:-<PATH_TO_YOUR_VIDEO_DIR>}"
local audio_dir="${opts[--dir]:-<PATH_TO_YOUR_AUDIO_DIR>}"
local codecs="vcodec:h264,res,acodec:m4a"
local filename="%(title)s.%(ext)s"
local url="https://www.youtube.com/watch?v=${1}"
local start=0
local finish="inf"
local dir=""
if (( $#flag_audio ))
then
dir="$audio_dir"
else
dir="$video_dir"
fi
if [ ! -z "${opts[--name]}" ]
then
filename="${opts[--name]}.%(ext)s"
fi
if [ ! -z "${opts[--start]}" ]
then
start="${opts[--start]}"
if [ ! -z "${opts[--end]}" ]
then
finish="${opts[--end]}"
fi
fi
yt-dlp -P "$dir" $([[ $#flag_audio -gt 0 ]] && echo "-x --audio-format m4a" || echo "-S $codecs") -o "$filename" --download-sections "*${start}-${finish}" "$url"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment