]>
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/clips/(?P<id>[^/?#&]+)'
18 'url': 'https://medal.tv/clips/2mA60jWAGQCBH',
19 'md5': '7b07b064331b1cf9e8e5c52a06ae68fa',
21 'id': '2mA60jWAGQCBH',
24 'description': 'Medal,https://medal.tv/desktop/',
25 'uploader': 'MowgliSB',
26 'timestamp': 1603165266,
27 'upload_date': '20201020',
28 'uploader_id': '10619174',
31 'url': 'https://medal.tv/clips/2um24TWdty0NA',
32 'md5': 'b6dc76b78195fff0b4f8bf4a33ec2148',
34 'id': '2um24TWdty0NA',
36 'title': 'u tk me i tk u bigger',
37 'description': 'Medal,https://medal.tv/desktop/',
39 'timestamp': 1605580939,
40 'upload_date': '20201117',
41 'uploader_id': '5156321',
44 'url': 'https://medal.tv/clips/37rMeFpryCC-9',
45 'only_matching': True,
47 'url': 'https://medal.tv/clips/2WRj40tpY_EU9',
48 'only_matching': True,
51 def _real_extract(self
, url
):
52 video_id
= self
._match
_id
(url
)
53 webpage
= self
._download
_webpage
(url
, video_id
)
55 hydration_data
= self
._parse
_json
(self
._search
_regex
(
56 r
'<script[^>]*>\s*(?:var\s*)?hydrationData\s*=\s*({.+?})\s*</script>',
57 webpage
, 'hydration data', default
='{}'), video_id
)
60 hydration_data
, lambda x
: x
['clips'][video_id
], dict) or {}
63 'Could not find video information.', video_id
=video_id
)
65 title
= clip
['contentTitle']
67 source_width
= int_or_none(clip
.get('sourceWidth'))
68 source_height
= int_or_none(clip
.get('sourceHeight'))
70 aspect_ratio
= source_width
/ source_height
if source_width
and source_height
else 16 / 9
72 def add_item(container
, item_url
, height
, id_key
='format_id', item_id
=None):
73 item_id
= item_id
or '%dp' % height
74 if item_id
not in item_url
:
76 width
= int(round(aspect_ratio
* height
))
86 for k
, v
in clip
.items():
87 if not (v
and isinstance(v
, compat_str
)):
89 mobj
= re
.match(r
'(contentUrl|thumbnail)(?:(\d+)p)?$', k
)
92 prefix
= mobj
.group(1)
93 height
= int_or_none(mobj
.group(2))
94 if prefix
== 'contentUrl':
96 formats
, v
, height
or source_height
,
97 item_id
=None if height
else 'source')
98 elif prefix
== 'thumbnail':
99 add_item(thumbnails
, v
, height
, 'id')
101 error
= clip
.get('error')
102 if not formats
and error
:
104 self
.raise_no_formats(
105 'That clip does not exist.',
106 expected
=True, video_id
=video_id
)
108 self
.raise_no_formats(
109 'An unknown error occurred ({0}).'.format(error
),
112 self
._sort
_formats
(formats
)
114 # Necessary because the id of the author is not known in advance.
115 # Won't raise an issue if no profile can be found as this is optional.
117 hydration_data
, lambda x
: list(x
['profiles'].values())[0], dict) or {}
118 author_id
= str_or_none(author
.get('id'))
119 author_url
= format_field(author_id
, template
='https://medal.tv/users/%s')
125 'thumbnails': thumbnails
,
126 'description': clip
.get('contentDescription'),
127 'uploader': author
.get('displayName'),
128 'timestamp': float_or_none(clip
.get('created'), 1000),
129 'uploader_id': author_id
,
130 'uploader_url': author_url
,
131 'duration': int_or_none(clip
.get('videoLengthSeconds')),
132 'view_count': int_or_none(clip
.get('views')),
133 'like_count': int_or_none(clip
.get('likes')),
134 'comment_count': int_or_none(clip
.get('comments')),