├── README ├── NOTES ├── enqueue.sh └── downloader.sh /README: -------------------------------------------------------------------------------- 1 | Use these scripts to download a bunch of YouTube videos. 2 | 3 | 1. Download and install youtube-dl on your system: 4 | 5 | http://rg3.github.io/youtube-dl/ 6 | 7 | 2. Execute the "enqueue" script: 8 | 9 | ./enqueue.sh 10 | 11 | 3. Paste URLs of YouTube videos at the command line. 12 | 13 | 4. Watch the downloads go! 14 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | * Tested on Ubuntu 12. 2 | 3 | * The downloader will start automatically as soon as you start 4 | enqueueing URLs. 5 | 6 | * If downloads are disrupted for any reason, the queue can be started 7 | again (by running "enqueue.sh") and should recover to where it 8 | left off. 9 | 10 | * To change the options passed to youtube-dl, change the YOUTUBE_DL_OPTIONS 11 | variable in downloader.sh. 12 | -------------------------------------------------------------------------------- /enqueue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # run this program and paste URLs of YouTube, Vimeo, etc. 4 | # and they will get downloaded automatically. 5 | 6 | ROOT_DIR="$(dirname "$0")" 7 | QUEUE_DIR="$(dirname $0)/queue" 8 | mkdir -p "${QUEUE_DIR}" 9 | 10 | echo -n "Automatically start the downloader on input? [Y/n] " 11 | read download 12 | if [ -z "${download}" ] ; then 13 | download="Y" 14 | elif [ "${download}" = "y" ] ; then 15 | download="Y" 16 | elif [ "${download}" = "yes" ] ; then 17 | download="Y" 18 | fi 19 | 20 | echo "Enter URLs of videos (CTRL-C to stop):" 21 | while /bin/true ; do 22 | if [ "${download}" = "Y" ] ; then 23 | # start the downloader 24 | downloaders=$(ps -f | grep downloader.sh | wc -l) 25 | if [[ "${downloaders}" < 2 ]] ; then 26 | # downloader is not running, start it 27 | "${ROOT_DIR}/downloader.sh" & 28 | fi 29 | fi 30 | 31 | read u 32 | queue_file=$(mktemp --tmpdir="${QUEUE_DIR}" "url.$(date +%Y%m%d).XXXXXX") 33 | echo "${u}" > "${queue_file}" 34 | done 35 | -------------------------------------------------------------------------------- /downloader.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -u 5 | #set -x 6 | 7 | # This program will get started automatically by the enqueue.sh script. 8 | starting=TRUE 9 | 10 | YOUTUBE_DL_OPTIONS="--quiet -r 1M --restrict-filename --no-playlist --no-check-certificate --recode-video mp4" 11 | 12 | ROOT_DIR="$(dirname "$0")" 13 | QUEUE_DIR="${ROOT_DIR}/queue" 14 | HOLDING_DIR="${ROOT_DIR}/holding" 15 | mkdir -p "${HOLDING_DIR}" 16 | DOWNLOAD_DIR="${ROOT_DIR}/download" 17 | mkdir -p "${DOWNLOAD_DIR}" 18 | ERROR_DIR="${ROOT_DIR}/error" 19 | 20 | while /bin/true ; do 21 | # First check if there's a leftover URL in "holding" 22 | url_file=$(ls -tr "${HOLDING_DIR}" | head -1) 23 | if [ -z "${url_file}" ] ; then 24 | # Nothing in "holding", choose the oldest file to download first 25 | url_file=$(ls -tr "${QUEUE_DIR}" | head -1) 26 | if [ -z "${url_file}" ] ; then 27 | if [ "${starting}" != "TRUE" ] ; then 28 | echo "=> Queue is empty." 29 | fi 30 | exit 0 31 | fi 32 | mv "${QUEUE_DIR}/${url_file}" "${HOLDING_DIR}" 33 | fi 34 | 35 | if [ "${starting}" = "TRUE" ] ; then 36 | echo "=> Starting the downloader..." 37 | starting=FALSE 38 | fi 39 | 40 | url_to_download="$(cat "${HOLDING_DIR}/${url_file}")" 41 | echo "=> Starting download: ${url_to_download}" 42 | 43 | options="${YOUTUBE_DL_OPTIONS} -o ${DOWNLOAD_DIR}/%(title)s.%(id)s.%(ext)s" 44 | if youtube-dl ${options} "${url_to_download}" ; then 45 | # success! remove the URL from the queue 46 | echo "=> Success." 47 | rm -f "${HOLDING_DIR}/${url_file}" 48 | else 49 | # failure :( move to the error dir 50 | echo "=> Failure." 51 | mkdir -p "${ERROR_DIR}" 52 | mv "${HOLDING_DIR}/${url_file}" "${ERROR_DIR}" 53 | fi 54 | done 55 | --------------------------------------------------------------------------------