Commit graph

861 commits

Author SHA1 Message Date
Rogério Brito
ff134d0915 coursera/api: Skip JSON documents with missing assetId.
Some JSON documents for some courses in Coursera's New Platform don't always
have an `assetId` attribute right below a `definition` attribute.

Since we convert a JSON document to a Python dictionary, we can't
(unfortunately) just go ahead and access something like
`element['definition']['assetId']`.

Important aside: It seems, during my tests with the `graph-analytics` course
that the method `_get_open_course_asset_ids` only gets called with such
"defective" JSON documents, which *may* indicate that the `if` filtering in
the list comprehension is always necessary and the lists returned by
`_get_open_course_asset_ids` are always empty after filtering (again, at
least with this course; haven't tested with others).

We should investigate things better and see what kind of JSON documents get
us there and, if possible, categorize the documents that Coursera spits so
that we have a better idea of what they are sending us and how to behave.

One (wild) idea would be to have a method for each possible type of JSON
document returning the data structures that we need.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-23 02:06:24 -03:00
Rogério Brito
38f190acd5 setup.py: Update version number for new release.
Since we have not broken compatibility, we are still in the 0.5 lineage.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:42:52 -02:00
Rogério Brito
141edebc3d Merge pull request #415 from gbarboza/patch-2
Maintain video order when creating playlists.

Thanks to @gbarboza for the contribution.
2016-02-11 02:39:15 -02:00
Rogério Brito
a3dcd6df2e .travis.yml: Remove requirements-travis.txt instructions.
As per the previous commit, everything should be included already in the
requirements-dev.txt file.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:33:40 -02:00
Rogério Brito
bb58afc020 requirements-{dev,travis}.txt: Move contents to -dev file.
Unless I'm wrong (which I may quite likely be), the tests will fail if the
keyring backend is not properly configured.  Including `keyrings.alt` is
likely to make tests pass even if we don't have a multitude of keyring
backends available.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:30:17 -02:00
Rogério Brito
811c500211 README.md: Fix badge type from coveralls.io.
We use an SVG file instead of a PNG file, which should look better on some
devices (yes, I know, this is a frivolous change).

Unfortunately, the URL registered there is still `coursera-dl/coursera` and
not the new one (`coursera-dl/coursera-dl`), since the site gives me an HTTP
500 error whenever I click on the button to update the repository
information, and this seems to be the recommended update procedure.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:24:21 -02:00
Rogério Brito
824e73df20 README.md: Fix URL to codeclimate.
Unfortunately, with this move, we lost the history of the project.

On the other hand, the site doesn't seem to have any easy to spot place to
update the URL (the one that it has is not editable).

At least we now point the site to the correct repository. The previously
computed "GPA" was only 1.67 and we have a substantial amount of new tests
now.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:20:21 -02:00
Rogério Brito
0c2bc6b65e tox.ini: Add py35 to list of interpreters.
Python 3.5 was released some time ago and new Linux distributions will have
it as the default interpreter, and we should make sure that it is supported.

Furthermore, Python 2 is on the way out of future releases of said Linux
distributions (e.g., Debian, Fedora and so on).

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:03:29 -02:00
Rogério Brito
9ab8ee2fcc tox.ini: Remove pypy from list of interpreters.
I don't have pypy right now installed on my computer.  I plan to add it back
when Python 3 is supported.

Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-02-11 02:02:24 -02:00
Rogério Brito
c8e42b564b tox.ini: Add keyrings.alt dependency. 2016-02-11 02:01:35 -02:00
Rogério Brito
e07dc9cb48 README.md: Update Python versions tested. 2016-02-11 02:01:01 -02:00
Rogério Brito
95441e9911 README.md: Remove special mentions of on-demand courses. 2016-02-11 01:59:35 -02:00
Rogério Brito
36e821002e Merge pull request #439 from balta2ar/extract-more-supplementary-files
Extract more supplementary files.

From the pull request:

----
This pull request adds extraction of supplementary files (e.g. PDFs) from lecture units.

There are many ways on the new Coursera platform to provide supplementary files. Different course makers use different facilities for that. As a result, it gets complicated and intricate during the
parsing/extraction. Thank got we only have to work with json structure, not (almost never) HTML.

This pull request is the second attempt to fix #425.
----

Thanks @balta2ar for the great contribution! Closes #425.
2016-02-11 01:16:03 -02:00
Yuri Bochkarev
e1aa574b5c Add test for extraction of links from assets provided in a lecture 2016-01-31 22:44:12 +03:00
Yuri Bochkarev
d17aaa7d67 Add extraction of supplementary files from lecture videos
It appears that there are many ways to provide PDFs in a lecture:
1. Add <a href> tags into the text of a "supplement" lecture unit
2. Add <asset> tags into the text of a "supplement" lecture unit
3. Add "assets" field to the content.definition of a "lecture" lecture unit

This commit implements extraction of files that were added with the
third option.

This requires:
1. Call api/openCourseAssets.v1 on each such asset to receive another
   list of asset ids (lets call them sub ids)
2. Call api/assets.v1 on each sub asset id to receive name and url
   of an asset.

Weirdly, asset ids there are present in content.definition.assets, contain
"@1" characters at the end. Only after they are cut off, method
api/openCourseAssets.v1 returns proper results.
2016-01-31 22:32:02 +03:00
Yuri Bochkarev
04464f0f08 Refactoring: move get_on_demand_video_url to api.CourseraOnDemand 2016-01-31 21:14:43 +03:00
Yuri Bochkarev
1ccb011646 Update .gitignore 2016-01-31 20:32:30 +03:00
Yuri Bochkarev
aa48d712b6 Update tests 2016-01-31 20:32:19 +03:00
Yuri Bochkarev
36beb23400 Extract links from both <asset> tags and <a href> tags in supplement sections
It appears that normal way to put a supplement file into a page
is to put it inside an <asset> tag. However, in certain courses
files can be found in <a href> tags in a text of an assignment.
2016-01-31 20:00:34 +03:00
Rogério Brito
8176f60b29 setup.py: Update version number for fixed markup on PyPI.
Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-01-30 07:09:43 -02:00
Rogério Brito
146ff276d1 {fabfile,setup}.py: Use vanilla markdown for rst files.
Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-01-30 07:09:04 -02:00
Rogério Brito
0a81422a33 setup.py: Fix URL of the project. 2016-01-30 07:05:06 -02:00
Rogério Brito
6c64121e86 setup.py: Prepare to release version 0.5 on PyPI.
Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-01-30 06:16:38 -02:00
Rogério Brito
4fba0d2c7a setup.py: Mark compatibility with Python 3.5.
Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-01-30 06:14:56 -02:00
Rogério Brito
fbd4cbe630 .travis.yml: Test the program with Python 3.5.
Signed-off-by: Rogério Brito <rbrito@ime.usp.br>
2016-01-30 06:01:33 -02:00
Rogério Brito
b334efda2a Merge pull request #429 from klimenko/all-lang-subtitles
added download: all-lang-subtitles and subscripts to on-demand classes

From the pull request message:

----

> I added feature of downloading additional files for on-demand classes:
>
> * subscripts for video
> * special value "all" for download subtitles and subscripts of all available languages
> (it's changed filename, for example: file.srt->file.en.srt).

----

Thanks @klimenko for the nice contribution!
2016-01-30 05:56:10 -02:00
Rogério Brito
b52186efb7 Merge pull request #437 from balta2ar/download-supplementary-materials
Add extraction of supplementary materials in on-demand courses.

From the pull request message:
----

> Supplementary materials are usually located on the first page of a
> module. These materials include: pdf, zip, ipynb, csv and other files.
> The code uses undocumented but "reverse engineered" (in browser) method:
> https://www.coursera.org/api/onDemandSupplements.v1. The code handles
> cases when there are multiple files of different formats (extensions)
> on the same page and downloads them all. This clearly benefits to the users
> which will now automatically get all the necessary files for practical
> assignments.
>
>One remarkable downside of this change is that new lecture is now added
> to the beginning of the list of lectures. It means that lectures will
> be renumbered, which will cause downloads of old lectures (even if they
> are already downloaded). I suggest removing ongoing on-demand courses
> and downloading them again (Internet connection permitting). Alternatively,
> one can use hardlink utility to find duplicate files and turn them into
> hardlinks to save up disk space.
>
> Another minor flaw is that occasionally supplementary HTML pages are
> downloaded and saved to filenames without extensions, e.g.
>
>>  01_reading-recommending-songs-assignment_graphlab.SFrame.groupby.html#graphlab.SFrame.groupby
>
>Technically, extension here is "groupby" but that looks ugly. I consider
> this to be a very minor issue. Anyway, suggestions are welcome.

----


Thanks to @balta2ar for the outstanding work with the support for on-demand
courses!
2016-01-30 05:43:44 -02:00
Yuri Bochkarev
894d35a5bb Add tests for supplement files extraction in programming assignments 2016-01-29 22:42:10 +03:00
Yuri Bochkarev
cbe72da11a Update tests 2016-01-29 21:58:40 +03:00
Yuri Bochkarev
71b1d643c9 Extract supplementary files from [un]gradedProgramming sections
I also moved a couple of methods into a separate class CourseraOnDemand
to encapsulate all the tricks that are performed to extract links to
different types of resources.
2016-01-29 21:58:12 +03:00
Yuri Bochkarev
e7b0fec4c3 Attempt to fix Travis-CI build issues with newer version of keyring
According to this advice:
https://github.com/jaraco/keyring/issues/203#issuecomment-176296396
2016-01-28 20:46:06 +03:00
Yuri Bochkarev
1f731839e7 Add Yuri Bochkarev to AUTHORS.md 2016-01-28 04:30:18 +03:00
Yuri Bochkarev
4ea30ce8e9 Add tests and fixtures for supplementary materials extraction 2016-01-28 04:29:47 +03:00
Yuri Bochkarev
b56957266c Add extraction of supplementary materials in on-demand courses
Supplementary materials are usually located on the first page of a
module. These materials include: pdf, zip, ipynb, csv and other files.
The code uses undocumented but "reverse engineered" (in browser) method:
https://www.coursera.org/api/onDemandSupplements.v1. The code handles
cases when there are multiple files of different formats (extensions)
on the same page and downloads them all. This clearly benefits to the users
which will now automatically get all the necessary files for practical
assignments.

One remarkable downside of this change is that new lecture is now added
to the beginning of the list of lectures. It means that lectures will
be renumbered, which will cause downloads of old lectures (even if they
are already downloaded). I suggest removing ongoing on-demand courses
and downloading them again (Internet connection permitting). Alternatively,
one can use hardlink utility to find duplicate files and turn them into
hardlinks to save up disk space.

Another minor flaw is that occasionally supplementary HTML pages are
downloaded and saved to filenames without extensions, e.g.

> 01_reading-recommending-songs-assignment_graphlab.SFrame.groupby.html#graphlab.SFrame.groupby

Technically, extension here is "groupby" but that looks ugly. I consider
this to be a very minor issue. Anyway, suggestions are welcome.
2016-01-28 04:26:58 +03:00
Yuri Bochkarev
186b5b921d Fix typos 2016-01-28 04:04:44 +03:00
Dmitry Klimenko
181cae897b all is default for subtitles, new format for subtiltles files for allways 2016-01-27 18:33:50 +03:00
Dmitry Klimenko
f1b58a01d4 added download: all-lang-subtitles and subscripts to on-demand classes 2015-12-22 14:58:11 +00:00
Garrett Barboza
8c355a1e5b Maintain video order when creating playlists. 2015-10-03 16:17:56 -05:00
Rogério Brito
45bdcaca4d Merge pull request #413 from balta2ar/deprecate-on-demand-option
Deprecate on demand option.

This nice pull request from @balta2ar stops the madness of having
the users know which course is of which type (which they really shouldn't
have to know, frankly).

From the original pull request message:

----

Users are very confused about `--on-demand` option. Sometimes it is required, sometimes it is not. This pull request deprecates the option. Instead, the script tries to detect course type automatically by trying all course types consecutively.

There are no tests for the feature but I think they should definitely be added. I'll do that once I figure out how to do it best. Please share your advices. For better testability, I moved consecutive course tries into a separate function.

----

This closes #387, closes #411, closes #412.
2015-09-25 15:30:36 -03:00
Yuri Bochkarev
a5f74c94c2 Cosmetic fixes after review
* Add link to coursera help page describing course types
* Print type of the course we're about to start downloading
  (for possible future debuging and troubleshooting)
2015-09-25 14:16:57 +03:00
Yuri Bochkarev
b62c2cdfb4 Better names for old-styled parsing methods of syllabus and video page
Make code more clear by adding old_style prefix to methods that
work with parsing of the old-style classes.
2015-09-24 10:21:21 +03:00
Yuri Bochkarev
f2fc5a562b Deprecate --on-demand option, try to detect class type automatically
We have received a lot of issues where people are confused about
distinction between old-style and new-style (on-demand) courses.
Sometimes --on-demand option is required, sometimes it's not.

This patch deprecates --on-demand option in favour of automatic
detection. The detection is straight forward: first, try to treat
the course as an old-style, and if the course is not found, try to
treat it as a new-style (on-demand).

Corresponding messages were adjusted (login method). Help message
for --on-demand option now advices to remove that option.
2015-09-24 10:15:24 +03:00
Rogério Brito
3a2253928c Merge pull request #405 from victorwestmann/master
Fix bug running batch file on Windows with paths with spaces.

Thanks @victorwestmann for solution and tests.
2015-09-11 16:19:55 -03:00
Victor Westmann
c360a1295e Fixed the problem of running coursera-dl.bat file using long paths with spaces in it. Now, after several tests it is working fine. 2015-09-11 13:59:12 -03:00
Victor Westmann
c9b69664bf Fixed the bug in Windows of breaking the code when running path with spaces. 2015-09-11 01:05:09 -03:00
Rogério Brito
1d9120b13a Merge pull request #404 from victorwestmann/master
Fix issue with Travis badge showing "build unknown".

Thanks @victorwestmann.
2015-09-10 23:56:47 -03:00
Victor Westmann
20d7140949 Added new Contributor: Victor Westmann. 2015-09-10 23:20:25 -03:00
Victor Westmann
8435147b86 Fixed small issue with URL. It should work in a few days now. 2015-09-10 22:39:22 -03:00
Rogério Brito
14e866ae16 Merge pull request #396 from coursera-dl/setup.py-robustness
Add more robustness to `setup.py`.

Thanks to @victorwestmann for the (private) report.
2015-09-08 00:23:52 -03:00
Rogério Brito
2e96b904a9 Merge pull request #395 from coursera-dl/selectable-resolution
Selectable resolution (fixes #389)

From my original pull request:

> This is a prototype to select the video resolution of courses.  It,
> unfortunately, only works for on-demand courses (since I don't believe
> that regular courses offer videos in resolutions other than 540p yet).
>
> The code here sucks a lot, since the program started "growing organically"
> and we have some functions with more than 10 parameters, which is a real
> madness (and we are essentially, just mimicking passing the command line
> arguments object to the functions, but in a very poor style: "unboxing"
> the parameters).
2015-09-08 00:21:55 -03:00