kelbyone.py 3.4 KB

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