Skip to content

Instantly share code, notes, and snippets.

@vmassuchetto
Last active September 26, 2023 12:21
Show Gist options
  • Save vmassuchetto/10338703 to your computer and use it in GitHub Desktop.
Save vmassuchetto/10338703 to your computer and use it in GitHub Desktop.
Shell script cron job to download YouTube videos from your subscription feed
#!/bin/bash
#
# Script to keep downloading YouTube videos to your computer using youtube-dl:
# http://rg3.github.io/youtube-dl/
#
# Put it to work:
#
# sudo wget "https://gist.github.com/vmassuchetto/10338703/raw" -O /etc/cron.hourly/youtube-dl-cron.sh
# sudo chmod +x /etc/cron.hourly/youtube-dl-cron.sh
# sudo service cron restart
#
YOUTUBE_EMAIL="[email protected]"
YOUTUBE_PASSWD="somepassword"
YOUTUBE_DL="/path/to/youtube-dl"
YOUTUBE_DST="/path/to/download/directory"
YOUTUBE_DATE=`date "+%Y%m%d" -d "4 days ago"`
#
# Uncomment this to download only when you have some specific IP address
# (to not download at work, for example)
#
# IP=`/sbin/ifconfig | grep "192.168.0.170" | wc -l`
# if [[ $IP -eq 0 ]]; then
# echo "not in 192.168.0.170"
# exit
# fi
#
# Chec if there's a running instance of youtube-dl
RUN=`ps aux | grep python.*youtube-dl | grep -v grep | wc -l`
if [[ $RUN -gt 0 ]]; then
echo "some instance of youtube-dl is already running"
exit
fi
cd "$YOUTUBE_DST"
$YOUTUBE_DL \
--ignore-errors \
-u "$YOUTUBE_EMAIL" \
-p "$YOUTUBE_PASSWD" \
-o "%(uploader)s %(upload_date)s %(title)s.%(ext)s" \
--dateafter $YOUTUBE_DATE \
"http://www.youtube.com/feed/subscriptions/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment