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