masters.py 1.4 KB

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