2 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from ..compat import (
12 compat_urllib_request,
21 class SmotriIE(InfoExtractor):
22 IE_DESC = 'Smotri.com'
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})'
25 _NETRC_MACHINE = 'smotri'
28 # real video id 2610366
30 'url': 'http://smotri.com/video/view/?id=v261036632ab',
31 'md5': '2a7b08249e6f5636557579c368040eb9',
35 'title': 'катастрофа с камер видеонаблюдения',
36 'uploader': 'rbc2008',
37 'uploader_id': 'rbc08',
38 'upload_date': '20131118',
39 'thumbnail': 'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg',
44 'url': 'http://smotri.com/video/view/?id=v57591cb20',
45 'md5': '830266dfc21f077eac5afd1883091bcd',
50 'uploader': 'Support Photofile@photofile',
51 'uploader_id': 'support-photofile',
52 'upload_date': '20070704',
53 'thumbnail': 'http://frame4.loadup.ru/03/ed/57591.2.3.jpg',
58 'url': 'http://smotri.com/video/view/?id=v1390466a13c',
59 'md5': 'f6331cef33cad65a0815ee482a54440b',
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',
70 'videopassword': 'qwerty',
72 'skip': 'Video is not approved by moderator',
74 # age limit + video-password
76 'url': 'http://smotri.com/video/view/?id=v15408898bcf',
77 'md5': '91e909c9f0521adf5ee86fbe073aad70',
81 'title': 'этот ролик не покажут по ТВ',
83 'uploader_id': 'ueggb',
84 'upload_date': '20101001',
85 'thumbnail': 'http://frame3.loadup.ru/75/75/1540889.1.3.jpg',
89 'videopassword': '333'
91 'skip': 'Video is not approved by moderator',
93 # not approved by moderator, but available
95 'url': 'http://smotri.com/video/view/?id=v28888533b73',
96 'md5': 'f44bc7adac90af518ef1ecf04893bb34',
100 'title': 'Russian Spies Killed By ISIL Child Soldier',
101 'uploader': 'Mopeder',
102 'uploader_id': 'mopeder',
104 'thumbnail': 'http://frame9.loadup.ru/d7/32/2888853.2.3.jpg',
105 'upload_date': '20150114',
110 'url': 'http://pics.smotri.com/scrubber_custom8.swf?file=v9188090500',
111 'md5': '4d47034979d9390d14acdf59c4935bc2',
115 'title': 'Shakira - Don\'t Bother',
116 'uploader': 'HannahL',
117 'uploader_id': 'lisaha95',
118 'upload_date': '20090331',
119 'thumbnail': 'http://frame8.loadup.ru/44/0b/918809.7.3.jpg',
125 def _extract_url(cls, webpage):
127 r'<embed[^>]src=(["\'])(?P<url>http://pics\.smotri\.com/(?:player|scrubber_custom8)\.swf\?file=v.+?\1)',
130 return mobj.group('url')
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)
137 return 'http://smotri.com/video/view/?id=%s' % mobj.group('id')
139 def _search_meta(self, name, html, display_name=None):
140 if display_name is None:
142 return self._html_search_regex(
143 r'<meta itemprop="%s" content="([^"]+)" />' % re.escape(name),
144 html, display_name, fatal=False)
145 return self._html_search_meta(name, html, display_name)
147 def _real_extract(self, url):
148 video_id = self._match_id(url)
154 'devid': 'LoadupFlashPlayer',
158 request = compat_urllib_request.Request(
159 'http://smotri.com/video/view/url/bot/', compat_urllib_parse.urlencode(video_form))
160 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
162 video = self._download_json(request, video_id, 'Downloading video JSON')
164 video_url = video.get('_vidURL') or video.get('_vidURL_mp4')
167 if video.get('_moderate_no') or not video.get('moderated'):
168 raise ExtractorError(
169 'Video %s has not been approved by moderator' % video_id, expected=True)
171 if video.get('error'):
172 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
174 title = video['title']
175 thumbnail = video['_imgURL']
176 upload_date = unified_strdate(video['added'])
177 uploader = video['userNick']
178 uploader_id = video['userLogin']
179 duration = int_or_none(video['duration'])
181 # Video JSON does not provide enough meta data
182 # We will extract some from the video web page instead
183 webpage_url = 'http://smotri.com/video/view/?id=%s' % video_id
184 webpage = self._download_webpage(webpage_url, video_id, 'Downloading video page')
186 # Warning if video is unavailable
187 warning = self._html_search_regex(
188 r'<div class="videoUnModer">(.*?)</div>', webpage,
189 'warning message', default=None)
190 if warning is not None:
191 self._downloader.report_warning(
192 'Video %s may not be available; smotri said: %s ' %
196 if re.search('EroConfirmText">', webpage) is not None:
197 self.report_age_confirmation()
198 confirm_string = self._html_search_regex(
199 r'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id,
200 webpage, 'confirm string')
201 confirm_url = webpage_url + '&confirm=%s' % confirm_string
202 webpage = self._download_webpage(confirm_url, video_id, 'Downloading video page (age confirmed)')
205 adult_content = False
207 view_count = self._html_search_regex(
208 'Общее количество просмотров.*?<span class="Number">(\\d+)</span>',
209 webpage, 'view count', fatal=False, flags=re.MULTILINE | re.DOTALL)
215 'thumbnail': thumbnail,
216 'uploader': uploader,
217 'upload_date': upload_date,
218 'uploader_id': uploader_id,
219 'duration': duration,
220 'view_count': int_or_none(view_count),
221 'age_limit': 18 if adult_content else 0,
225 class SmotriCommunityIE(InfoExtractor):
226 IE_DESC = 'Smotri.com community videos'
227 IE_NAME = 'smotri:community'
228 _VALID_URL = r'^https?://(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)'
230 'url': 'http://smotri.com/community/video/kommuna',
235 'playlist_mincount': 4,
238 def _real_extract(self, url):
239 mobj = re.match(self._VALID_URL, url)
240 community_id = mobj.group('communityid')
242 url = 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id
243 rss = self._download_xml(url, community_id, 'Downloading community RSS')
245 entries = [self.url_result(video_url.text, 'Smotri')
246 for video_url in rss.findall('./channel/item/link')]
248 description_text = rss.find('./channel/description').text
249 community_title = self._html_search_regex(
250 '^Видео сообщества "([^"]+)"$', description_text, 'community title')
252 return self.playlist_result(entries, community_id, community_title)
255 class SmotriUserIE(InfoExtractor):
256 IE_DESC = 'Smotri.com user videos'
257 IE_NAME = 'smotri:user'
258 _VALID_URL = r'^https?://(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)'
260 'url': 'http://smotri.com/user/inspector',
263 'title': 'Inspector',
265 'playlist_mincount': 9,
268 def _real_extract(self, url):
269 mobj = re.match(self._VALID_URL, url)
270 user_id = mobj.group('userid')
272 url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id
273 rss = self._download_xml(url, user_id, 'Downloading user RSS')
275 entries = [self.url_result(video_url.text, 'Smotri')
276 for video_url in rss.findall('./channel/item/link')]
278 description_text = rss.find('./channel/description').text
279 user_nickname = self._html_search_regex(
280 '^Видео режиссера (.*)$', description_text,
283 return self.playlist_result(entries, user_id, user_nickname)
286 class SmotriBroadcastIE(InfoExtractor):
287 IE_DESC = 'Smotri.com broadcasts'
288 IE_NAME = 'smotri:broadcast'
289 _VALID_URL = r'^https?://(?:www\.)?(?P<url>smotri\.com/live/(?P<broadcastid>[^/]+))/?.*'
291 def _real_extract(self, url):
292 mobj = re.match(self._VALID_URL, url)
293 broadcast_id = mobj.group('broadcastid')
295 broadcast_url = 'http://' + mobj.group('url')
296 broadcast_page = self._download_webpage(broadcast_url, broadcast_id, 'Downloading broadcast page')
298 if re.search('>Режиссер с логином <br/>"%s"<br/> <span>не существует<' % broadcast_id, broadcast_page) is not None:
299 raise ExtractorError(
300 'Broadcast %s does not exist' % broadcast_id, expected=True)
303 if re.search('EroConfirmText">', broadcast_page) is not None:
305 (username, password) = self._get_login_info()
307 raise ExtractorError(
308 'Erotic broadcasts allowed only for registered users, '
309 'use --username and --password options to provide account credentials.',
314 'confirm_erotic': '1',
316 'password': password,
319 request = compat_urllib_request.Request(
320 broadcast_url + '/?no_redirect=1', compat_urllib_parse.urlencode(login_form))
321 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
322 broadcast_page = self._download_webpage(
323 request, broadcast_id, 'Logging in and confirming age')
325 if re.search('>Неверный логин или пароль<', broadcast_page) is not None:
326 raise ExtractorError('Unable to log in: bad username or password', expected=True)
330 adult_content = False
332 ticket = self._html_search_regex(
333 r"window\.broadcast_control\.addFlashVar\('file'\s*,\s*'([^']+)'\)",
334 broadcast_page, 'broadcast ticket')
336 url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket
338 broadcast_password = self._downloader.params.get('videopassword', None)
339 if broadcast_password:
340 url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest()
342 broadcast_json_page = self._download_webpage(
343 url, broadcast_id, 'Downloading broadcast JSON')
346 broadcast_json = json.loads(broadcast_json_page)
348 protected_broadcast = broadcast_json['_pass_protected'] == 1
349 if protected_broadcast and not broadcast_password:
350 raise ExtractorError(
351 'This broadcast is protected by a password, use the --video-password option',
354 broadcast_offline = broadcast_json['is_play'] == 0
355 if broadcast_offline:
356 raise ExtractorError('Broadcast %s is offline' % broadcast_id, expected=True)
358 rtmp_url = broadcast_json['_server']
359 mobj = re.search(r'^rtmp://[^/]+/(?P<app>.+)/?$', rtmp_url)
361 raise ExtractorError('Unexpected broadcast rtmp URL')
363 broadcast_playpath = broadcast_json['_streamName']
364 broadcast_app = '%s/%s' % (mobj.group('app'), broadcast_json['_vidURL'])
365 broadcast_thumbnail = broadcast_json['_imgURL']
366 broadcast_title = self._live_title(broadcast_json['title'])
367 broadcast_description = broadcast_json['description']
368 broadcaster_nick = broadcast_json['nick']
369 broadcaster_login = broadcast_json['login']
370 rtmp_conn = 'S:%s' % uuid.uuid4().hex
372 if protected_broadcast:
373 raise ExtractorError('Bad broadcast password', expected=True)
374 raise ExtractorError('Unexpected broadcast JSON')
379 'title': broadcast_title,
380 'thumbnail': broadcast_thumbnail,
381 'description': broadcast_description,
382 'uploader': broadcaster_nick,
383 'uploader_id': broadcaster_login,
384 'age_limit': 18 if adult_content else 0,
386 'play_path': broadcast_playpath,
387 'player_url': 'http://pics.smotri.com/broadcast_play.swf',
388 'app': broadcast_app,
390 'rtmp_conn': rtmp_conn,