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.

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