]>
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'
26 def _perform_login(self
, username
, password
):
28 res
= self
._download
_json
(
29 'https://www.vidio.com/interactions.json', None, 'Checking if logged in', fatal
=False) or {}
30 return bool(res
.get('current_user'))
35 login_page
= self
._download
_webpage
(
36 self
._LOGIN
_URL
, None, 'Downloading log in page')
38 login_form
= self
._form
_hidden
_inputs
("login-form", login_page
)
40 'user[login]': username
,
41 'user[password]': password
,
43 login_post
, login_post_urlh
= self
._download
_webpage
_handle
(
44 self
._LOGIN
_URL
, None, 'Logging in', data
=urlencode_postdata(login_form
), expected_status
=[302, 401])
46 if login_post_urlh
.status
== 401:
47 if get_element_by_class('onboarding-content-register-popup__title', login_post
):
49 'Unable to log in: The provided email has not registered yet.', expected
=True)
51 reason
= get_element_by_class('onboarding-form__general-error', login_post
) or get_element_by_class('onboarding-modal__title', login_post
)
52 if 'Akun terhubung ke' in reason
:
54 'Unable to log in: Your account is linked to a social media account. '
55 'Use --cookies to provide account credentials instead', expected
=True)
57 subreason
= get_element_by_class('onboarding-modal__description-text', login_post
) or ''
59 'Unable to log in: %s. %s' % (reason
, clean_html(subreason
)), expected
=True)
60 raise ExtractorError('Unable to log in')
62 def _initialize_pre_login(self
):
63 self
._api
_key
= self
._download
_json
(
64 'https://www.vidio.com/auth', None, data
=b
'')['api_key']
66 def _call_api(self
, url
, video_id
, note
=None):
67 return self
._download
_json
(url
, video_id
, note
=note
, headers
={
68 'Content-Type': 'application/vnd.api+json',
69 'X-API-KEY': self
._api
_key
,
73 class VidioIE(VidioBaseIE
):
74 _VALID_URL
= r
'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)'
76 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015',
77 'md5': 'cd2801394afc164e9775db6a140b91fe',
80 'display_id': 'dj_ambred-booyah-live-2015',
82 'title': 'DJ_AMBRED - Booyah (Live 2015)',
83 'description': 'md5:27dc15f819b6a78a626490881adbadf8',
84 'thumbnail': r
're:^https?://.*\.jpg$',
87 'uploader': 'TWELVE Pic',
88 'timestamp': 1444902800,
89 'upload_date': '20151015',
90 'uploader_id': 'twelvepictures',
91 'channel': 'Cover Music Video',
92 'channel_id': '280236',
99 'url': 'https://www.vidio.com/watch/77949-south-korea-test-fires-missile-that-can-strike-all-of-the-north',
100 'only_matching': True,
102 # Premier-exclusive video
103 'url': 'https://www.vidio.com/watch/1550718-stand-by-me-doraemon',
104 'only_matching': True
107 def _real_extract(self
, url
):
108 match
= self
._match
_valid
_url
(url
).groupdict()
109 video_id
, display_id
= match
.get('id'), match
.get('display_id')
110 data
= self
._call
_api
('https://api.vidio.com/videos/' + video_id
, display_id
)
111 video
= data
['videos'][0]
112 title
= video
['title'].strip()
113 is_premium
= video
.get('is_premium')
116 sources
= self
._download
_json
(
117 'https://www.vidio.com/interactions_stream.json?video_id=%s&type=videos' % video_id
,
118 display_id
, note
='Downloading premier API JSON')
119 if not (sources
.get('source') or sources
.get('source_dash')):
120 self
.raise_login_required('This video is only available for registered users with the appropriate subscription')
122 formats
, subs
= [], {}
123 if sources
.get('source'):
124 hls_formats
, hls_subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
125 sources
['source'], display_id
, 'mp4', 'm3u8_native')
126 formats
.extend(hls_formats
)
127 subs
.update(hls_subs
)
128 if sources
.get('source_dash'): # TODO: Find video example with source_dash
129 dash_formats
, dash_subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
130 sources
['source_dash'], display_id
, 'dash')
131 formats
.extend(dash_formats
)
132 subs
.update(dash_subs
)
134 hls_url
= data
['clips'][0]['hls_url']
135 formats
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
136 hls_url
, display_id
, 'mp4', 'm3u8_native')
138 self
._sort
_formats
(formats
)
140 get_first
= lambda x
: try_get(data
, lambda y
: y
[x
+ 's'][0], dict) or {}
141 channel
= get_first('channel')
142 user
= get_first('user')
143 username
= user
.get('username')
144 get_count
= lambda x
: int_or_none(video
.get('total_' + x
))
148 'display_id': display_id
,
150 'description': strip_or_none(video
.get('description')),
151 'thumbnail': video
.get('image_url_medium'),
152 'duration': int_or_none(video
.get('duration')),
153 'like_count': get_count('likes'),
156 'uploader': user
.get('name'),
157 'timestamp': parse_iso8601(video
.get('created_at')),
158 'uploader_id': username
,
159 'uploader_url': format_field(username
, template
='https://www.vidio.com/@%s'),
160 'channel': channel
.get('name'),
161 'channel_id': str_or_none(channel
.get('id')),
162 'view_count': get_count('view_count'),
163 'dislike_count': get_count('dislikes'),
164 'comment_count': get_count('comments'),
165 'tags': video
.get('tag_list'),
169 class VidioPremierIE(VidioBaseIE
):
170 _VALID_URL
= r
'https?://(?:www\.)?vidio\.com/premier/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
172 'url': 'https://www.vidio.com/premier/2885/badai-pasti-berlalu',
173 'playlist_mincount': 14,
175 # Series with both free and premier-exclusive videos
176 'url': 'https://www.vidio.com/premier/2567/sosmed',
177 'only_matching': True,
180 def _playlist_entries(self
, playlist_url
, display_id
):
183 playlist_json
= self
._call
_api
(playlist_url
, display_id
, 'Downloading API JSON page %s' % index
)
184 for video_json
in playlist_json
.get('data', []):
185 link
= video_json
['links']['watchpage']
186 yield self
.url_result(link
, 'Vidio', video_json
['id'])
187 playlist_url
= try_get(playlist_json
, lambda x
: x
['links']['next'])
190 def _real_extract(self
, url
):
191 url
, idata
= unsmuggle_url(url
, {})
192 playlist_id
, display_id
= self
._match
_valid
_url
(url
).groups()
194 playlist_url
= idata
.get('url')
195 if playlist_url
: # Smuggled data contains an API URL. Download only that playlist
196 playlist_id
= idata
['id']
197 return self
.playlist_result(
198 self
._playlist
_entries
(playlist_url
, playlist_id
),
199 playlist_id
=playlist_id
, playlist_title
=idata
.get('title'))
201 playlist_data
= self
._call
_api
('https://api.vidio.com/content_profiles/%s/playlists' % playlist_id
, display_id
)
203 return self
.playlist_from_matches(
204 playlist_data
.get('data', []), playlist_id
=playlist_id
, ie
=self
.ie_key(),
205 getter
=lambda data
: smuggle_url(url
, {
206 'url': data
['relationships']['videos']['links']['related'],
208 'title': try_get(data
, lambda x
: x
['attributes']['name'])
212 class VidioLiveIE(VidioBaseIE
):
213 _VALID_URL
= r
'https?://(?:www\.)?vidio\.com/live/(?P<id>\d+)-(?P<display_id>[^/?#&]+)'
215 'url': 'https://www.vidio.com/live/204-sctv',
220 'uploader_id': 'sctv',
221 'thumbnail': r
're:^https?://.*\.jpg$',
224 # Premier-exclusive livestream
225 'url': 'https://www.vidio.com/live/6362-tvn',
226 'only_matching': True,
228 # DRM premier-exclusive livestream
229 'url': 'https://www.vidio.com/live/6299-bein-1',
230 'only_matching': True,
233 def _real_extract(self
, url
):
234 video_id
, display_id
= self
._match
_valid
_url
(url
).groups()
235 stream_data
= self
._call
_api
(
236 'https://www.vidio.com/api/livestreamings/%s/detail' % video_id
, display_id
)
237 stream_meta
= stream_data
['livestreamings'][0]
238 user
= stream_data
.get('users', [{}])[0]
240 title
= stream_meta
.get('title')
241 username
= user
.get('username')
244 if stream_meta
.get('is_drm'):
245 if not self
.get_param('allow_unplayable_formats'):
246 self
.report_drm(video_id
)
247 if stream_meta
.get('is_premium'):
248 sources
= self
._download
_json
(
249 'https://www.vidio.com/interactions_stream.json?video_id=%s&type=livestreamings' % video_id
,
250 display_id
, note
='Downloading premier API JSON')
251 if not (sources
.get('source') or sources
.get('source_dash')):
252 self
.raise_login_required('This video is only available for registered users with the appropriate subscription')
254 if str_or_none(sources
.get('source')):
255 token_json
= self
._download
_json
(
256 'https://www.vidio.com/live/%s/tokens' % video_id
,
257 display_id
, note
='Downloading HLS token JSON', data
=b
'')
258 formats
.extend(self
._extract
_m
3u8_formats
(
259 sources
['source'] + '?' + token_json
.get('token', ''), display_id
, 'mp4', 'm3u8_native'))
260 if str_or_none(sources
.get('source_dash')):
263 if stream_meta
.get('stream_token_url'):
264 token_json
= self
._download
_json
(
265 'https://www.vidio.com/live/%s/tokens' % video_id
,
266 display_id
, note
='Downloading HLS token JSON', data
=b
'')
267 formats
.extend(self
._extract
_m
3u8_formats
(
268 stream_meta
['stream_token_url'] + '?' + token_json
.get('token', ''),
269 display_id
, 'mp4', 'm3u8_native'))
270 if stream_meta
.get('stream_dash_url'):
272 if stream_meta
.get('stream_url'):
273 formats
.extend(self
._extract
_m
3u8_formats
(
274 stream_meta
['stream_url'], display_id
, 'mp4', 'm3u8_native'))
275 self
._sort
_formats
(formats
)
279 'display_id': display_id
,
282 'description': strip_or_none(stream_meta
.get('description')),
283 'thumbnail': stream_meta
.get('image'),
284 'like_count': int_or_none(stream_meta
.get('like')),
285 'dislike_count': int_or_none(stream_meta
.get('dislike')),
287 'uploader': user
.get('name'),
288 'timestamp': parse_iso8601(stream_meta
.get('start_time')),
289 'uploader_id': username
,
290 'uploader_url': format_field(username
, template
='https://www.vidio.com/@%s'),