kelbyone.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none
  3. class KelbyOneIE(InfoExtractor):
  4. _VALID_URL = r'https?://members\.kelbyone\.com/course/(?P<id>[^$&?#/]+)'
  5. _TESTS = [{
  6. 'url': 'https://members.kelbyone.com/course/glyn-dewis-mastering-selections/',
  7. 'playlist_mincount': 1,
  8. 'info_dict': {
  9. 'id': 'glyn-dewis-mastering-selections',
  10. 'title': 'Trailer - Mastering Selections in Photoshop',
  11. },
  12. 'playlist': [{
  13. 'info_dict': {
  14. 'id': 'MkiOnLqK',
  15. 'ext': 'mp4',
  16. 'title': 'Trailer - Mastering Selections in Photoshop',
  17. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  18. 'thumbnail': 'https://content.jwplatform.com/v2/media/MkiOnLqK/poster.jpg?width=720',
  19. 'timestamp': 1601568639,
  20. 'duration': 90,
  21. 'upload_date': '20201001',
  22. },
  23. }]
  24. }]
  25. def _entries(self, playlist):
  26. for item in playlist:
  27. video_id = item['mediaid']
  28. thumbnails = [{
  29. 'url': image.get('src'),
  30. 'width': int_or_none(image.get('width')),
  31. } for image in item.get('images') or []]
  32. formats, subtitles = [], {}
  33. for source in item.get('sources') or []:
  34. if not source.get('file'):
  35. continue
  36. if source.get('type') == 'application/vnd.apple.mpegurl':
  37. fmts, subs = self._extract_m3u8_formats_and_subtitles(source['file'], video_id)
  38. formats.extend(fmts)
  39. subtitles = self._merge_subtitles(subs, subtitles)
  40. elif source.get('type') == 'audio/mp4':
  41. formats.append({
  42. 'format_id': source.get('label'),
  43. 'url': source['file'],
  44. 'vcodec': 'none',
  45. })
  46. else:
  47. formats.append({
  48. 'format_id': source.get('label'),
  49. 'height': source.get('height'),
  50. 'width': source.get('width'),
  51. 'url': source['file'],
  52. })
  53. for track in item.get('tracks'):
  54. if track.get('kind') == 'captions' and track.get('file'):
  55. subtitles.setdefault('en', []).append({
  56. 'url': track['file'],
  57. })
  58. yield {
  59. 'id': video_id,
  60. 'title': item['title'],
  61. 'description': item.get('description'),
  62. 'thumbnails': thumbnails,
  63. 'thumbnail': item.get('image'),
  64. 'timestamp': item.get('pubdate'),
  65. 'duration': item.get('duration'),
  66. 'formats': formats,
  67. 'subtitles': subtitles,
  68. }
  69. def _real_extract(self, url):
  70. item_id = self._match_id(url)
  71. webpage = self._download_webpage(url, item_id)
  72. playlist_url = self._html_search_regex(r'playlist"\:"(https.*content\.jwplatform\.com.*json)"', webpage, 'playlist url').replace('\\', '')
  73. course_data = self._download_json(playlist_url, item_id)
  74. return self.playlist_result(self._entries(course_data['playlist']), item_id,
  75. course_data.get('title'), course_data.get('description'))