-
-
Save danog/a3963463892f7f7df74a to your computer and use it in GitHub Desktop.
Script to download videos from YouTube using Dropbox and IFTTT automation (IFTTT recipe: https://ifttt.com/recipes/277403-download-every-youtube-video-you-add-to-your-watch-later-playlist-automatically)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Original script by Geoffeg, modified by Roblight and later by me (alias me='alias Danog='Daniil Gentili'') | |
### How to install this script: | |
### wget https://gist.github.com/danog/a3963463892f7f7df74a/raw/dropbox_youtube_dl.sh -O ~/dropbox_youtube_dl.sh && chmod 755 ~/dropbox_youtube_dl.sh && ~/dropbox_youtube_dl.sh --install | |
### | |
### IFTTT Recipe URL: https://ifttt.com/recipes/277403-download-every-youtube-video-you-add-to-your-watch-later-playlist-automatically | |
if [ "$1" = "--install" ]; then | |
if [ -f /usr/local/bin/youtube-dl ]; then echo "Youtube-dl already installed."; else echo "Installing youtube-dl..."; sudo curl https://yt-dl.org/downloads/2015.04.03/youtube-dl -o /usr/local/bin/youtube-dl && sudo chmod a+x /usr/local/bin/youtube-dl && echo "YouTube-dl installed successfully." || echo "Couldn't install YouTube-dl."; fi | |
if [ -f ~/.dropbox-dist/dropboxd ]; then echo "Dropbox already installed."; else | |
echo "Installing Dropbox..." | |
platform=`uname -m | tr '[A-Z]' '[a-z]'` | |
case $platform in | |
"x86_64") | |
DROPBOXURL="http://www.dropbox.com/download?plat=lnx.x86_64" | |
;; | |
*) | |
DROPBOXURL="http://www.dropbox.com/download?plat=lnx.x86" | |
;; | |
esac | |
cd ~ && wget -O - $DROPBOXURL | tar xzf - && ~/.dropbox-dist/dropboxd && echo "Dropbox installed successfully." || echo "Couldn't install Dropbox."; fi | |
[ -f /usr/bin/dropbox.py ] || sudo wget -O /usr/bin/dropbox.py https://www.dropbox.com/download?dl=packages/dropbox.py | |
crontab -l | grep -q "dropbox_youtube_dl.sh"; if [ "$?" = "0" ]; then echo "Crontab already edited."; else echo "Editing crontab..."; oldcron=$(crontab -l) && echo "$oldcron | |
* * * * * ~/dropbox_youtube_dl.sh" | crontab - && echo "Crontab edited successfully." || echo "Couldn't edit crontab."; fi | |
while [[ -z $tmpout ]]; do echo -n "Please enter the path of the directory where the video files should be downloaded and remember, put a '\' before spaces in directory names: "; read tmpout; done | |
echo "$tmpout" > ~/.dropytdlrc && echo "All done!" | |
exit $? | |
fi | |
[ "$1" = "--folder" ] && { while [[ -z $tmpout ]]; do echo -n "Please enter the path of the directory where the video files should be downloaded and remember, put a '\' before spaces in directory names: "; read tmpout; done; echo "$tmpout" > ~/.dropytdlrc && echo "All done!"; exit $?; } | |
[ "$1" = "--help" ] && echo "Script to download videos from YouTube using Dropbox and IFTTT automation (specifically this recipe: | |
https://ifttt.com/recipes/277403-download-every-youtube-video-you-add-to-your-watch-later-playlist-automatically) | |
This script will automatically check ~/Dropbox/IFTTT/youtube-dl | |
for new text files containing YouTube video urls and it will download them | |
automatically into the directory you specified during initial configuration or in ~/Videos_YouTube | |
if initial configuration was never run. | |
Options: | |
--install Installs required dependencies, sets up crontab and sets up download folder. | |
--folder Sets up download folder. | |
--help Shows this extremely helpful message. | |
" && exit | |
queue_files_dir=~/Dropbox/IFTTT/youtube-dl | |
queue_files="$queue_files_dir"/*.txt | |
output_dir=$(cat ~/.dropytdlrc 2>/dev/null || { [ -d ~/Videos_YouTube ] && echo -n "~/Videos_YouTube" || { mkdir ~/Videos_YouTube/ && echo -n "~/Videos_YouTube/"; }; }) | |
dropbox.py start >/dev/null | |
shopt -s nullglob | |
for queue_file in $queue_files; do | |
video_url=`cat "$queue_file"` | |
echo "processing $queue_file: $video_url" | |
mv "$queue_file" "$queue_files_dir/processed" | |
youtube-dl -f 18 -o "$output_dir/%(title)s-%(id)s.%(ext)s" "$video_url" | |
# youtube-dl -q -o "$output_dir%(stitle)s.%(ext)s" "$video_url" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does youtube-dl print a log anywhere? I'm having trouble getting this working. Everything seems fine but the videos don't seem to be output anywhere after being processed. Tried a few different folders with no luck.