]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/egghead.py
edabaafe689a3d4ffae1b626dc1a55aa068d05aa
   2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
   5 from ..compat 
import compat_str
 
  14 class EggheadCourseIE(InfoExtractor
): 
  15     IE_DESC 
= 'egghead.io course' 
  16     IE_NAME 
= 'egghead:course' 
  17     _VALID_URL 
= r
'https://egghead\.io/courses/(?P<id>[^/?#&]+)' 
  19         'url': 'https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript', 
  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.$', 
  28     def _real_extract(self
, url
): 
  29         playlist_id 
= self
._match
_id
(url
) 
  31         lessons 
= self
._download
_json
( 
  32             'https://egghead.io/api/v1/series/%s/lessons' % playlist_id
, 
  33             playlist_id
, 'Downloading course lessons JSON') 
  36         for lesson 
in lessons
: 
  37             lesson_url 
= lesson
.get('http_url') 
  38             if not lesson_url 
or not isinstance(lesson_url
, compat_str
): 
  40             lesson_id 
= lesson
.get('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
)) 
  46         course 
= self
._download
_json
( 
  47             'https://egghead.io/api/v1/series/%s' % playlist_id
, 
  48             playlist_id
, 'Downloading course JSON', fatal
=False) or {} 
  50         playlist_id 
= course
.get('id') 
  52             playlist_id 
= compat_str(playlist_id
) 
  54         return self
.playlist_result( 
  55             entries
, playlist_id
, course
.get('title'), 
  56             course
.get('description')) 
  59 class EggheadLessonIE(InfoExtractor
): 
  60     IE_DESC 
= 'egghead.io lesson' 
  61     IE_NAME 
= 'egghead:lesson' 
  62     _VALID_URL 
= r
'https://egghead\.io/(?:api/v1/)?lessons/(?P<id>[^/?#&]+)' 
  64         'url': 'https://egghead.io/lessons/javascript-linear-data-flow-with-container-style-types-box', 
  67             'display_id': 'javascript-linear-data-flow-with-container-style-types-box', 
  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', 
  76             'tags': ['javascript', 'free'], 
  79             'skip_download': True, 
  80             'format': 'bestvideo', 
  83         'url': 'https://egghead.io/api/v1/lessons/react-add-redux-to-a-react-application', 
  84         'only_matching': True, 
  87     def _real_extract(self
, url
): 
  88         display_id 
= self
._match
_id
(url
) 
  90         lesson 
= self
._download
_json
( 
  91             'https://egghead.io/api/v1/lessons/%s' % display_id
, display_id
) 
  93         lesson_id 
= compat_str(lesson
['id']) 
  94         title 
= lesson
['title'] 
  97         for _
, format_url 
in lesson
['media_urls'].items(): 
  98             if not format_url 
or not isinstance(format_url
, compat_str
): 
 100             ext 
= determine_ext(format_url
) 
 102                 formats
.extend(self
._extract
_m
3u8_formats
( 
 103                     format_url
, lesson_id
, 'mp4', entry_protocol
='m3u8', 
 104                     m3u8_id
='hls', fatal
=False)) 
 106                 formats
.extend(self
._extract
_mpd
_formats
( 
 107                     format_url
, lesson_id
, mpd_id
='dash', fatal
=False)) 
 112         self
._sort
_formats
(formats
) 
 116             'display_id': display_id
, 
 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), 
 125                 lesson
, lambda x
: x
['series']['title'], compat_str
),