Last active
August 29, 2015 14:02
-
-
Save sarofr/b5fb8463c98a49701f9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
############################################################################ | |
# Automated WWDC 2014 videos downloader script | |
# Cristian Grau @SaroFR | |
# Based on Krzysztof Zablocki's (@merowing_) Download HD WWDC 2014 command | |
############################################################################ | |
function download { | |
curl --silent --remote-name $1 | |
echo $1 | grep SD > /dev/null | |
if [ $? -eq 0 ]; then | |
if [ -f `echo $1 | cut -d "/" -f9` ]; then | |
echo -e "[\033[38;5;40mSUCCESS\033[39m]" | |
else | |
echo -e "[\033[38;5;196mFAILED\033[39m]" | |
fi | |
fi | |
} | |
function downloadHD { | |
echo -n "-> Downloading $1... " | |
download $1 | |
if [ ! -f `echo $1 | cut -d "/" -f9` ]; then | |
echo -e "[\033[38;5;196mFAILED\033[39m]" | |
echo -en "\t-> Downloading SD version... " | |
SDfile=`echo $remotefile | sed 's/HD/SD/' | sed 's/hd/sd/'` | |
download $SDfile | |
else | |
echo -e "[\033[38;5;40mSUCCESS\033[39m]" | |
fi | |
} | |
function downloadPDF { | |
echo -n "-> Downloading $1..." | |
curl --silent --remote-name $1 | |
if [ -f `echo $1 | cut -d "/" -f9` ]; then | |
echo -e "[\033[38;5;40mSUCCESS\033[39m]" | |
else | |
echo -e "[\033[38;5;196mFAILED\033[39m]" | |
fi | |
} | |
echo -n "-> Checking available videos... " | |
files=`curl --silent https://developer.apple.com/videos/wwdc/2014/ | grep -iIoh 'http.*._hd_.*dl=1">HD' | sed -e 's/\?dl=1">HD//g'` | |
echo "Found `echo $files | tr " " "\n" | wc -l |tr -d " "` " | |
for remotefile in `echo $files | sed 's/’//' | tr " " "\n"` | |
do | |
filename=`echo $remotefile | cut -d "/" -f9` | |
echo -n "-> Checking $filename... " | |
remotesize=`curl -sI $remotefile | grep "Content-Length" | cut -d" " -f2 | sed 's/.$//'` | |
if [ -f $filename ] ; then | |
localsize=`ls -la $filename | tr -s " " | cut -d" " -f5` | |
if [ $remotesize != $localsize ]; then | |
echo -e "[\033[38;5;196mSIZE DOESN'T MATCH\033[39m]" | |
downloadHD $remotefile | |
else | |
echo -e "[\033[38;5;40mEXISTS\033[39m]" | |
fi | |
else | |
echo -e "[\033[38;5;196mDOESN'T EXIST\033[39m]" | |
filename=`echo $filename | sed 's/hd/sd/'` | |
echo -en "\t-> Checking SD version... " | |
if [ -f $filename ]; then | |
localsize=`ls -la $filename | tr -s " " | cut -d" " -f5` | |
remotefile=`echo $remotefile | sed 's/HD/SD/' | sed 's/hd/sd/'` | |
remotesize=`curl -sI $remotefile | grep "Content-Length" | cut -d" " -f2 | sed 's/.$//'` | |
if [ $remotesize != $localsize ]; then | |
echo -e "[\033[38;5;196mSIZE DOESN'T MATCH\033[39m]" | |
echo -n "-> Downloading $remotefile... " | |
download $remotefile | |
else | |
echo -e "[\033[38;5;40mEXISTS\033[39m]" | |
fi | |
else | |
echo -e "[\033[38;5;196mDOESN'T EXIST\033[39m]" | |
downloadHD $remotefile | |
fi | |
fi | |
remotePDFfile=`echo $remotefile | sed -E 's/(hd|sd)_//g' | sed 's/mov/pdf/'` | |
if [ ! -f `echo $remotePDFfile | cut -d "/" -f9` ]; then | |
downloadPDF $remotePDFfile | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer to remove all silent option from code. It's easier to see how much time is to end downloading one curse.