]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/medaltv.py
3 from .common
import InfoExtractor
4 from ..compat
import compat_str
16 class MedalTVIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?medal\.tv/games/[^/?#&]+/clips/(?P<id>[^/?#&]+)'
19 'url': 'https://medal.tv/games/valorant/clips/jTBFnLKdLy15K',
20 'md5': '03e4911fdcf7fce563090705c2e79267',
22 'id': 'jTBFnLKdLy15K',
24 'title': "Mornu's clutch",
27 'timestamp': 1651628243,
28 'upload_date': '20220504',
29 'uploader_id': '19335460',
30 'uploader_url': 'https://medal.tv/users/19335460',
37 'url': 'https://medal.tv/games/cod-cold-war/clips/2mA60jWAGQCBH',
38 'md5': 'fc7a3e4552ae8993c1c4006db46be447',
40 'id': '2mA60jWAGQCBH',
43 'description': 'Medal,https://medal.tv/desktop/',
44 'uploader': 'MowgliSB',
45 'timestamp': 1603165266,
46 'upload_date': '20201020',
47 'uploader_id': '10619174',
48 'thumbnail': 'https://cdn.medal.tv/10619174/thumbnail-34934644-720p.jpg?t=1080p&c=202042&missing',
49 'uploader_url': 'https://medal.tv/users/10619174',
56 'url': 'https://medal.tv/games/cod-cold-war/clips/2um24TWdty0NA',
57 'md5': 'b6dc76b78195fff0b4f8bf4a33ec2148',
59 'id': '2um24TWdty0NA',
61 'title': 'u tk me i tk u bigger',
62 'description': 'Medal,https://medal.tv/desktop/',
64 'timestamp': 1605580939,
65 'upload_date': '20201117',
66 'uploader_id': '5156321',
67 'thumbnail': 'https://cdn.medal.tv/5156321/thumbnail-36787208-360p.jpg?t=1080p&c=202046&missing',
68 'uploader_url': 'https://medal.tv/users/5156321',
75 'url': 'https://medal.tv/games/valorant/clips/37rMeFpryCC-9',
76 'only_matching': True,
78 'url': 'https://medal.tv/games/valorant/clips/2WRj40tpY_EU9',
79 'only_matching': True,
82 def _real_extract(self
, url
):
83 video_id
= self
._match
_id
(url
)
85 webpage
= self
._download
_webpage
(update_url_query(url
, {'mobilebypass': 'true'}
), video_id
)
87 hydration_data
= self
._search
_json
(
88 r
'<script[^>]*>[^<]*\bhydrationData\s*=', webpage
,
89 'next data', video_id
, end_pattern
='</script>', fatal
=False)
91 clip
= traverse_obj(hydration_data
, ('clips', ...), get_all
=False)
94 'Could not find video information.', video_id
=video_id
)
96 title
= clip
['contentTitle']
98 source_width
= int_or_none(clip
.get('sourceWidth'))
99 source_height
= int_or_none(clip
.get('sourceHeight'))
101 aspect_ratio
= source_width
/ source_height
if source_width
and source_height
else 16 / 9
103 def add_item(container
, item_url
, height
, id_key
='format_id', item_id
=None):
104 item_id
= item_id
or '%dp' % height
105 if item_id
not in item_url
:
107 width
= int(round(aspect_ratio
* height
))
117 for k
, v
in clip
.items():
118 if not (v
and isinstance(v
, compat_str
)):
120 mobj
= re
.match(r
'(contentUrl|thumbnail)(?:(\d+)p)?$', k
)
123 prefix
= mobj
.group(1)
124 height
= int_or_none(mobj
.group(2))
125 if prefix
== 'contentUrl':
127 formats
, v
, height
or source_height
,
128 item_id
=None if height
else 'source')
129 elif prefix
== 'thumbnail':
130 add_item(thumbnails
, v
, height
, 'id')
132 error
= clip
.get('error')
133 if not formats
and error
:
135 self
.raise_no_formats(
136 'That clip does not exist.',
137 expected
=True, video_id
=video_id
)
139 self
.raise_no_formats(
140 'An unknown error occurred ({0}).'.format(error
),
143 # Necessary because the id of the author is not known in advance.
144 # Won't raise an issue if no profile can be found as this is optional.
145 author
= traverse_obj(hydration_data
, ('profiles', ...), get_all
=False) or {}
146 author_id
= str_or_none(author
.get('userId'))
147 author_url
= format_field(author_id
, None, 'https://medal.tv/users/%s')
153 'thumbnails': thumbnails
,
154 'description': clip
.get('contentDescription'),
155 'uploader': author
.get('displayName'),
156 'timestamp': float_or_none(clip
.get('created'), 1000),
157 'uploader_id': author_id
,
158 'uploader_url': author_url
,
159 'duration': int_or_none(clip
.get('videoLengthSeconds')),
160 'view_count': int_or_none(clip
.get('views')),
161 'like_count': int_or_none(clip
.get('likes')),
162 'comment_count': int_or_none(clip
.get('comments')),