diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2014-01-07 09:35:34 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2014-01-07 09:35:34 +0100 |
commit | 3d3538e422a711aab238f4d1ab667d72cc9bbdbf (patch) | |
tree | e268f0ce37ded1226eccf65d17dffb16cd9b01ee /youtube_dl/extractor/khanacademy.py | |
parent | 0cdad20c75d9bb4be2b5ea131baab18a45773ea8 (diff) |
[khanacademy] Add support (Fixes #2066)
Diffstat (limited to 'youtube_dl/extractor/khanacademy.py')
-rw-r--r-- | youtube_dl/extractor/khanacademy.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/youtube_dl/extractor/khanacademy.py b/youtube_dl/extractor/khanacademy.py new file mode 100644 index 000000000..772bb5671 --- /dev/null +++ b/youtube_dl/extractor/khanacademy.py @@ -0,0 +1,71 @@ +from __future__ import unicode_literals + +import re + +from .common import InfoExtractor +from ..utils import ( + unified_strdate, +) + + +class KhanAcademyIE(InfoExtractor): + _VALID_URL = r'^https?://(?:www\.)?khanacademy\.org/(?P<key>[^/]+)/(?:[^/]+/){,2}(?P<id>[^?#/]+)(?:$|[?#])' + IE_NAME = 'KhanAcademy' + + _TEST = { + 'url': 'http://www.khanacademy.org/video/one-time-pad', + 'file': 'one-time-pad.mp4', + 'md5': '7021db7f2d47d4fff89b13177cb1e8f4', + 'info_dict': { + 'title': 'The one-time pad', + 'description': 'The perfect cipher', + 'duration': 176, + 'uploader': 'Brit Cruise', + 'upload_date': '20120411', + } + } + + def _real_extract(self, url): + m = re.match(self._VALID_URL, url) + video_id = m.group('id') + + if m.group('key') == 'video': + data = self._download_json( + 'http://api.khanacademy.org/api/v1/videos/' + video_id, + video_id, 'Downloading video info') + + upload_date = unified_strdate(data['date_added']) + uploader = ', '.join(data['author_names']) + return { + '_type': 'url_transparent', + 'url': data['url'], + 'id': video_id, + 'title': data['title'], + 'thumbnail': data['image_url'], + 'duration': data['duration'], + 'description': data['description'], + 'uploader': uploader, + 'upload_date': upload_date, + } + else: + # topic + data = self._download_json( + 'http://api.khanacademy.org/api/v1/topic/' + video_id, + video_id, 'Downloading topic info') + + entries = [ + { + '_type': 'url', + 'url': c['url'], + 'id': c['id'], + 'title': c['title'], + } + for c in data['children'] if c['kind'] in ('Video', 'Topic')] + + return { + '_type': 'playlist', + 'id': video_id, + 'title': data['title'], + 'description': data['description'], + 'entries': entries, + } |