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