Skip to content

Instantly share code, notes, and snippets.

@efontan
Last active January 15, 2019 04:08
Show Gist options
  • Save efontan/dd55ccb32df29d31c906014e30e0dfdb to your computer and use it in GitHub Desktop.
Save efontan/dd55ccb32df29d31c906014e30e0dfdb to your computer and use it in GitHub Desktop.
Download all lectures and videos from a Coursera class you are enrolled in.
#!/bin/bash -e
#title : download-coursera-course.sh
#description : Download all lectures and videos from a Coursera class you are enrolled in.
#forked from : https://link.medium.com/agVPPIsauT
#author : ef0ntan
#usage : ./download-coursera-course.sh -c <class-name> -d <download_dir> -i
#parameters :
# -c : Coursera class name in the URL. For example, for "concurrent-programming-in-java"
# Name used in the URL for class: https://www.coursera.org/learn/<CLASS_NAME>/home/welcome
# -d : [OPTIONAL] Directory to download clasee files. Default is ~/Coursera/Classes/
# -i : [OPTIONAL] Download and install coursera-dl files.
OFF='\033[0m' # Color off
RED='\033[0;31m' # Red
GREEN='\033[0;32m' # Green
INSTALL_DIR=~/bin/coursera-dl
USER_DIR=$(eval echo "~$USER")
DOWNLOAD_DIR=$USER_DIR/Coursera/Classes/
COURSE_NAME=""
INSTALL=false
usage() {
echo -e "${RED}Usage: ./download-coursera-course.sh -c <class-name> [-d <download_dir>] [-i]${OFF}"
}
while getopts 'd:c:i' opt; do
case "$opt" in
d)
DOWNLOAD_DIR="$OPTARG" ;;
c)
COURSE_NAME="$OPTARG" ;;
i)
INSTALL=true ;;
*)
usage
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
if [ "$INSTALL" = true ] ; then
echo -e "${GREEN}Installing coursera-dl files.${OFF}"
rm -rf $INSTALL_DIR
mkdir -p $INSTALL_DIR
cd $INSTALL_DIR
git clone https://github.com/coursera-dl/coursera-dl .
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
echo -e "${GREEN}"
read -p 'Please enter your Coursera email: ' EMAIL
read -sp 'Please enter your Coursera password: ' PASS
echo -e "${OFF}"
echo
echo -e "${GREEN}Creating coursera-dl.conf file...${OFF}"
echo
cat > coursera-dl.conf <<EOL
--username $EMAIL
--password $PASS
--subtitle-language en
--download-quizzes
--path $DOWNLOAD_DIR
EOL
fi
mkdir -p $DOWNLOAD_DIR
echo -e "${GREEN}Downloading ${COURSE_NAME} files to ${DOWNLOAD_DIR}${OFF}"
$INSTALL_DIR/coursera-dl $COURSE_NAME
echo -e "${GREEN}Download files complete.${OFF}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment