]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/medaltv.py
3 from .common
import InfoExtractor
4 from ..compat
import compat_str
15 class MedalTVIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?medal\.tv/(?P<path>games/[^/?#&]+/clips)/(?P<id>[^/?#&]+)'
18 'url': 'https://medal.tv/games/valorant/clips/jTBFnLKdLy15K',
19 'md5': '6930f8972914b6b9fdc2bb3918098ba0',
21 'id': 'jTBFnLKdLy15K',
23 'title': "Mornu's clutch",
26 'timestamp': 1651628243,
27 'upload_date': '20220504',
28 'uploader_id': '19335460',
29 'uploader_url': 'https://medal.tv/users/19335460',
36 'url': 'https://medal.tv/games/cod%20cold%20war/clips/2mA60jWAGQCBH',
37 'md5': '3d19d426fe0b2d91c26e412684e66a06',
39 'id': '2mA60jWAGQCBH',
42 'description': 'Medal,https://medal.tv/desktop/',
43 'uploader': 'MowgliSB',
44 'timestamp': 1603165266,
45 'upload_date': '20201020',
46 'uploader_id': '10619174',
47 'thumbnail': 'https://cdn.medal.tv/10619174/thumbnail-34934644-720p.jpg?t=1080p&c=202042&missing',
48 'uploader_url': 'https://medal.tv/users/10619174',
55 'url': 'https://medal.tv/games/cod%20cold%20war/clips/2um24TWdty0NA',
56 'md5': 'b6dc76b78195fff0b4f8bf4a33ec2148',
58 'id': '2um24TWdty0NA',
60 'title': 'u tk me i tk u bigger',
61 'description': 'Medal,https://medal.tv/desktop/',
63 'timestamp': 1605580939,
64 'upload_date': '20201117',
65 'uploader_id': '5156321',
66 'thumbnail': 'https://cdn.medal.tv/5156321/thumbnail-36787208-360p.jpg?t=1080p&c=202046&missing',
67 'uploader_url': 'https://medal.tv/users/5156321',
74 'url': 'https://medal.tv/games/valorant/clips/37rMeFpryCC-9',
75 'only_matching': True,
77 'url': 'https://medal.tv/games/valorant/clips/2WRj40tpY_EU9',
78 'only_matching': True,
81 def _real_extract(self
, url
):
82 video_id
= self
._match
_id
(url
)
83 path
= self
._match
_valid
_url
(url
).group('path')
85 webpage
= self
._download
_webpage
(url
, video_id
)
87 next_data
= self
._search
_json
(
88 '<script[^>]*__NEXT_DATA__[^>]*>', webpage
,
89 'next data', video_id
, end_pattern
='</script>', fatal
=False)
91 build_id
= next_data
.get('buildId')
94 'Could not find build ID.', video_id
=video_id
)
96 locale
= next_data
.get('locale', 'en')
98 api_response
= self
._download
_json
(
99 f
'https://medal.tv/_next/data/{build_id}/{locale}/{path}/{video_id}.json', video_id
)
101 clip
= traverse_obj(api_response
, ('pageProps', 'clip')) or {}
103 raise ExtractorError(
104 'Could not find video information.', video_id
=video_id
)
106 title
= clip
['contentTitle']
108 source_width
= int_or_none(clip
.get('sourceWidth'))
109 source_height
= int_or_none(clip
.get('sourceHeight'))
111 aspect_ratio
= source_width
/ source_height
if source_width
and source_height
else 16 / 9
113 def add_item(container
, item_url
, height
, id_key
='format_id', item_id
=None):
114 item_id
= item_id
or '%dp' % height
115 if item_id
not in item_url
:
117 width
= int(round(aspect_ratio
* height
))
127 for k
, v
in clip
.items():
128 if not (v
and isinstance(v
, compat_str
)):
130 mobj
= re
.match(r
'(contentUrl|thumbnail)(?:(\d+)p)?$', k
)
133 prefix
= mobj
.group(1)
134 height
= int_or_none(mobj
.group(2))
135 if prefix
== 'contentUrl':
137 formats
, v
, height
or source_height
,
138 item_id
=None if height
else 'source')
139 elif prefix
== 'thumbnail':
140 add_item(thumbnails
, v
, height
, 'id')
142 error
= clip
.get('error')
143 if not formats
and error
:
145 self
.raise_no_formats(
146 'That clip does not exist.',
147 expected
=True, video_id
=video_id
)
149 self
.raise_no_formats(
150 'An unknown error occurred ({0}).'.format(error
),
153 # Necessary because the id of the author is not known in advance.
154 # Won't raise an issue if no profile can be found as this is optional.
155 author
= traverse_obj(api_response
, ('pageProps', 'profile')) or {}
156 author_id
= str_or_none(author
.get('userId'))
157 author_url
= format_field(author_id
, None, 'https://medal.tv/users/%s')
163 'thumbnails': thumbnails
,
164 'description': clip
.get('contentDescription'),
165 'uploader': author
.get('displayName'),
166 'timestamp': float_or_none(clip
.get('created'), 1000),
167 'uploader_id': author_id
,
168 'uploader_url': author_url
,
169 'duration': int_or_none(clip
.get('videoLengthSeconds')),
170 'view_count': int_or_none(clip
.get('views')),
171 'like_count': int_or_none(clip
.get('likes')),
172 'comment_count': int_or_none(clip
.get('comments')),