]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/medaltv.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
17 class MedalTVIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?medal\.tv/clips/(?P<id>[0-9]+)'
20 'url': 'https://medal.tv/clips/34934644/3Is9zyGMoBMr',
21 'md5': '7b07b064331b1cf9e8e5c52a06ae68fa',
26 'description': 'Medal,https://medal.tv/desktop/',
27 'uploader': 'MowgliSB',
28 'timestamp': 1603165266,
29 'upload_date': '20201020',
30 'uploader_id': 10619174,
33 'url': 'https://medal.tv/clips/36787208',
34 'md5': 'b6dc76b78195fff0b4f8bf4a33ec2148',
38 'title': 'u tk me i tk u bigger',
39 'description': 'Medal,https://medal.tv/desktop/',
41 'timestamp': 1605580939,
42 'upload_date': '20201117',
43 'uploader_id': 5156321,
47 def _real_extract(self
, url
):
48 video_id
= self
._match
_id
(url
)
49 webpage
= self
._download
_webpage
(url
, video_id
)
51 hydration_data
= self
._parse
_json
(self
._search
_regex
(
52 r
'<script[^>]*>\s*(?:var\s*)?hydrationData\s*=\s*({.+?})\s*</script>',
53 webpage
, 'hydration data', default
='{}'), video_id
)
56 hydration_data
, lambda x
: x
['clips'][video_id
], dict) or {}
59 'Could not find video information.', video_id
=video_id
)
61 title
= clip
['contentTitle']
63 source_width
= int_or_none(clip
.get('sourceWidth'))
64 source_height
= int_or_none(clip
.get('sourceHeight'))
66 aspect_ratio
= source_width
/ source_height
if source_width
and source_height
else 16 / 9
68 def add_item(container
, item_url
, height
, id_key
='format_id', item_id
=None):
69 item_id
= item_id
or '%dp' % height
70 if item_id
not in item_url
:
72 width
= int(round(aspect_ratio
* height
))
82 for k
, v
in clip
.items():
83 if not (v
and isinstance(v
, compat_str
)):
85 mobj
= re
.match(r
'(contentUrl|thumbnail)(?:(\d+)p)?$', k
)
88 prefix
= mobj
.group(1)
89 height
= int_or_none(mobj
.group(2))
90 if prefix
== 'contentUrl':
92 formats
, v
, height
or source_height
,
93 item_id
=None if height
else 'source')
94 elif prefix
== 'thumbnail':
95 add_item(thumbnails
, v
, height
, 'id')
97 error
= clip
.get('error')
98 if not formats
and error
:
100 raise ExtractorError(
101 'That clip does not exist.',
102 expected
=True, video_id
=video_id
)
104 raise ExtractorError(
105 'An unknown error occurred ({0}).'.format(error
),
108 self
._sort
_formats
(formats
)
110 # Necessary because the id of the author is not known in advance.
111 # Won't raise an issue if no profile can be found as this is optional.
113 hydration_data
, lambda x
: list(x
['profiles'].values())[0], dict) or {}
114 author_id
= str_or_none(author
.get('id'))
115 author_url
= 'https://medal.tv/users/{0}'.format(author_id
) if author_id
else None
121 'thumbnails': thumbnails
,
122 'description': clip
.get('contentDescription'),
123 'uploader': author
.get('displayName'),
124 'timestamp': float_or_none(clip
.get('created'), 1000),
125 'uploader_id': author_id
,
126 'uploader_url': author_url
,
127 'duration': int_or_none(clip
.get('videoLengthSeconds')),
128 'view_count': int_or_none(clip
.get('views')),
129 'like_count': int_or_none(clip
.get('likes')),
130 'comment_count': int_or_none(clip
.get('comments')),