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': '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': '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>[^
/]+))/?
.*'
314 def _real_extract(self, url):
315 mobj = re.match(self._VALID_URL, url)
316 broadcast_id = mobj.group('id')
318 broadcast_url = 'http
://' + mobj.group('url
')
319 broadcast_page = self._download_webpage(broadcast_url, broadcast_id, 'Downloading broadcast page
')
321 if re.search('>Режиссер с логином
<br
/>"%s"<br
/> <span
>не существует
<' % broadcast_id, broadcast_page) is not None:
322 raise ExtractorError(
323 'Broadcast
%s does
not exist
' % broadcast_id, expected=True)
326 if re.search('EroConfirmText
">', broadcast_page) is not None:
328 (username, password) = self._get_login_info()
330 self.raise_login_required(
331 'Erotic broadcasts allowed only for registered users')
335 'confirm_erotic': '1',
337 'password': password,
340 request = sanitized_Request(
341 broadcast_url + '/?no_redirect=1', urlencode_postdata(login_form))
342 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
343 broadcast_page = self._download_webpage(
344 request, broadcast_id, 'Logging in and confirming age')
346 if '>Неверный логин или пароль<' in broadcast_page:
347 raise ExtractorError(
348 'Unable to log in: bad username or password', expected=True)
352 adult_content = False
354 ticket = self._html_search_regex(
355 r"window\
.broadcast_control\
.addFlashVar\
('file'\s
*,\s
*'([^']+)'\)",
356 broadcast_page, 'broadcast ticket
')
358 url = 'http
://smotri
.com
/broadcast
/view
/url
/?ticket
=%s' % ticket
360 broadcast_password = self._downloader.params.get('videopassword
')
361 if broadcast_password:
362 url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf
-8')).hexdigest()
364 broadcast_json_page = self._download_webpage(
365 url, broadcast_id, 'Downloading broadcast JSON
')
368 broadcast_json = json.loads(broadcast_json_page)
370 protected_broadcast = broadcast_json['_pass_protected
'] == 1
371 if protected_broadcast and not broadcast_password:
372 raise ExtractorError(
373 'This broadcast
is protected by a password
, use the
--video
-password option
',
376 broadcast_offline = broadcast_json['is_play
'] == 0
377 if broadcast_offline:
378 raise ExtractorError('Broadcast
%s is offline
' % broadcast_id, expected=True)
380 rtmp_url = broadcast_json['_server
']
381 mobj = re.search(r'^rtmp
://[^
/]+/(?P
<app
>.+)/?$
', rtmp_url)
383 raise ExtractorError('Unexpected broadcast rtmp URL
')
385 broadcast_playpath = broadcast_json['_streamName
']
386 broadcast_app = '%s/%s' % (mobj.group('app
'), broadcast_json['_vidURL
'])
387 broadcast_thumbnail = broadcast_json.get('_imgURL
')
388 broadcast_title = self._live_title(broadcast_json['title
'])
389 broadcast_description = broadcast_json.get('description
')
390 broadcaster_nick = broadcast_json.get('nick
')
391 broadcaster_login = broadcast_json.get('login
')
392 rtmp_conn = 'S
:%s' % uuid.uuid4().hex
394 if protected_broadcast:
395 raise ExtractorError('Bad broadcast password
', expected=True)
396 raise ExtractorError('Unexpected broadcast JSON
')
401 'title
': broadcast_title,
402 'thumbnail
': broadcast_thumbnail,
403 'description
': broadcast_description,
404 'uploader
': broadcaster_nick,
405 'uploader_id
': broadcaster_login,
406 'age_limit
': 18 if adult_content else 0,
408 'play_path
': broadcast_playpath,
409 'player_url
': 'http
://pics
.smotri
.com
/broadcast_play
.swf
',
410 'app
': broadcast_app,
412 'rtmp_conn
': rtmp_conn,