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