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