masters.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. traverse_obj,
  5. unified_strdate,
  6. )
  7. class MastersIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?masters\.com/en_US/watch/(?P<date>\d{4}-\d{2}-\d{2})/(?P<id>\d+)'
  9. _TESTS = [{
  10. 'url': 'https://www.masters.com/en_US/watch/2022-04-07/16493755593805191/sungjae_im_thursday_interview_2022.html',
  11. 'info_dict': {
  12. 'id': '16493755593805191',
  13. 'ext': 'mp4',
  14. 'title': 'Sungjae Im: Thursday Interview 2022',
  15. 'upload_date': '20220407',
  16. 'thumbnail': r're:^https?://.*\.jpg$',
  17. }
  18. }]
  19. def _real_extract(self, url):
  20. video_id, upload_date = self._match_valid_url(url).group('id', 'date')
  21. content_resp = self._download_json(
  22. f'https://www.masters.com/relatedcontent/rest/v2/masters_v1/en/content/masters_v1_{video_id}_en',
  23. video_id)
  24. formats, subtitles = self._extract_m3u8_formats_and_subtitles(traverse_obj(content_resp, ('media', 'm3u8')), video_id, 'mp4')
  25. thumbnails = [{'id': name, 'url': url} for name, url in traverse_obj(content_resp, ('images', 0), default={}).items()]
  26. return {
  27. 'id': video_id,
  28. 'title': content_resp.get('title'),
  29. 'formats': formats,
  30. 'subtitles': subtitles,
  31. 'upload_date': unified_strdate(upload_date),
  32. 'thumbnails': thumbnails,
  33. }