2 from __future__ import unicode_literals
9 from .common import InfoExtractor
20 class SmotriIE(InfoExtractor):
21 IE_DESC = 'Smotri.com'
23 _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})'
24 _NETRC_MACHINE = 'smotri'
27 # real video id 2610366
29 'url': 'http://smotri.com/video/view/?id=v261036632ab',
30 'md5': '02c0dfab2102984e9c5bb585cc7cc321',
34 'title': 'катастрофа с камер видеонаблюдения',
35 'uploader': 'rbc2008',
36 'uploader_id': 'rbc08',
37 'upload_date': '20131118',
38 'thumbnail': 'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg',
43 'url': 'http://smotri.com/video/view/?id=v57591cb20',
44 'md5': '830266dfc21f077eac5afd1883091bcd',
49 'uploader': 'Support Photofile@photofile',
50 'uploader_id': 'support-photofile',
51 'upload_date': '20070704',
52 'thumbnail': 'http://frame4.loadup.ru/03/ed/57591.2.3.jpg',
55 # video-password, not approved by moderator
57 'url': 'http://smotri.com/video/view/?id=v1390466a13c',
58 'md5': 'f6331cef33cad65a0815ee482a54440b',
62 'title': 'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
63 'uploader': 'timoxa40',
64 'uploader_id': 'timoxa40',
65 'upload_date': '20100404',
66 'thumbnail': 'http://frame7.loadup.ru/af/3f/1390466.3.3.jpg',
69 'videopassword': 'qwerty',
71 'skip': 'Video is not approved by moderator',
75 'url': 'http://smotri.com/video/view/?id=v6984858774#',
76 'md5': 'f11e01d13ac676370fc3b95b9bda11b0',
80 'title': 'Дача Солженицина ПАРОЛЬ 223322',
81 'uploader': 'psavari1',
82 'uploader_id': 'psavari1',
83 'upload_date': '20081103',
84 'thumbnail': r're:^https?://.*\.jpg$',
87 'videopassword': '223322',
90 # age limit + video-password, not approved by moderator
92 'url': 'http://smotri.com/video/view/?id=v15408898bcf',
93 'md5': '91e909c9f0521adf5ee86fbe073aad70',
97 'title': 'этот ролик не покажут по ТВ',
99 'uploader_id': 'ueggb',
100 'upload_date': '20101001',
101 'thumbnail': 'http://frame3.loadup.ru/75/75/1540889.1.3.jpg',
105 'videopassword': '333'
107 'skip': 'Video is not approved by moderator',
109 # age limit + video-password
111 'url': 'http://smotri.com/video/view/?id=v7780025814',
112 'md5': 'b4599b068422559374a59300c5337d72',
116 'title': 'Sexy Beach (пароль 123)',
118 'uploader_id': 'asya_prosto',
119 'upload_date': '20081218',
120 'thumbnail': r're:^https?://.*\.jpg$',
124 'videopassword': '123'
129 'url': 'http://pics.smotri.com/scrubber_custom8.swf?file=v9188090500',
130 'md5': '31099eeb4bc906712c5f40092045108d',
134 'title': 'Shakira - Don\'t Bother',
135 'uploader': 'HannahL',
136 'uploader_id': 'lisaha95',
137 'upload_date': '20090331',
138 'thumbnail': 'http://frame8.loadup.ru/44/0b/918809.7.3.jpg',
144 def _extract_url(cls, webpage):
146 r'<embed[^>]src=(["\'])(?P<url>http://pics\.smotri\.com/(?:player|scrubber_custom8)\.swf\?file=v.+?\1)',
149 return mobj.group('url')
152 r'''(?x)<div\s+class="video_file">http://smotri\.com/video/download/file/[^<]+</div>\s*
153 <div\s+class="video_image">[^<]+</div>\s*
154 <div\s+class="video_id">(?P<id>[^<]+)</div>''', webpage)
156 return 'http://smotri.com/video/view/?id=%s' % mobj.group('id')
158 def _search_meta(self, name, html, display_name=None):
159 if display_name is None:
161 return self._html_search_meta(name, html, display_name)
163 def _real_extract(self, url):
164 video_id = self._match_id(url)
170 'devid': 'LoadupFlashPlayer',
174 video_password = self._downloader.params.get('videopassword')
176 video_form['pass'] = hashlib.md5(video_password.encode('utf-8')).hexdigest()
178 video = self._download_json(
179 'http://smotri.com/video/view/url/bot/',
180 video_id, 'Downloading video JSON',
181 data=urlencode_postdata(video_form),
182 headers={'Content-Type': 'application/x-www-form-urlencoded'})
184 video_url = video.get('_vidURL') or video.get('_vidURL_mp4')
187 if video.get('_moderate_no'):
188 raise ExtractorError(
189 'Video %s has not been approved by moderator' % video_id, expected=True)
191 if video.get('error'):
192 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
194 if video.get('_pass_protected') == 1:
195 msg = ('Invalid video password' if video_password
196 else 'This video is protected by a password, use the --video-password option')
197 raise ExtractorError(msg, expected=True)
199 title = video['title']
200 thumbnail = video.get('_imgURL')
201 upload_date = unified_strdate(video.get('added'))
202 uploader = video.get('userNick')
203 uploader_id = video.get('userLogin')
204 duration = int_or_none(video.get('duration'))
206 # Video JSON does not provide enough meta data
207 # We will extract some from the video web page instead
208 webpage_url = 'http://smotri.com/video/view/?id=%s' % video_id
209 webpage = self._download_webpage(webpage_url, video_id, 'Downloading video page')
211 # Warning if video is unavailable
212 warning = self._html_search_regex(
213 r'<div[^>]+class="videoUnModer"[^>]*>(.+?)</div>', webpage,
214 'warning message', default=None)
215 if warning is not None:
216 self._downloader.report_warning(
217 'Video %s may not be available; smotri said: %s ' %
221 if 'EroConfirmText">' in webpage:
222 self.report_age_confirmation()
223 confirm_string = self._html_search_regex(
224 r'<a[^>]+href="/video/view/\?id=%s&confirm=([^"]+)"' % video_id,
225 webpage, 'confirm string')
226 confirm_url = webpage_url + '&confirm=%s' % confirm_string
227 webpage = self._download_webpage(
228 confirm_url, video_id,
229 'Downloading video page (age confirmed)')
232 adult_content = False
234 view_count = self._html_search_regex(
235 r'(?s)Общее количество просмотров.*?<span class="Number">(\d+)</span>',
236 webpage, 'view count', fatal=False)
242 'thumbnail': thumbnail,
243 'uploader': uploader,
244 'upload_date': upload_date,
245 'uploader_id': uploader_id,
246 'duration': duration,
247 'view_count': int_or_none(view_count),
248 'age_limit': 18 if adult_content else 0,
252 class SmotriCommunityIE(InfoExtractor):
253 IE_DESC = 'Smotri.com community videos'
254 IE_NAME = 'smotri:community'
255 _VALID_URL = r'https?://(?:www\.)?smotri\.com/community/video/(?P<id>[0-9A-Za-z_\'-]+)'
257 'url': 'http://smotri.com/community/video/kommuna',
261 'playlist_mincount': 4,
264 def _real_extract(self, url):
265 community_id = self._match_id(url)
267 rss = self._download_xml(
268 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id,
269 community_id, 'Downloading community RSS')
272 self.url_result(video_url.text, SmotriIE.ie_key())
273 for video_url in rss.findall('./channel/item/link')]
275 return self.playlist_result(entries, community_id)
278 class SmotriUserIE(InfoExtractor):
279 IE_DESC = 'Smotri.com user videos'
280 IE_NAME = 'smotri:user'
281 _VALID_URL = r'https?://(?:www\.)?smotri\.com/user/(?P<id>[0-9A-Za-z_\'-]+)'
283 'url': 'http://smotri.com/user/inspector',
286 'title': 'Inspector',
288 'playlist_mincount': 9,
291 def _real_extract(self, url):
292 user_id = self._match_id(url)
294 rss = self._download_xml(
295 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id,
296 user_id, 'Downloading user RSS')
298 entries = [self.url_result(video_url.text, 'Smotri')
299 for video_url in rss.findall('./channel/item/link')]
301 description_text = xpath_text(rss, './channel/description') or ''
302 user_nickname = self._search_regex(
303 '^Видео режиссера (.+)$', description_text,
304 'user nickname', fatal=False)
306 return self.playlist_result(entries, user_id, user_nickname)
309 class SmotriBroadcastIE(InfoExtractor):
310 IE_DESC = 'Smotri.com broadcasts'
311 IE_NAME = 'smotri:broadcast'
312 _VALID_URL = r'https?://(?:www\.)?(?P<url>smotri\.com/live/(?P<id>[^/]+))/?.*'
313 _NETRC_MACHINE = 'smotri'
315 def _real_extract(self, url):
316 mobj = re.match(self._VALID_URL, url)
317 broadcast_id = mobj.group('id')
319 broadcast_url = 'http://' + mobj.group('url')
320 broadcast_page = self._download_webpage(broadcast_url, broadcast_id, 'Downloading broadcast page')
322 if re.search('>Режиссер с логином <br/>"%s"<br/> <span>не существует<' % broadcast_id, broadcast_page) is not None:
323 raise ExtractorError(
324 'Broadcast %s does not exist' % broadcast_id, expected=True)
327 if re.search('EroConfirmText">', broadcast_page) is not None:
329 (username, password) = self._get_login_info()
331 self.raise_login_required(
332 'Erotic broadcasts allowed only for registered users')
336 'confirm_erotic': '1',
338 'password': password,
341 request = sanitized_Request(
342 broadcast_url + '/?no_redirect=1', urlencode_postdata(login_form))
343 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
344 broadcast_page = self._download_webpage(
345 request, broadcast_id, 'Logging in and confirming age')
347 if '>Неверный логин или пароль<' in broadcast_page:
348 raise ExtractorError(
349 'Unable to log in: bad username or password', expected=True)
353 adult_content = False
355 ticket = self._html_search_regex(
356 (r'data-user-file=(["\'])(?P<ticket>(?!\1).+)\1',
357 r"window\.broadcast_control\.addFlashVar\('file'\s*,\s*'(?P<ticket>[^']+)'\)"),
358 broadcast_page, 'broadcast ticket', group='ticket')
360 broadcast_url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket
362 broadcast_password = self._downloader.params.get('videopassword')
363 if broadcast_password:
364 broadcast_url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest()
366 broadcast_json_page = self._download_webpage(
367 broadcast_url, broadcast_id, 'Downloading broadcast JSON')
370 broadcast_json = json.loads(broadcast_json_page)
372 protected_broadcast = broadcast_json['_pass_protected'] == 1
373 if protected_broadcast and not broadcast_password:
374 raise ExtractorError(
375 'This broadcast is protected by a password, use the --video-password option',
378 broadcast_offline = broadcast_json['is_play'] == 0
379 if broadcast_offline:
380 raise ExtractorError('Broadcast %s is offline' % broadcast_id, expected=True)
382 rtmp_url = broadcast_json['_server']
383 mobj = re.search(r'^rtmp://[^/]+/(?P<app>.+)/?$', rtmp_url)
385 raise ExtractorError('Unexpected broadcast rtmp URL')
387 broadcast_playpath = broadcast_json['_streamName']
388 broadcast_app = '%s/%s' % (mobj.group('app'), broadcast_json['_vidURL'])
389 broadcast_thumbnail = broadcast_json.get('_imgURL')
390 broadcast_title = self._live_title(broadcast_json['title'])
391 broadcast_description = broadcast_json.get('description')
392 broadcaster_nick = broadcast_json.get('nick')
393 broadcaster_login = broadcast_json.get('login')
394 rtmp_conn = 'S:%s' % uuid.uuid4().hex
396 if protected_broadcast:
397 raise ExtractorError('Bad broadcast password', expected=True)
398 raise ExtractorError('Unexpected broadcast JSON')
403 'title': broadcast_title,
404 'thumbnail': broadcast_thumbnail,
405 'description': broadcast_description,
406 'uploader': broadcaster_nick,
407 'uploader_id': broadcaster_login,
408 'age_limit': 18 if adult_content else 0,
410 'play_path': broadcast_playpath,
411 'player_url': 'http://pics.smotri.com/broadcast_play.swf',
412 'app': broadcast_app,
414 'rtmp_conn': rtmp_conn,