]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/vidio.py
2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
22 class VidioBaseIE(InfoExtractor
):
23 _LOGIN_URL
= 'https://www.vidio.com/users/login'
24 _NETRC_MACHINE
= 'vidio'
27 username
, password
= self
._get
_login
_info
()
32 res
= self
._download
_json
(
33 'https://www.vidio.com/interactions.json', None, 'Checking if logged in', fatal
=False) or {}
34 return bool(res
.get('current_user'))
39 login_page
= self
._download
_webpage
(
40 self
._LOGIN
_URL
, None, 'Downloading log in page')
42 login_form
= self
._form
_hidden
_inputs
("login-form", login_page
)
44 'user[login]': username
,
45 'user[password]': password
,
47 login_post
, login_post_urlh
= self
._download
_webpage
_handle
(
48 self
._LOGIN
_URL
, None, 'Logging in', data
=urlencode_postdata(login_form
), expected_status
=[302, 401])
50 if login_post_urlh
.status
== 401:
51 if get_element_by_class('onboarding-content-register-popup__title', login_post
):
53 'Unable to log in: The provided email has not registered yet.', expected
=True)
55 reason
= get_element_by_class('onboarding-form__general-error', login_post
) or get_element_by_class('onboarding-modal__title', login_post
)
56 if 'Akun terhubung ke' in reason
:
58 'Unable to log in: Your account is linked to a social media account. '
59 'Use --cookies to provide account credentials instead', expected
=True)
61 subreason
= get_element_by_class('onboarding-modal__description-text', login_post
) or ''
63 'Unable to log in: %s. %s' % (reason
, clean_html(subreason
)), expected
=True)
64 raise ExtractorError('Unable to log in')
66 def _real_initialize(self
):
67 self
._api
_key
= self
._download
_json
(
68 'https://www.vidio.com/auth', None, data
=b
'')['api_key']
71 def _call_api(self
, url
, video_id
, note
=None):
72 return self
._download
_json
(url
, video_id
, note
=note
, headers
={
73 'Content-Type': 'application/vnd.api+json',
74 'X-API-KEY': self
._api
_key
,
78 class VidioIE(VidioBaseIE
):
79 _VALID_URL
= r
'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)'
81 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015',
82 'md5': 'cd2801394afc164e9775db6a140b91fe',
85 'display_id': 'dj_ambred-booyah-live-2015',
87 'title': 'DJ_AMBRED - Booyah (Live 2015)',
88 'description': 'md5:27dc15f819b6a78a626490881adbadf8',
89 'thumbnail': r
're:^https?://.*\.jpg$',
92 'uploader': 'TWELVE Pic',
93 'timestamp': 1444902800,
94 'upload_date': '20151015',
95 'uploader_id': 'twelvepictures',
96 'channel': 'Cover Music Video',
97 'channel_id': '280236',
100 'comment_count': int,
104 'url': 'https://www.vidio.com/watch/77949-south-korea-test-fires-missile-that-can-strike-all-of-the-north',
105 'only_matching': True,
107 # Premier-exclusive video
108 'url': 'https://www.vidio.com/watch/1550718-stand-by-me-doraemon',
109 'only_matching': True
112 def _real_extract(self
, url
):
113 match
= self
._match
_valid
_url
(url
).groupdict()
114 video_id
, display_id
= match
.get('id'), match
.get('display_id')
115 data
= self
._call
_api
('https://api.vidio.com/videos/' + video_id
, display_id
)
116 video
= data
['videos'][0]
117 title
= video
['title'].strip()
118 is_premium
= video
.get('is_premium')
121 sources
= self
._download
_json
(
122 'https://www.vidio.com/interactions_stream.json?video_id=%s&type=videos' % video_id
,
123 display_id
, note
='Downloading premier API JSON')
124 if not (sources
.get('source') or sources
.get('source_dash')):
125 self
.raise_login_required('This video is only available for registered users with the appropriate subscription')
127 formats
, subs
= [], {}
128 if sources
.get('source'):
129 hls_formats
, hls_subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
130 sources
['source'], display_id
, 'mp4', 'm3u8_native')
131 formats
.extend(hls_formats
)
132 subs
.update(hls_subs
)
133 if sources
.get('source_dash'): # TODO: Find video example with source_dash
134 dash_formats
, dash_subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
135 sources
['source_dash'], display_id
, 'dash')
136 formats
.extend(dash_formats
)
137 subs
.update(dash_subs
)
139 hls_url
= data
['clips'][0]['hls_url']
140 formats
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
141 hls_url
, display_id
, 'mp4', 'm3u8_native')
143 self
._sort
_formats
(formats
)
145 get_first
= lambda x
: try_get(data
, lambda y
: y
[x
+ 's'][0], dict) or {}
146 channel
= get_first('channel')
147 user
= get_first('user')
148 username
= user
.get('username')
149 get_count
= lambda x
: int_or_none(video
.get('total_' + x
))
153 'display_id': display_id
,
155 'description': strip_or_none(video
.get('description')),
156 'thumbnail': video
.get('image_url_medium'),
157 'duration': int_or_none(video
.get('duration')),
158 'like_count': get_count('likes'),
161 'uploader': user
.get('name'),
162 'timestamp': parse_iso8601(video
.get('created_at')),
163 'uploader_id': username
,
164 'uploader_url': format_field(username
, template
='https://www.vidio.com/@%s'),
165 'channel': channel
.get('name'),
166 'channel_id': str_or_none(channel
.get('id')),
167 'view_count': get_count('view_count'),
168 'dislike_count': get_count('dislikes'),
169 'comment_count': get_count('comments'),
170 'tags': video
.get('tag_list'),
174 class VidioPremierIE(VidioBaseIE
):
175 _VALID_URL
= r
'https?://(?:www\.)?vidio\.com/premier/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
177 'url': 'https://www.vidio.com/premier/2885/badai-pasti-berlalu',
178 'playlist_mincount': 14,
180 # Series with both free and premier-exclusive videos
181 'url': 'https://www.vidio.com/premier/2567/sosmed',
182 'only_matching': True,
185 def _playlist_entries(self
, playlist_url
, display_id
):
188 playlist_json
= self
._call
_api
(playlist_url
, display_id
, 'Downloading API JSON page %s' % index
)
189 for video_json
in playlist_json
.get('data', []):
190 link
= video_json
['links']['watchpage']
191 yield self
.url_result(link
, 'Vidio', video_json
['id'])
192 playlist_url
= try_get(playlist_json
, lambda x
: x
['links']['next'])
195 def _real_extract(self
, url
):
196 url
, idata
= unsmuggle_url(url
, {})
197 playlist_id
, display_id
= self
._match
_valid
_url
(url
).groups()
199 playlist_url
= idata
.get('url')
200 if playlist_url
: # Smuggled data contains an API URL. Download only that playlist
201 playlist_id
= idata
['id']
202 return self
.playlist_result(
203 self
._playlist
_entries
(playlist_url
, playlist_id
),
204 playlist_id
=playlist_id
, playlist_title
=idata
.get('title'))
206 playlist_data
= self
._call
_api
('https://api.vidio.com/content_profiles/%s/playlists' % playlist_id
, display_id
)
208 return self
.playlist_from_matches(
209 playlist_data
.get('data', []), playlist_id
=playlist_id
, ie
=self
.ie_key(),
210 getter
=lambda data
: smuggle_url(url
, {
211 'url': data
['relationships']['videos']['links']['related'],
213 'title': try_get(data
, lambda x
: x
['attributes']['name'])
217 class VidioLiveIE(VidioBaseIE
):
218 _VALID_URL
= r
'https?://(?:www\.)?vidio\.com/live/(?P<id>\d+)-(?P<display_id>[^/?#&]+)'
220 'url': 'https://www.vidio.com/live/204-sctv',
225 'uploader_id': 'sctv',
226 'thumbnail': r
're:^https?://.*\.jpg$',
229 # Premier-exclusive livestream
230 'url': 'https://www.vidio.com/live/6362-tvn',
231 'only_matching': True,
233 # DRM premier-exclusive livestream
234 'url': 'https://www.vidio.com/live/6299-bein-1',
235 'only_matching': True,
238 def _real_extract(self
, url
):
239 video_id
, display_id
= self
._match
_valid
_url
(url
).groups()
240 stream_data
= self
._call
_api
(
241 'https://www.vidio.com/api/livestreamings/%s/detail' % video_id
, display_id
)
242 stream_meta
= stream_data
['livestreamings'][0]
243 user
= stream_data
.get('users', [{}])[0]
245 title
= stream_meta
.get('title')
246 username
= user
.get('username')
249 if stream_meta
.get('is_drm'):
250 if not self
.get_param('allow_unplayable_formats'):
251 self
.report_drm(video_id
)
252 if stream_meta
.get('is_premium'):
253 sources
= self
._download
_json
(
254 'https://www.vidio.com/interactions_stream.json?video_id=%s&type=livestreamings' % video_id
,
255 display_id
, note
='Downloading premier API JSON')
256 if not (sources
.get('source') or sources
.get('source_dash')):
257 self
.raise_login_required('This video is only available for registered users with the appropriate subscription')
259 if str_or_none(sources
.get('source')):
260 token_json
= self
._download
_json
(
261 'https://www.vidio.com/live/%s/tokens' % video_id
,
262 display_id
, note
='Downloading HLS token JSON', data
=b
'')
263 formats
.extend(self
._extract
_m
3u8_formats
(
264 sources
['source'] + '?' + token_json
.get('token', ''), display_id
, 'mp4', 'm3u8_native'))
265 if str_or_none(sources
.get('source_dash')):
268 if stream_meta
.get('stream_token_url'):
269 token_json
= self
._download
_json
(
270 'https://www.vidio.com/live/%s/tokens' % video_id
,
271 display_id
, note
='Downloading HLS token JSON', data
=b
'')
272 formats
.extend(self
._extract
_m
3u8_formats
(
273 stream_meta
['stream_token_url'] + '?' + token_json
.get('token', ''),
274 display_id
, 'mp4', 'm3u8_native'))
275 if stream_meta
.get('stream_dash_url'):
277 if stream_meta
.get('stream_url'):
278 formats
.extend(self
._extract
_m
3u8_formats
(
279 stream_meta
['stream_url'], display_id
, 'mp4', 'm3u8_native'))
280 self
._sort
_formats
(formats
)
284 'display_id': display_id
,
287 'description': strip_or_none(stream_meta
.get('description')),
288 'thumbnail': stream_meta
.get('image'),
289 'like_count': int_or_none(stream_meta
.get('like')),
290 'dislike_count': int_or_none(stream_meta
.get('dislike')),
292 'uploader': user
.get('name'),
293 'timestamp': parse_iso8601(stream_meta
.get('start_time')),
294 'uploader_id': username
,
295 'uploader_url': format_field(username
, template
='https://www.vidio.com/@%s'),