Last active
August 29, 2015 13:56
-
-
Save lakemove/8929850 to your computer and use it in GitHub Desktop.
download coursera lecture 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 | |
# 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