[egghead:course] Improve (closes #13370)
[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>[^/?#&]+)'
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
24         course = self._download_json(
25             'https://egghead.io/api/v1/series/%s' % playlist_id, playlist_id)
26
27         entries = [
28             self.url_result(
29                 'wistia:%s' % lesson['wistia_id'], ie='Wistia',
30                 video_id=lesson['wistia_id'], video_title=lesson.get('title'))
31             for lesson in course['lessons'] if lesson.get('wistia_id')]
32
33         return self.playlist_result(
34             entries, playlist_id, course.get('title'),
35             course.get('description'))