learningequality/ka-lite — pull request #470 by dylanjbarth (2013-08-13 01:02:37+00:00)
Title: Subtitles immediate fix

Okie dokie, here it goes again!

This PR addresses [#128](https://github.com/learningequality/ka-lite/issues/128). Thanks to Ben for cleaning and improving this second pass.

Behavior changes:
1. Instead of downloading subtitles from Amara.org, we now cache them on the central server and expose them for download at a static URL (ex: kalite.adhocsync.com/static/srt/asdkfjhasdf83.srt
2. Distributed servers now download from the central server rather than Amara.org.
3. (small change) User can now see how many subtitles are available for each language on the Update page.

Code changes:
1. The addition of two central server management commands to gather information from Amara's API about which subtitles exist and to download and store the subtitles.
2. Added subtitles utilities that generate current counts of srt files available and make reasonably efficient requests
3. Changed the subtitledownload command to 1) point to central server and 2) only make requests when the subtitle is available.

Testing:

The management commands can be run with the following + -h for usage help.

python manage.py generate_subtitle_map
python manage.py cache_subtitles

You will need to set up a test central server with the data and files downloaded by the scripts above, and then try to download from that central_server with a distributed server instance.

Known issue: the caching of the subtitles results in a 404 about 50% of the time, despite checking with Amara to make sure it exists before making the request. I've submitted a ticket to Amara and will update this if they get back to me, but as far as I can tell (and I am wrong frequently :hamster:), we are requesting the right data and somehow their mapping is off.