Last active
August 29, 2015 14:22
-
-
Save sarofr/0245b9e09184d074a91e to your computer and use it in GitHub Desktop.
WWDC2015's videos downloader
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 2015 videos downloader script | |
# Cristian Grau @SaroFR | |
############################################################################ | |
function showPercentage { | |
sleep 5 | |
currentsize=0 | |
while [ $currentsize -lt $remotesize ] | |
do | |
currentsize=`ls -la $filename |tr -s " "|cut -d" " -f5` | |
percent=$[$currentsize*100/$remotesize] | |
echo -ne "-> Downloading $remotesize bytes from $1. $percent%\r" | |
sleep 0.5 | |
currentsize=`ls -la $filename |tr -s " "|cut -d" " -f5` | |
percent=$[$currentsize*100/$remotesize] | |
echo -ne "-> Downloading $remotesize bytes from $1.. $percent%\r" | |
sleep 0.5 | |
currentsize=`ls -la $filename |tr -s " "|cut -d" " -f5` | |
percent=$[$currentsize*100/$remotesize] | |
echo -ne "-> Downloading $remotesize bytes from $1... $percent%\r" | |
sleep 0.5 | |
done | |
echo -e "-> Downloading $remotesize bytes from $1... [\033[38;5;40mSUCCESS\033[39m]" | |
} | |
function resume { | |
curl --silent -C - --remote-name $1 & | |
showPercentage $1 | |
} | |
function download { | |
curl --silent --remote-name $1 & | |
showPercentage $1 | |
} | |
if [ $# -eq 0 ]; then | |
echo "Usage: `basename $0` (SD | HD) [-e <excluded-id>]..." | |
exit 1 | |
fi | |
quality=`echo $1 | tr '[:lower:]' '[:upper:]'` | |
if [ $quality != "SD" ] && [ $quality != "HD" ]; then | |
echo "Usage: `basename $0` (SD | HD) [-e <excluded-id>]..." | |
exit 1 | |
fi | |
excludedIds="" | |
shift | |
while [ $# -gt 1 ] | |
do | |
opt=$1 | |
case $opt in | |
-e|--exclude) | |
excludedIds="$excludedIds | grep -v $2" | |
shift | |
;; | |
*) | |
echo "Invalid parameter $opt" | |
exit 2 | |
;; | |
esac | |
shift | |
done | |
echo -n "-> Checking available videos... " | |
command="curl --silent https://developer.apple.com/videos/wwdc/2015/| tr -d \"\t\" |grep \"?id=\" | grep \"^<a href\" $excludedIds" | |
files=`eval $command` | |
echo "Found `echo $files | sed -e $'s/a> /a>;/g' | tr ";" "\n" | wc -l | tr -d " "` " | |
for fileId in `echo $files | sed -e $'s/a> /a>;/g' | tr ";" "\n" | cut -d"=" -f3 | cut -d"\"" -f1 | sort -n` | |
do | |
url=`echo https://developer.apple.com/videos/wwdc/2015/?id=$fileId` | |
if [ $quality == "SD" ]; then | |
remotefile=`curl --silent \`echo $url\` | grep "SD" | tr -d "\t" | cut -d"\"" -f4 | cut -d"?" -f1` | |
else | |
remotefile=`curl --silent \`echo $url\` | grep "HD" | tr -d "\t" | cut -d"\"" -f8 | cut -d"?" -f1` | |
fi | |
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 -gt $localsize ]; then | |
echo -e "[\033[38;5;196mSIZE DOESN'T MATCH\033[39m]" | |
echo "-> Resuming download..." | |
resume $remotefile | |
elif [ $remotesize -lt $localsize ]; then | |
echo -e "[\033[38;5;196mWRONG SIZE\033[39m]" | |
echo "-> Restarting download..." | |
rm $filename | |
download $remotefile | |
else | |
echo -e "[\033[38;5;40mALREADY DOWNLOADED\033[39m]" | |
fi | |
else | |
echo -e "[\033[38;5;196mDOESN'T EXIST\033[39m]" | |
download $remotefile | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment