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