Skip to content

Instantly share code, notes, and snippets.

@lakemove
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakemove/8929850 to your computer and use it in GitHub Desktop.
Save lakemove/8929850 to your computer and use it in GitHub Desktop.
download coursera lecture videos
#!/bin/bash
# download video by providing video url and cookie.
# saved file name will be from Content-Disposition
function download() {
local url=$1
local cookies=$2
local filename=$(curl -I -L -s --cookie "$cookies" "$url" | grep Content-Disposition | python -c "import sys, urllib as ul; print ul.unquote(sys.stdin.read());" | awk -F\" '{print $2}')
echo "start to download $filename"
curl -L -o "$filename" --cookie "$cookies" "$url"
}
# extract all video links from page
function listUrls() {
local page=$1
local cookies=$2
urls=$(curl -s --cookie "$cookies" "$page" | grep download.mp4 | awk -F\" '{print $4}')
echo "$urls"
}
# download all videos on a page
function downloadAll() {
local page=$1
local cookies=$2
local urls=$(listUrls "$page" "$cookies")
for url in $urls ; do
download "$url" "$cookies"
done
}
cat << EOF
HELP
firstly you need to run following to import functions to your current shell session :
>. ./coursera.sh
to download a single video , run (replace cookies with your own):
>download "https://class.coursera.org/artificialvision-001/lecture/download.mp4?lecture_id=41" "CAUTH=xxx"
1st param is video url, 2nd is the cookie needed to access this privileged url
to download all videos on lectures page, run :
>downloadAll "https://class.coursera.org/artificialvision-001/lecture" "CAUTH=XXX"
1st param is the page url that contains links to video url
2nd is the cookie needed to access this privileged url
cookies can be viewed and copied from chrome's developer tool
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment