[egghead:course] Fix extraction
[youtube-dl] / youtube_dl / extractor / egghead.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class EggheadCourseIE(InfoExtractor):
8     IE_DESC = 'egghead.io course'
9     IE_NAME = 'egghead:course'
10     _VALID_URL = r'https://egghead\.io/courses/(?P<id>[a-zA-Z_0-9-]+)'
11     _TEST = {
12         'url': 'https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript',
13         'playlist_count': 29,
14         'info_dict': {
15             'id': 'professor-frisby-introduces-composable-functional-javascript',
16             'title': 'Professor Frisby Introduces Composable Functional JavaScript',
17             'description': 're:(?s)^This course teaches the ubiquitous.*You\'ll start composing functionality before you know it.$',
18         },
19     }
20
21     def _real_extract(self, url):
22         playlist_id = self._match_id(url)
23         api_url = 'https://egghead.io/api/v1/series/' + playlist_id
24         course = self._download_json(api_url, playlist_id)
25         title = course.get('title')
26         description = course.get('description')
27
28         lessons = course.get('lessons')
29         entries = [{'_type': 'url', 'ie_key': 'Wistia', 'url': 'wistia:' + l.get('wistia_id')} for l in lessons]
30
31         return {
32             '_type': 'playlist',
33             'id': playlist_id,
34             'title': title,
35             'description': description,
36             'entries': entries,
37         }