Coursera is arguably the leader in massive open online courses (MOOC) with a selection of more than 300 classes from 62 different institutions as of February 2013. Generous contributions by educators and institutions are making excellent education available to many who could not afford it otherwise. There are even non-profits with "feet on the ground" in remote areas of the world who are helping spread the wealth (see the feedback below from Tunapanda).
This script makes it easier to batch download lecture resources (e.g., videos, ppt, etc) for Coursera classes. Given one or more class names and account credentials, it obtains week and class names from the lectures page, and then downloads the related materials into appropriately named files and directories.
Why is this helpful? A utility like wget can work, but has the
following limitations:
DownloadThemAll is another possibility, but this script provides more features such as appropriately named files.
This work was originally inspired in part by youtube-dl by which I've downloaded many other good videos such as those from Khan Academy.
.netrc filecoursera-dl requires Python 2 (2.6 or newer) or Python 3 (3.2 or newer)
and a free Coursera account enrolled in the class of interest. On Windows
ensure that Python executable location is added to the PATH environment variable.
Note: You must already have (manually) agreed to the Honor of Code of the
particular courses that you want to use with coursera-dl.
We strongly recommend that you consider installing Python packages with
pip, as in it is the current preferred method. If you are
using pip, you can directly install all the dependencies from the
requirements file using pip install -r requirements.txt.
Warning: This method is not recommended unless you know what you are
doing. Before filing bug reports, please check that the versions of your
modules are those recommended in the requirements.txt file.
You may choose to install the dependencies yourself, but our users had
issues that not all resources (videos etc.) were downloaded with versions
of the dependencies different than those listed in the requirements.txt
file.
In any case, you may want to install:
sudo apt-get install python-bs4sudo port install py-beautifulsoup4pip beautifulsoup4sudo apt-get install python-argparsepip argparsesudo apt-get install python-requestssudo port install py-requestspip requestssudo apt-get install python-sixsudo port install py27-sixpip sixsudo apt-get install python-html5libsudo port install py-html5libpip html5libpip supersedes it.sudo apt-get install python-setuptoolsAgain, make sure that you have the versions mentioned in the file
requirements.txt (later versions may be OK).
On Mac OSX using MacPorts, the following may be used:
port
> select --set python python27
> install py-beautifulsoup
> install py-argparse
> install py-setuptools
> install py-requests
> install py27-six
If you don't already have one, create a Coursera account and enroll in a class. See https://www.coursera.org/courses for the list of classes.
Run the script to download the materials by providing your Coursera account
credentials (e.g. email address and password or a ~/.netrc file), the class names,
as well as any additional parameters:
General: coursera-dl -u <user> -p <pass> modelthinking-004
Multiple classes: coursera-dl -u <user> -p <pass> saas historyofrock1-001 algo-2012-002
Filter by section name: coursera-dl -u <user> -p <pass> -sf "Chapter_Four" crypto-004
Filter by lecture name: coursera-dl -u <user> -p <pass> -lf "3.1_" ml-2012-002
Download only ppt files: coursera-dl -u <user> -p <pass> -f "ppt" qcomp-2012-001
Use a ~/.netrc file: coursera-dl -n -- matrix-001
Get the preview classes: coursera-dl -n -b ni-001
Specify download path: coursera-dl -n --path=C:\Coursera\Classes\ comnetworks-002
Display help: coursera-dl --help
Maintain a list of classes in a dir:
Initialize: mkdir -p CURRENT/{class1,class2,..classN}
Update: coursera-dl -n --path CURRENT `ls CURRENT`
On *nix platforms, the use of a ~/.netrc file is a good alternative to
specifying both your username and password every time on the command
line. To use it, simply add a line like the one below to a file named
.netrc in your home directory (or the equivalent, if you are using
Windows) with contents like:
machine coursera-dl login <user> password <pass>
Create the file if it doesn't exist yet. From then on, you can switch from
using -u and -p to simply call coursera-dl with the option -n
instead. This is especially convenient, as typing usernames and passwords
directly on the command line can get tiresome (even more if you happened to
choose a "strong" password).
It is important that:
When reporting bugs against coursera-dl, please don't forget to include
enough information so that you can help us help you:
requirements.txt.Make sure the class name you are using corresponds to the resource name
used in the URL for that class:
https://class.coursera.org/<CLASS_NAME>/class/index
Note that many courses (most, perhaps?) may remove the materials after a little while after the course is completed, while other courses may retain the materials up to a next session/offering of the same course (to avoid problems with academic dishonesty, apparently).
In short, it is not guaranteed that you will be able to download after the course is finished and this is, unfortunately, nothing that we can help you with.
Make sure you have installed and/or updated all of your dependencies
according to the requirements.txt file as described above.
One can export a Netscape-style cookies file with a browser extension
(1, 2) and use it with the -c option. This comes in handy
when the authentication via password is not working (the authentication
process changes now and then).
If results show 0 sections, you most likely have provided invalid
credentials (username and/or password in the command line or in your
.netrc file).
For courses that have not started yet, but have had a previous iteration sometimes a preview is available, containing all the classes from the last course. These files can be downloaded by passing the -b parameter.
If you are using Beautiful Soup 4, make sure you have installed html5lib:
$ python
>>> import html5lib
>>> print(html5lib.__version__)
1.0b2
If you get an error like Could not find class: <CLASS_NAME>:
class
and the current version of the course (a number). For example, for a
class named class, you would have to use class-001, class-002
etc.If:
-n to specify that you want to use a
.netrc file and,coursera-dl: error: too few argumentsThen you should specify -- as an argument after -n, that is, -n --
or change the order in which you pass the arguments to the script, so that
the argument after -n begins with an hyphen (-). Otherwise, Python's
argparse module will think that what you are passing is the name of the
netrc file that you want to use. See issue #162.
I enjoy getting feedback. Here are a few of the comments I've received:
Guillaume V. 11/8/2012
Jay L., Tunapanda 3/20/2013
William G. 2/18/2013
Razvan T. 11/26/2012
Viktor V. 24/04/2013
Post bugs and issues on github. Send other comments to John Lehmann: first last at geemail dotcom or @jplehmann
$ claude mcp add coursera-dl \
-- python -m otcore.mcp_server <graph>