diff --git a/download_daily_shows.sh b/download_daily_shows.sh index adc315a..927afef 100755 --- a/download_daily_shows.sh +++ b/download_daily_shows.sh @@ -1,12 +1,27 @@ #/bin/bash +# +# sudo pip install --upgrade youtube-dl && sudo pip3 install --upgrade youtube-dl +# +# If you get youtube-dl permissions errors like +# "ImportError: cannot import name 'main'", run +# sudo find /usr/local -type d -exec chmod a+rx {} + && sudo find /usr/local -type f -exec chmod a+r {} + && sudo find /usr/local/bin -type f -exec chmod a+rx {} + +# + + +TMP_DIR=/tmp/dailyshow DOWNLOAD_DIR=/media/nas/video/series #YOUTUBE_DL="/usr/bin/youtube-dl" -YOUTUBE_DL="/usr/local/bin/youtube-dl" +YOUTUBE_DL="python3 /usr/local/bin/youtube-dl" #KEEP_DAYS=40 KEEP_DAYS=100 ARGS=-qwc +if [ ! -d ${DOWNLOAD_DIR} ]; then + echo "Error: directory not found: ${DOWNLOAD_DIR}" + exit +fi + OPTIND=1 # Reset is necessary if getopts was used previously while getopts ":u:d" opt; do case "${opt}" in @@ -44,11 +59,13 @@ function download_show { url="$1" show="$2" + mkdir -p "${TMP_DIR}/${show}" mkdir -p "${DOWNLOAD_DIR}/${show}" # Get a chosen video format for each site if [[ "${url}" =~ cc.com ]]; then - FORMAT=1028 + FORMAT="1028/907/498/500" + FORMAT="best[width<=?640]" elif [[ "${url}" =~ cbs.com ]]; then FORMAT="rtmp-496-0" fi @@ -56,12 +73,13 @@ function download_show { # Try and download twice (resume if partially downloaded) for i in 1 2; do ${YOUTUBE_DL} ${ARGS} -f ${FORMAT} \ - -o "${DOWNLOAD_DIR}/${show}/%(upload_date)s/%(title)s-%(id)s.%(ext)s" \ + -o "${TMP_DIR}/${show}/%(upload_date)s/%(title)s-%(id)s.%(ext)s" \ --download-archive "${DOWNLOAD_DIR}/${show}.archive" \ ${url} # Wait 10 minutes before trying again #sleep 600 + cp -nr "${TMP_DIR}/${show}"/* "${DOWNLOAD_DIR}/${show}"/ done # Move files from ${DOWNLOAD_DIR}/The Daily Show/NA/ to ${DOWNLOAD_DIR}/The Daily Show/$date