]>
Commit | Line | Data |
---|---|---|
8084951b PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
8084951b | 4 | from .common import InfoExtractor |
514e8aef | 5 | from ..compat import compat_str |
dc6520aa | 6 | from ..utils import ( |
514e8aef | 7 | determine_ext, |
dc6520aa S |
8 | int_or_none, |
9 | try_get, | |
10 | unified_timestamp, | |
11 | ) | |
8084951b PH |
12 | |
13 | ||
14 | class EggheadCourseIE(InfoExtractor): | |
15 | IE_DESC = 'egghead.io course' | |
16 | IE_NAME = 'egghead:course' | |
485cb375 | 17 | _VALID_URL = r'https://egghead\.io/courses/(?P<id>[^/?#&]+)' |
8084951b PH |
18 | _TEST = { |
19 | 'url': 'https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript', | |
20 | 'playlist_count': 29, | |
21 | 'info_dict': { | |
514e8aef | 22 | 'id': '72', |
8084951b PH |
23 | 'title': 'Professor Frisby Introduces Composable Functional JavaScript', |
24 | 'description': 're:(?s)^This course teaches the ubiquitous.*You\'ll start composing functionality before you know it.$', | |
25 | }, | |
26 | } | |
27 | ||
28 | def _real_extract(self, url): | |
29 | playlist_id = self._match_id(url) | |
8084951b | 30 | |
514e8aef S |
31 | lessons = self._download_json( |
32 | 'https://egghead.io/api/v1/series/%s/lessons' % playlist_id, | |
33 | playlist_id, 'Downloading course lessons JSON') | |
34 | ||
35 | entries = [] | |
36 | for lesson in lessons: | |
37 | lesson_url = lesson.get('http_url') | |
38 | if not lesson_url or not isinstance(lesson_url, compat_str): | |
39 | continue | |
40 | lesson_id = lesson.get('id') | |
41 | if lesson_id: | |
42 | lesson_id = compat_str(lesson_id) | |
43 | entries.append(self.url_result( | |
44 | lesson_url, ie=EggheadLessonIE.ie_key(), video_id=lesson_id)) | |
45 | ||
485cb375 | 46 | course = self._download_json( |
514e8aef S |
47 | 'https://egghead.io/api/v1/series/%s' % playlist_id, |
48 | playlist_id, 'Downloading course JSON', fatal=False) or {} | |
8084951b | 49 | |
514e8aef S |
50 | playlist_id = course.get('id') |
51 | if playlist_id: | |
52 | playlist_id = compat_str(playlist_id) | |
485cb375 S |
53 | |
54 | return self.playlist_result( | |
55 | entries, playlist_id, course.get('title'), | |
56 | course.get('description')) | |
dc6520aa S |
57 | |
58 | ||
59 | class EggheadLessonIE(InfoExtractor): | |
60 | IE_DESC = 'egghead.io lesson' | |
61 | IE_NAME = 'egghead:lesson' | |
514e8aef S |
62 | _VALID_URL = r'https://egghead\.io/(?:api/v1/)?lessons/(?P<id>[^/?#&]+)' |
63 | _TESTS = [{ | |
dc6520aa S |
64 | 'url': 'https://egghead.io/lessons/javascript-linear-data-flow-with-container-style-types-box', |
65 | 'info_dict': { | |
514e8aef S |
66 | 'id': '1196', |
67 | 'display_id': 'javascript-linear-data-flow-with-container-style-types-box', | |
dc6520aa S |
68 | 'ext': 'mp4', |
69 | 'title': 'Create linear data flow with container style types (Box)', | |
70 | 'description': 'md5:9aa2cdb6f9878ed4c39ec09e85a8150e', | |
71 | 'thumbnail': r're:^https?:.*\.jpg$', | |
72 | 'timestamp': 1481296768, | |
73 | 'upload_date': '20161209', | |
74 | 'duration': 304, | |
75 | 'view_count': 0, | |
76 | 'tags': ['javascript', 'free'], | |
77 | }, | |
78 | 'params': { | |
79 | 'skip_download': True, | |
514e8aef | 80 | 'format': 'bestvideo', |
dc6520aa | 81 | }, |
514e8aef S |
82 | }, { |
83 | 'url': 'https://egghead.io/api/v1/lessons/react-add-redux-to-a-react-application', | |
84 | 'only_matching': True, | |
85 | }] | |
dc6520aa S |
86 | |
87 | def _real_extract(self, url): | |
514e8aef | 88 | display_id = self._match_id(url) |
dc6520aa S |
89 | |
90 | lesson = self._download_json( | |
514e8aef S |
91 | 'https://egghead.io/api/v1/lessons/%s' % display_id, display_id) |
92 | ||
93 | lesson_id = compat_str(lesson['id']) | |
94 | title = lesson['title'] | |
95 | ||
96 | formats = [] | |
97 | for _, format_url in lesson['media_urls'].items(): | |
98 | if not format_url or not isinstance(format_url, compat_str): | |
99 | continue | |
100 | ext = determine_ext(format_url) | |
101 | if ext == 'm3u8': | |
102 | formats.extend(self._extract_m3u8_formats( | |
103 | format_url, lesson_id, 'mp4', entry_protocol='m3u8', | |
104 | m3u8_id='hls', fatal=False)) | |
105 | elif ext == 'mpd': | |
106 | formats.extend(self._extract_mpd_formats( | |
107 | format_url, lesson_id, mpd_id='dash', fatal=False)) | |
108 | else: | |
109 | formats.append({ | |
110 | 'url': format_url, | |
111 | }) | |
112 | self._sort_formats(formats) | |
dc6520aa S |
113 | |
114 | return { | |
514e8aef S |
115 | 'id': lesson_id, |
116 | 'display_id': display_id, | |
117 | 'title': title, | |
dc6520aa S |
118 | 'description': lesson.get('summary'), |
119 | 'thumbnail': lesson.get('thumb_nail'), | |
120 | 'timestamp': unified_timestamp(lesson.get('published_at')), | |
121 | 'duration': int_or_none(lesson.get('duration')), | |
122 | 'view_count': int_or_none(lesson.get('plays_count')), | |
123 | 'tags': try_get(lesson, lambda x: x['tag_list'], list), | |
514e8aef S |
124 | 'series': try_get( |
125 | lesson, lambda x: x['series']['title'], compat_str), | |
126 | 'formats': formats, | |
dc6520aa | 127 | } |