]>
Commit | Line | Data |
---|---|---|
5270d8cb | 1 | # encoding: utf-8 |
ffe8f62d | 2 | from __future__ import unicode_literals |
5270d8cb | 3 | |
4 | import re | |
5 | import json | |
6 | import hashlib | |
55f6597c | 7 | import uuid |
5270d8cb | 8 | |
9 | from .common import InfoExtractor | |
1cc79574 | 10 | from ..compat import ( |
55f6597c | 11 | compat_urllib_parse, |
12 | compat_urllib_request, | |
1cc79574 PH |
13 | ) |
14 | from ..utils import ( | |
693b8b2d | 15 | ExtractorError, |
cb3ac1c6 | 16 | int_or_none, |
598c218f | 17 | unified_strdate, |
5270d8cb | 18 | ) |
19 | ||
20 | ||
21 | class SmotriIE(InfoExtractor): | |
ffe8f62d | 22 | IE_DESC = 'Smotri.com' |
23 | IE_NAME = 'smotri' | |
598c218f | 24 | _VALID_URL = r'^https?://(?:www\.)?(?:smotri\.com/video/view/\?id=|pics\.smotri\.com/(?:player|scrubber_custom8)\.swf\?file=)(?P<id>v(?P<realvideoid>[0-9]+)[a-z0-9]{4})' |
541cb26c | 25 | _NETRC_MACHINE = 'smotri' |
aaebed13 | 26 | |
5270d8cb | 27 | _TESTS = [ |
28 | # real video id 2610366 | |
29 | { | |
ffe8f62d | 30 | 'url': 'http://smotri.com/video/view/?id=v261036632ab', |
ffe8f62d | 31 | 'md5': '2a7b08249e6f5636557579c368040eb9', |
32 | 'info_dict': { | |
cb3ac1c6 S |
33 | 'id': 'v261036632ab', |
34 | 'ext': 'mp4', | |
ffe8f62d | 35 | 'title': 'катастрофа с камер видеонаблюдения', |
36 | 'uploader': 'rbc2008', | |
37 | 'uploader_id': 'rbc08', | |
38 | 'upload_date': '20131118', | |
ffe8f62d | 39 | 'thumbnail': 'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg', |
5270d8cb | 40 | }, |
41 | }, | |
42 | # real video id 57591 | |
43 | { | |
ffe8f62d | 44 | 'url': 'http://smotri.com/video/view/?id=v57591cb20', |
ffe8f62d | 45 | 'md5': '830266dfc21f077eac5afd1883091bcd', |
46 | 'info_dict': { | |
cb3ac1c6 S |
47 | 'id': 'v57591cb20', |
48 | 'ext': 'flv', | |
ffe8f62d | 49 | 'title': 'test', |
50 | 'uploader': 'Support Photofile@photofile', | |
51 | 'uploader_id': 'support-photofile', | |
52 | 'upload_date': '20070704', | |
ffe8f62d | 53 | 'thumbnail': 'http://frame4.loadup.ru/03/ed/57591.2.3.jpg', |
aaebed13 | 54 | }, |
5270d8cb | 55 | }, |
56 | # video-password | |
57 | { | |
ffe8f62d | 58 | 'url': 'http://smotri.com/video/view/?id=v1390466a13c', |
ffe8f62d | 59 | 'md5': 'f6331cef33cad65a0815ee482a54440b', |
60 | 'info_dict': { | |
cb3ac1c6 S |
61 | 'id': 'v1390466a13c', |
62 | 'ext': 'mp4', | |
ffe8f62d | 63 | 'title': 'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1', |
64 | 'uploader': 'timoxa40', | |
65 | 'uploader_id': 'timoxa40', | |
66 | 'upload_date': '20100404', | |
67 | 'thumbnail': 'http://frame7.loadup.ru/af/3f/1390466.3.3.jpg', | |
5270d8cb | 68 | }, |
ffe8f62d | 69 | 'params': { |
70 | 'videopassword': 'qwerty', | |
5270d8cb | 71 | }, |
544dec62 | 72 | 'skip': 'Video is not approved by moderator', |
5270d8cb | 73 | }, |
74 | # age limit + video-password | |
75 | { | |
ffe8f62d | 76 | 'url': 'http://smotri.com/video/view/?id=v15408898bcf', |
ffe8f62d | 77 | 'md5': '91e909c9f0521adf5ee86fbe073aad70', |
78 | 'info_dict': { | |
cb3ac1c6 S |
79 | 'id': 'v15408898bcf', |
80 | 'ext': 'flv', | |
ffe8f62d | 81 | 'title': 'этот ролик не покажут по ТВ', |
82 | 'uploader': 'zzxxx', | |
83 | 'uploader_id': 'ueggb', | |
84 | 'upload_date': '20101001', | |
85 | 'thumbnail': 'http://frame3.loadup.ru/75/75/1540889.1.3.jpg', | |
86 | 'age_limit': 18, | |
aaebed13 | 87 | }, |
ffe8f62d | 88 | 'params': { |
89 | 'videopassword': '333' | |
544dec62 S |
90 | }, |
91 | 'skip': 'Video is not approved by moderator', | |
cb3ac1c6 | 92 | }, |
c9ef44ce S |
93 | # not approved by moderator, but available |
94 | { | |
95 | 'url': 'http://smotri.com/video/view/?id=v28888533b73', | |
96 | 'md5': 'f44bc7adac90af518ef1ecf04893bb34', | |
97 | 'info_dict': { | |
98 | 'id': 'v28888533b73', | |
99 | 'ext': 'mp4', | |
100 | 'title': 'Russian Spies Killed By ISIL Child Soldier', | |
101 | 'uploader': 'Mopeder', | |
102 | 'uploader_id': 'mopeder', | |
103 | 'duration': 71, | |
104 | 'thumbnail': 'http://frame9.loadup.ru/d7/32/2888853.2.3.jpg', | |
37f4ce53 | 105 | 'upload_date': '20150114', |
c9ef44ce S |
106 | }, |
107 | }, | |
cb3ac1c6 S |
108 | # swf player |
109 | { | |
110 | 'url': 'http://pics.smotri.com/scrubber_custom8.swf?file=v9188090500', | |
749f2ca0 | 111 | 'md5': '31099eeb4bc906712c5f40092045108d', |
cb3ac1c6 S |
112 | 'info_dict': { |
113 | 'id': 'v9188090500', | |
114 | 'ext': 'mp4', | |
115 | 'title': 'Shakira - Don\'t Bother', | |
116 | 'uploader': 'HannahL', | |
117 | 'uploader_id': 'lisaha95', | |
118 | 'upload_date': '20090331', | |
cb3ac1c6 S |
119 | 'thumbnail': 'http://frame8.loadup.ru/44/0b/918809.7.3.jpg', |
120 | }, | |
121 | }, | |
5270d8cb | 122 | ] |
ffe8f62d | 123 | |
cb3ac1c6 S |
124 | @classmethod |
125 | def _extract_url(cls, webpage): | |
126 | mobj = re.search( | |
127 | r'<embed[^>]src=(["\'])(?P<url>http://pics\.smotri\.com/(?:player|scrubber_custom8)\.swf\?file=v.+?\1)', | |
128 | webpage) | |
129 | if mobj is not None: | |
130 | return mobj.group('url') | |
131 | ||
132 | mobj = re.search( | |
133 | r'''(?x)<div\s+class="video_file">http://smotri\.com/video/download/file/[^<]+</div>\s* | |
134 | <div\s+class="video_image">[^<]+</div>\s* | |
135 | <div\s+class="video_id">(?P<id>[^<]+)</div>''', webpage) | |
136 | if mobj is not None: | |
137 | return 'http://smotri.com/video/view/?id=%s' % mobj.group('id') | |
138 | ||
5270d8cb | 139 | def _search_meta(self, name, html, display_name=None): |
140 | if display_name is None: | |
141 | display_name = name | |
aaebed13 PH |
142 | return self._html_search_meta(name, html, display_name) |
143 | ||
5270d8cb | 144 | def _real_extract(self, url): |
598c218f S |
145 | video_id = self._match_id(url) |
146 | ||
147 | video_form = { | |
148 | 'ticket': video_id, | |
149 | 'video_url': '1', | |
150 | 'frame_url': '1', | |
151 | 'devid': 'LoadupFlashPlayer', | |
152 | 'getvideoinfo': '1', | |
153 | } | |
5270d8cb | 154 | |
598c218f S |
155 | request = compat_urllib_request.Request( |
156 | 'http://smotri.com/video/view/url/bot/', compat_urllib_parse.urlencode(video_form)) | |
157 | request.add_header('Content-Type', 'application/x-www-form-urlencoded') | |
ffe8f62d | 158 | |
598c218f | 159 | video = self._download_json(request, video_id, 'Downloading video JSON') |
ffe8f62d | 160 | |
c9ef44ce S |
161 | video_url = video.get('_vidURL') or video.get('_vidURL_mp4') |
162 | ||
163 | if not video_url: | |
164 | if video.get('_moderate_no') or not video.get('moderated'): | |
165 | raise ExtractorError( | |
166 | 'Video %s has not been approved by moderator' % video_id, expected=True) | |
ffe8f62d | 167 | |
c9ef44ce S |
168 | if video.get('error'): |
169 | raise ExtractorError('Video %s does not exist' % video_id, expected=True) | |
598c218f | 170 | |
598c218f S |
171 | title = video['title'] |
172 | thumbnail = video['_imgURL'] | |
173 | upload_date = unified_strdate(video['added']) | |
174 | uploader = video['userNick'] | |
175 | uploader_id = video['userLogin'] | |
176 | duration = int_or_none(video['duration']) | |
ffe8f62d | 177 | |
5270d8cb | 178 | # Video JSON does not provide enough meta data |
179 | # We will extract some from the video web page instead | |
598c218f S |
180 | webpage_url = 'http://smotri.com/video/view/?id=%s' % video_id |
181 | webpage = self._download_webpage(webpage_url, video_id, 'Downloading video page') | |
7dbf5ae5 PH |
182 | |
183 | # Warning if video is unavailable | |
184 | warning = self._html_search_regex( | |
598c218f | 185 | r'<div class="videoUnModer">(.*?)</div>', webpage, |
ffe8f62d | 186 | 'warning message', default=None) |
7dbf5ae5 PH |
187 | if warning is not None: |
188 | self._downloader.report_warning( | |
ffe8f62d | 189 | 'Video %s may not be available; smotri said: %s ' % |
7dbf5ae5 PH |
190 | (video_id, warning)) |
191 | ||
5270d8cb | 192 | # Adult content |
598c218f | 193 | if re.search('EroConfirmText">', webpage) is not None: |
5270d8cb | 194 | self.report_age_confirmation() |
195 | confirm_string = self._html_search_regex( | |
aaebed13 | 196 | r'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id, |
598c218f S |
197 | webpage, 'confirm string') |
198 | confirm_url = webpage_url + '&confirm=%s' % confirm_string | |
199 | webpage = self._download_webpage(confirm_url, video_id, 'Downloading video page (age confirmed)') | |
5270d8cb | 200 | adult_content = True |
201 | else: | |
202 | adult_content = False | |
ffe8f62d | 203 | |
598c218f | 204 | view_count = self._html_search_regex( |
ffe8f62d | 205 | 'Общее количество просмотров.*?<span class="Number">(\\d+)</span>', |
2514d263 | 206 | webpage, 'view count', fatal=False, flags=re.MULTILINE | re.DOTALL) |
ffe8f62d | 207 | |
5270d8cb | 208 | return { |
209 | 'id': video_id, | |
210 | 'url': video_url, | |
598c218f S |
211 | 'title': title, |
212 | 'thumbnail': thumbnail, | |
213 | 'uploader': uploader, | |
214 | 'upload_date': upload_date, | |
215 | 'uploader_id': uploader_id, | |
216 | 'duration': duration, | |
217 | 'view_count': int_or_none(view_count), | |
5270d8cb | 218 | 'age_limit': 18 if adult_content else 0, |
5270d8cb | 219 | } |
220 | ||
aaebed13 | 221 | |
5270d8cb | 222 | class SmotriCommunityIE(InfoExtractor): |
ffe8f62d | 223 | IE_DESC = 'Smotri.com community videos' |
224 | IE_NAME = 'smotri:community' | |
aaebed13 | 225 | _VALID_URL = r'^https?://(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)' |
22a6f150 PH |
226 | _TEST = { |
227 | 'url': 'http://smotri.com/community/video/kommuna', | |
228 | 'info_dict': { | |
229 | 'id': 'kommuna', | |
230 | 'title': 'КПРФ', | |
231 | }, | |
232 | 'playlist_mincount': 4, | |
233 | } | |
5f6a1245 | 234 | |
5270d8cb | 235 | def _real_extract(self, url): |
236 | mobj = re.match(self._VALID_URL, url) | |
237 | community_id = mobj.group('communityid') | |
aaebed13 | 238 | |
5270d8cb | 239 | url = 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id |
ffe8f62d | 240 | rss = self._download_xml(url, community_id, 'Downloading community RSS') |
aaebed13 | 241 | |
5270d8cb | 242 | entries = [self.url_result(video_url.text, 'Smotri') |
243 | for video_url in rss.findall('./channel/item/link')] | |
aaebed13 PH |
244 | |
245 | description_text = rss.find('./channel/description').text | |
5270d8cb | 246 | community_title = self._html_search_regex( |
ffe8f62d | 247 | '^Видео сообщества "([^"]+)"$', description_text, 'community title') |
5270d8cb | 248 | |
249 | return self.playlist_result(entries, community_id, community_title) | |
aaebed13 PH |
250 | |
251 | ||
5270d8cb | 252 | class SmotriUserIE(InfoExtractor): |
ffe8f62d | 253 | IE_DESC = 'Smotri.com user videos' |
254 | IE_NAME = 'smotri:user' | |
aaebed13 | 255 | _VALID_URL = r'^https?://(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)' |
22a6f150 PH |
256 | _TESTS = [{ |
257 | 'url': 'http://smotri.com/user/inspector', | |
258 | 'info_dict': { | |
259 | 'id': 'inspector', | |
260 | 'title': 'Inspector', | |
261 | }, | |
262 | 'playlist_mincount': 9, | |
263 | }] | |
aaebed13 | 264 | |
5270d8cb | 265 | def _real_extract(self, url): |
aaebed13 | 266 | mobj = re.match(self._VALID_URL, url) |
5270d8cb | 267 | user_id = mobj.group('userid') |
aaebed13 | 268 | |
5270d8cb | 269 | url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id |
ffe8f62d | 270 | rss = self._download_xml(url, user_id, 'Downloading user RSS') |
aaebed13 | 271 | |
5270d8cb | 272 | entries = [self.url_result(video_url.text, 'Smotri') |
273 | for video_url in rss.findall('./channel/item/link')] | |
aaebed13 PH |
274 | |
275 | description_text = rss.find('./channel/description').text | |
5270d8cb | 276 | user_nickname = self._html_search_regex( |
ffe8f62d | 277 | '^Видео режиссера (.*)$', description_text, |
278 | 'user nickname') | |
5270d8cb | 279 | |
280 | return self.playlist_result(entries, user_id, user_nickname) | |
55f6597c | 281 | |
282 | ||
283 | class SmotriBroadcastIE(InfoExtractor): | |
ffe8f62d | 284 | IE_DESC = 'Smotri.com broadcasts' |
285 | IE_NAME = 'smotri:broadcast' | |
55f6597c | 286 | _VALID_URL = r'^https?://(?:www\.)?(?P<url>smotri\.com/live/(?P<broadcastid>[^/]+))/?.*' |
287 | ||
288 | def _real_extract(self, url): | |
289 | mobj = re.match(self._VALID_URL, url) | |
290 | broadcast_id = mobj.group('broadcastid') | |
291 | ||
292 | broadcast_url = 'http://' + mobj.group('url') | |
ffe8f62d | 293 | broadcast_page = self._download_webpage(broadcast_url, broadcast_id, 'Downloading broadcast page') |
55f6597c | 294 | |
ffe8f62d | 295 | if re.search('>Режиссер с логином <br/>"%s"<br/> <span>не существует<' % broadcast_id, broadcast_page) is not None: |
a81bbebf S |
296 | raise ExtractorError( |
297 | 'Broadcast %s does not exist' % broadcast_id, expected=True) | |
55f6597c | 298 | |
299 | # Adult content | |
ffe8f62d | 300 | if re.search('EroConfirmText">', broadcast_page) is not None: |
55f6597c | 301 | |
302 | (username, password) = self._get_login_info() | |
303 | if username is None: | |
a81bbebf S |
304 | raise ExtractorError( |
305 | 'Erotic broadcasts allowed only for registered users, ' | |
306 | 'use --username and --password options to provide account credentials.', | |
307 | expected=True) | |
ffe8f62d | 308 | |
309 | login_form = { | |
310 | 'login-hint53': '1', | |
311 | 'confirm_erotic': '1', | |
312 | 'login': username, | |
313 | 'password': password, | |
55f6597c | 314 | } |
ffe8f62d | 315 | |
a81bbebf S |
316 | request = compat_urllib_request.Request( |
317 | broadcast_url + '/?no_redirect=1', compat_urllib_parse.urlencode(login_form)) | |
55f6597c | 318 | request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
a81bbebf S |
319 | broadcast_page = self._download_webpage( |
320 | request, broadcast_id, 'Logging in and confirming age') | |
55f6597c | 321 | |
ffe8f62d | 322 | if re.search('>Неверный логин или пароль<', broadcast_page) is not None: |
323 | raise ExtractorError('Unable to log in: bad username or password', expected=True) | |
55f6597c | 324 | |
325 | adult_content = True | |
326 | else: | |
327 | adult_content = False | |
328 | ||
329 | ticket = self._html_search_regex( | |
a81bbebf | 330 | r"window\.broadcast_control\.addFlashVar\('file'\s*,\s*'([^']+)'\)", |
ffe8f62d | 331 | broadcast_page, 'broadcast ticket') |
55f6597c | 332 | |
333 | url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket | |
334 | ||
335 | broadcast_password = self._downloader.params.get('videopassword', None) | |
336 | if broadcast_password: | |
337 | url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest() | |
338 | ||
a81bbebf S |
339 | broadcast_json_page = self._download_webpage( |
340 | url, broadcast_id, 'Downloading broadcast JSON') | |
55f6597c | 341 | |
342 | try: | |
343 | broadcast_json = json.loads(broadcast_json_page) | |
344 | ||
345 | protected_broadcast = broadcast_json['_pass_protected'] == 1 | |
346 | if protected_broadcast and not broadcast_password: | |
a81bbebf S |
347 | raise ExtractorError( |
348 | 'This broadcast is protected by a password, use the --video-password option', | |
349 | expected=True) | |
55f6597c | 350 | |
351 | broadcast_offline = broadcast_json['is_play'] == 0 | |
352 | if broadcast_offline: | |
ffe8f62d | 353 | raise ExtractorError('Broadcast %s is offline' % broadcast_id, expected=True) |
55f6597c | 354 | |
355 | rtmp_url = broadcast_json['_server'] | |
a81bbebf S |
356 | mobj = re.search(r'^rtmp://[^/]+/(?P<app>.+)/?$', rtmp_url) |
357 | if not mobj: | |
ffe8f62d | 358 | raise ExtractorError('Unexpected broadcast rtmp URL') |
55f6597c | 359 | |
360 | broadcast_playpath = broadcast_json['_streamName'] | |
a81bbebf | 361 | broadcast_app = '%s/%s' % (mobj.group('app'), broadcast_json['_vidURL']) |
55f6597c | 362 | broadcast_thumbnail = broadcast_json['_imgURL'] |
a81bbebf | 363 | broadcast_title = self._live_title(broadcast_json['title']) |
55f6597c | 364 | broadcast_description = broadcast_json['description'] |
365 | broadcaster_nick = broadcast_json['nick'] | |
366 | broadcaster_login = broadcast_json['login'] | |
367 | rtmp_conn = 'S:%s' % uuid.uuid4().hex | |
368 | except KeyError: | |
369 | if protected_broadcast: | |
ffe8f62d | 370 | raise ExtractorError('Bad broadcast password', expected=True) |
371 | raise ExtractorError('Unexpected broadcast JSON') | |
55f6597c | 372 | |
373 | return { | |
374 | 'id': broadcast_id, | |
375 | 'url': rtmp_url, | |
376 | 'title': broadcast_title, | |
377 | 'thumbnail': broadcast_thumbnail, | |
378 | 'description': broadcast_description, | |
379 | 'uploader': broadcaster_nick, | |
380 | 'uploader_id': broadcaster_login, | |
381 | 'age_limit': 18 if adult_content else 0, | |
382 | 'ext': 'flv', | |
383 | 'play_path': broadcast_playpath, | |
a81bbebf S |
384 | 'player_url': 'http://pics.smotri.com/broadcast_play.swf', |
385 | 'app': broadcast_app, | |
55f6597c | 386 | 'rtmp_live': True, |
a81bbebf S |
387 | 'rtmp_conn': rtmp_conn, |
388 | 'is_live': True, | |
693b8b2d | 389 | } |