Created
September 18, 2017 12:27
-
-
Save radianttap/ed6a5518bc9dc896ad003be9ae43256a to your computer and use it in GitHub Desktop.
Script to download Fall 2017 HD videos
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 | |
#Setup the environnement | |
mkdir fall2017 | |
cd fall2017 | |
mkdir tmp_download | |
cd tmp_download | |
#Extract IDs | |
echo "Downloading the index" | |
wget -q http://developer.apple.com/videos/fall2017/ -O index.html | |
# find parts of the document where data-released=true, all the way to the first H4 header where title of that talk is | |
# then find lines containing "videos/play/fall2017", then remove all chars except session number, then clean duplicated lines | |
cat index.html | sed -n '/data-released=\"true\"/,/\<h4/p' | grep videos/play/fall2017 | sed -e 's/.*fall2017\///' -e 's/\/\"\>//' | sed '$!N; /^\(.*\)\n\1$/!P; D' > ../downloadData | |
rm index.html | |
#Iterate through the talk IDs | |
while read -r line | |
do | |
#Download the page with the real download URL and the talk name | |
wget -q "https://developer.apple.com/videos/play/fall2017/$line/" -O webpage | |
#We grab the title of the page then clean it up | |
talkName=$(cat webpage | grep "<title" | sed -e "s/.*\<title\>//" -e "s/ \- Fall 2017.*//") | |
#We grep "_hd_" which bring up the download URL, then some cleanup | |
#If we were to want SD video, all we would have to do is replace _hd_ by _sd_ | |
dlURL=$(cat webpage | grep _hd | sed -e "s/.*href\=//" -e "s/\>.*//" -e "s/\"//g") | |
pdfURL=$(cat webpage | grep .pdf | grep devstreaming | sed -e "s/.*href\=//" -e "s/\>.*//" -e "s/\"//g" -e "s/ .*$//g") | |
rm webpage | |
#Is there a video URL? | |
if [ -z "$dlURL" ]; then | |
echo "No HD video found at url: $dlURL" | |
else | |
echo "Video $line ($talkName)" | |
echo " url: $dlURL" | |
#Great, we download the file | |
wget -c "$dlURL" -O "../$line - $talkName.mp4" | |
fi | |
done < "../downloadData" | |
#cleanup | |
cd .. | |
rm -rf tmp_download | |
rm downloadData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment