]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/egghead.py
Updated version 2017.10.15.1 from 'upstream/2017.10.15.1'
[youtubedl] / youtube_dl / extractor / egghead.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 try_get,
8 unified_timestamp,
9 )
10
11
12 class EggheadCourseIE(InfoExtractor):
13 IE_DESC = 'egghead.io course'
14 IE_NAME = 'egghead:course'
15 _VALID_URL = r'https://egghead\.io/courses/(?P<id>[^/?#&]+)'
16 _TEST = {
17 'url': 'https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript',
18 'playlist_count': 29,
19 'info_dict': {
20 'id': 'professor-frisby-introduces-composable-functional-javascript',
21 'title': 'Professor Frisby Introduces Composable Functional JavaScript',
22 'description': 're:(?s)^This course teaches the ubiquitous.*You\'ll start composing functionality before you know it.$',
23 },
24 }
25
26 def _real_extract(self, url):
27 playlist_id = self._match_id(url)
28
29 course = self._download_json(
30 'https://egghead.io/api/v1/series/%s' % playlist_id, playlist_id)
31
32 entries = [
33 self.url_result(
34 'wistia:%s' % lesson['wistia_id'], ie='Wistia',
35 video_id=lesson['wistia_id'], video_title=lesson.get('title'))
36 for lesson in course['lessons'] if lesson.get('wistia_id')]
37
38 return self.playlist_result(
39 entries, playlist_id, course.get('title'),
40 course.get('description'))
41
42
43 class EggheadLessonIE(InfoExtractor):
44 IE_DESC = 'egghead.io lesson'
45 IE_NAME = 'egghead:lesson'
46 _VALID_URL = r'https://egghead\.io/lessons/(?P<id>[^/?#&]+)'
47 _TEST = {
48 'url': 'https://egghead.io/lessons/javascript-linear-data-flow-with-container-style-types-box',
49 'info_dict': {
50 'id': 'fv5yotjxcg',
51 'ext': 'mp4',
52 'title': 'Create linear data flow with container style types (Box)',
53 'description': 'md5:9aa2cdb6f9878ed4c39ec09e85a8150e',
54 'thumbnail': r're:^https?:.*\.jpg$',
55 'timestamp': 1481296768,
56 'upload_date': '20161209',
57 'duration': 304,
58 'view_count': 0,
59 'tags': ['javascript', 'free'],
60 },
61 'params': {
62 'skip_download': True,
63 },
64 }
65
66 def _real_extract(self, url):
67 lesson_id = self._match_id(url)
68
69 lesson = self._download_json(
70 'https://egghead.io/api/v1/lessons/%s' % lesson_id, lesson_id)
71
72 return {
73 '_type': 'url_transparent',
74 'ie_key': 'Wistia',
75 'url': 'wistia:%s' % lesson['wistia_id'],
76 'id': lesson['wistia_id'],
77 'title': lesson.get('title'),
78 'description': lesson.get('summary'),
79 'thumbnail': lesson.get('thumb_nail'),
80 'timestamp': unified_timestamp(lesson.get('published_at')),
81 'duration': int_or_none(lesson.get('duration')),
82 'view_count': int_or_none(lesson.get('plays_count')),
83 'tags': try_get(lesson, lambda x: x['tag_list'], list),
84 }