]>
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/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
)
84 webpage
= self
._download
_webpage
(url
, video_id
)
86 hydration_data
= self
._search
_json
(
87 r
'<script[^>]*>[^<]*\bhydrationData\s*=', webpage
,
88 'next data', video_id
, end_pattern
='</script>', fatal
=False)
90 clip
= traverse_obj(hydration_data
, ('clips', ...), get_all
=False)
93 'Could not find video information.', video_id
=video_id
)
95 title
= clip
['contentTitle']
97 source_width
= int_or_none(clip
.get('sourceWidth'))
98 source_height
= int_or_none(clip
.get('sourceHeight'))
100 aspect_ratio
= source_width
/ source_height
if source_width
and source_height
else 16 / 9
102 def add_item(container
, item_url
, height
, id_key
='format_id', item_id
=None):
103 item_id
= item_id
or '%dp' % height
104 if item_id
not in item_url
:
106 width
= int(round(aspect_ratio
* height
))
116 for k
, v
in clip
.items():
117 if not (v
and isinstance(v
, compat_str
)):
119 mobj
= re
.match(r
'(contentUrl|thumbnail)(?:(\d+)p)?$', k
)
122 prefix
= mobj
.group(1)
123 height
= int_or_none(mobj
.group(2))
124 if prefix
== 'contentUrl':
126 formats
, v
, height
or source_height
,
127 item_id
=None if height
else 'source')
128 elif prefix
== 'thumbnail':
129 add_item(thumbnails
, v
, height
, 'id')
131 error
= clip
.get('error')
132 if not formats
and error
:
134 self
.raise_no_formats(
135 'That clip does not exist.',
136 expected
=True, video_id
=video_id
)
138 self
.raise_no_formats(
139 'An unknown error occurred ({0}).'.format(error
),
142 # Necessary because the id of the author is not known in advance.
143 # Won't raise an issue if no profile can be found as this is optional.
144 author
= traverse_obj(hydration_data
, ('profiles', ...), get_all
=False) or {}
145 author_id
= str_or_none(author
.get('userId'))
146 author_url
= format_field(author_id
, None, 'https://medal.tv/users/%s')
152 'thumbnails': thumbnails
,
153 'description': clip
.get('contentDescription'),
154 'uploader': author
.get('displayName'),
155 'timestamp': float_or_none(clip
.get('created'), 1000),
156 'uploader_id': author_id
,
157 'uploader_url': author_url
,
158 'duration': int_or_none(clip
.get('videoLengthSeconds')),
159 'view_count': int_or_none(clip
.get('views')),
160 'like_count': int_or_none(clip
.get('likes')),
161 'comment_count': int_or_none(clip
.get('comments')),