You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. try_get,
  9. unified_timestamp,
  10. url_or_none,
  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': '72',
  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. def _real_extract(self, url):
  26. playlist_id = self._match_id(url)
  27. lessons = self._download_json(
  28. 'https://egghead.io/api/v1/series/%s/lessons' % playlist_id,
  29. playlist_id, 'Downloading course lessons JSON')
  30. entries = []
  31. for lesson in lessons:
  32. lesson_url = url_or_none(lesson.get('http_url'))
  33. if not lesson_url:
  34. continue
  35. lesson_id = lesson.get('id')
  36. if lesson_id:
  37. lesson_id = compat_str(lesson_id)
  38. entries.append(self.url_result(
  39. lesson_url, ie=EggheadLessonIE.ie_key(), video_id=lesson_id))
  40. course = self._download_json(
  41. 'https://egghead.io/api/v1/series/%s' % playlist_id,
  42. playlist_id, 'Downloading course JSON', fatal=False) or {}
  43. playlist_id = course.get('id')
  44. if playlist_id:
  45. playlist_id = compat_str(playlist_id)
  46. return self.playlist_result(
  47. entries, playlist_id, course.get('title'),
  48. course.get('description'))
  49. class EggheadLessonIE(InfoExtractor):
  50. IE_DESC = 'egghead.io lesson'
  51. IE_NAME = 'egghead:lesson'
  52. _VALID_URL = r'https://egghead\.io/(?:api/v1/)?lessons/(?P<id>[^/?#&]+)'
  53. _TESTS = [{
  54. 'url': 'https://egghead.io/lessons/javascript-linear-data-flow-with-container-style-types-box',
  55. 'info_dict': {
  56. 'id': '1196',
  57. 'display_id': 'javascript-linear-data-flow-with-container-style-types-box',
  58. 'ext': 'mp4',
  59. 'title': 'Create linear data flow with container style types (Box)',
  60. 'description': 'md5:9aa2cdb6f9878ed4c39ec09e85a8150e',
  61. 'thumbnail': r're:^https?:.*\.jpg$',
  62. 'timestamp': 1481296768,
  63. 'upload_date': '20161209',
  64. 'duration': 304,
  65. 'view_count': 0,
  66. 'tags': ['javascript', 'free'],
  67. },
  68. 'params': {
  69. 'skip_download': True,
  70. 'format': 'bestvideo',
  71. },
  72. }, {
  73. 'url': 'https://egghead.io/api/v1/lessons/react-add-redux-to-a-react-application',
  74. 'only_matching': True,
  75. }]
  76. def _real_extract(self, url):
  77. display_id = self._match_id(url)
  78. lesson = self._download_json(
  79. 'https://egghead.io/api/v1/lessons/%s' % display_id, display_id)
  80. lesson_id = compat_str(lesson['id'])
  81. title = lesson['title']
  82. formats = []
  83. for _, format_url in lesson['media_urls'].items():
  84. format_url = url_or_none(format_url)
  85. if not format_url:
  86. continue
  87. ext = determine_ext(format_url)
  88. if ext == 'm3u8':
  89. formats.extend(self._extract_m3u8_formats(
  90. format_url, lesson_id, 'mp4', entry_protocol='m3u8',
  91. m3u8_id='hls', fatal=False))
  92. elif ext == 'mpd':
  93. formats.extend(self._extract_mpd_formats(
  94. format_url, lesson_id, mpd_id='dash', fatal=False))
  95. else:
  96. formats.append({
  97. 'url': format_url,
  98. })
  99. self._sort_formats(formats)
  100. return {
  101. 'id': lesson_id,
  102. 'display_id': display_id,
  103. 'title': title,
  104. 'description': lesson.get('summary'),
  105. 'thumbnail': lesson.get('thumb_nail'),
  106. 'timestamp': unified_timestamp(lesson.get('published_at')),
  107. 'duration': int_or_none(lesson.get('duration')),
  108. 'view_count': int_or_none(lesson.get('plays_count')),
  109. 'tags': try_get(lesson, lambda x: x['tag_list'], list),
  110. 'series': try_get(
  111. lesson, lambda x: x['series']['title'], compat_str),
  112. 'formats': formats,
  113. }