3 from .common
import InfoExtractor
14 class MedalTVIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?medal\.tv/games/[^/?#&]+/clips/(?P<id>[^/?#&]+)'
17 'url': 'https://medal.tv/games/valorant/clips/jTBFnLKdLy15K',
18 'md5': '03e4911fdcf7fce563090705c2e79267',
20 'id': 'jTBFnLKdLy15K',
22 'title': "Mornu's clutch",
25 'timestamp': 1651628243,
26 'upload_date': '20220504',
27 'uploader_id': '19335460',
28 'uploader_url': 'https://medal.tv/users/19335460',
35 'url': 'https://medal.tv/games/cod-cold-war/clips/2mA60jWAGQCBH',
36 'md5': 'fc7a3e4552ae8993c1c4006db46be447',
38 'id': '2mA60jWAGQCBH',
41 'description': 'Medal,https://medal.tv/desktop/',
42 'uploader': 'MowgliSB',
43 'timestamp': 1603165266,
44 'upload_date': '20201020',
45 'uploader_id': '10619174',
46 'thumbnail': 'https://cdn.medal.tv/10619174/thumbnail-34934644-720p.jpg?t=1080p&c=202042&missing',
47 'uploader_url': 'https://medal.tv/users/10619174',
54 'url': 'https://medal.tv/games/cod-cold-war/clips/2um24TWdty0NA',
55 'md5': 'b6dc76b78195fff0b4f8bf4a33ec2148',
57 'id': '2um24TWdty0NA',
59 'title': 'u tk me i tk u bigger',
60 'description': 'Medal,https://medal.tv/desktop/',
62 'timestamp': 1605580939,
63 'upload_date': '20201117',
64 'uploader_id': '5156321',
65 'thumbnail': 'https://cdn.medal.tv/5156321/thumbnail-36787208-360p.jpg?t=1080p&c=202046&missing',
66 'uploader_url': 'https://medal.tv/users/5156321',
73 'url': 'https://medal.tv/games/valorant/clips/37rMeFpryCC-9',
74 'only_matching': True,
76 'url': 'https://medal.tv/games/valorant/clips/2WRj40tpY_EU9',
77 'only_matching': True,
80 def _real_extract(self
, url
):
81 video_id
= self
._match
_id
(url
)
83 webpage
= self
._download
_webpage
(url
, video_id
, query
={'mobilebypass': 'true'})
85 hydration_data
= self
._search
_json
(
86 r
'<script[^>]*>[^<]*\bhydrationData\s*=', webpage
,
87 'next data', video_id
, end_pattern
='</script>', fatal
=False)
89 clip
= traverse_obj(hydration_data
, ('clips', ...), get_all
=False)
92 'Could not find video information.', video_id
=video_id
)
94 title
= clip
['contentTitle']
96 source_width
= int_or_none(clip
.get('sourceWidth'))
97 source_height
= int_or_none(clip
.get('sourceHeight'))
99 aspect_ratio
= source_width
/ source_height
if source_width
and source_height
else 16 / 9
101 def add_item(container
, item_url
, height
, id_key
='format_id', item_id
=None):
102 item_id
= item_id
or '%dp' % height
103 if item_id
not in item_url
:
105 width
= int(round(aspect_ratio
* height
))
115 for k
, v
in clip
.items():
116 if not (v
and isinstance(v
, str)):
118 mobj
= re
.match(r
'(contentUrl|thumbnail)(?:(\d+)p)?$', k
)
121 prefix
= mobj
.group(1)
122 height
= int_or_none(mobj
.group(2))
123 if prefix
== 'contentUrl':
125 formats
, v
, height
or source_height
,
126 item_id
=None if height
else 'source')
127 elif prefix
== 'thumbnail':
128 add_item(thumbnails
, v
, height
, 'id')
130 error
= clip
.get('error')
131 if not formats
and error
:
133 self
.raise_no_formats(
134 'That clip does not exist.',
135 expected
=True, video_id
=video_id
)
137 self
.raise_no_formats(
138 f
'An unknown error occurred ({error}).',
141 # Necessary because the id of the author is not known in advance.
142 # Won't raise an issue if no profile can be found as this is optional.
143 author
= traverse_obj(hydration_data
, ('profiles', ...), get_all
=False) or {}
144 author_id
= str_or_none(author
.get('userId'))
145 author_url
= format_field(author_id
, None, 'https://medal.tv/users/%s')
151 'thumbnails': thumbnails
,
152 'description': clip
.get('contentDescription'),
153 'uploader': author
.get('displayName'),
154 'timestamp': float_or_none(clip
.get('created'), 1000),
155 'uploader_id': author_id
,
156 'uploader_url': author_url
,
157 'duration': int_or_none(clip
.get('videoLengthSeconds')),
158 'view_count': int_or_none(clip
.get('views')),
159 'like_count': int_or_none(clip
.get('likes')),
160 'comment_count': int_or_none(clip
.get('comments')),