Up until quite recently, I’ve been using YTD Video Downloader in Windows for downloading YouTube videos, but even the paid version has issues. This weekend I rediscovered the steps I took using youtube-dl (yt-dlp) during last Xmas, and made a shell script to automate everything.

#!/bin/sh
#set -x

if [ -z "${*}" ]; then
  echo "Usage: ${0} URL …" > /dev/stderr
  exit 64
fi

if [ -z "`which youtube-dl`" ]; then
  echo "${0}: missing youtube-dl in PATH" > /dev/stderr

  if [ "`uname -o`" = FreeBSD ]; then
    echo "${0}: maybe you need to run pkg install yt-dlp" > /dev/stderr
    echo "${0}: or build and install www/yt-dlp from ports" > /dev/stderr
    echo "${0}: for use in a metaport, try RUN_DEPENDS+=yt-dlp>0:www/yt-dlp" > /dev/stderr
  fi

  exit 69
fi

youtube-dl --keep-video --no-post-overwrites --progress --recode-video mp4 "${@}"

for audio in mp3 opus; do
  youtube-dl --audio-format ${audio} --extract-audio --keep-video --no-post-overwrites --progress "${@}"
done

# EOF

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>