8 from .common
import InfoExtractor
11 compat_urllib_request
,
16 class SmotriIE(InfoExtractor
):
17 IE_DESC
= u
'Smotri.com'
19 _VALID_URL
= r
'^https?://(?:www\.)?(?P<url>smotri\.com/video/view/\?id=(?P<videoid>v(?P<realvideoid>[0-9]+)[a-z0-9]{4}))'
22 # real video id 2610366
24 u
'url': u
'http://smotri.com/video/view/?id=v261036632ab',
25 u
'file': u
'v261036632ab.mp4',
26 u
'md5': u
'2a7b08249e6f5636557579c368040eb9',
28 u
'title': u
'катастрофа с камер видеонаблюдения',
29 u
'uploader': u
'rbc2008',
30 u
'uploader_id': u
'rbc08',
31 u
'upload_date': u
'20131118',
32 u
'description': u
'катастрофа с камер видеонаблюдения, видео катастрофа с камер видеонаблюдения',
33 u
'thumbnail': u
'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg',
38 u
'url': u
'http://smotri.com/video/view/?id=v57591cb20',
39 u
'file': u
'v57591cb20.flv',
40 u
'md5': u
'830266dfc21f077eac5afd1883091bcd',
43 u
'uploader': u
'Support Photofile@photofile',
44 u
'uploader_id': u
'support-photofile',
45 u
'upload_date': u
'20070704',
46 u
'description': u
'test, видео test',
47 u
'thumbnail': u
'http://frame4.loadup.ru/03/ed/57591.2.3.jpg',
52 u
'url': u
'http://smotri.com/video/view/?id=v1390466a13c',
53 u
'file': u
'v1390466a13c.mp4',
54 u
'md5': u
'f6331cef33cad65a0815ee482a54440b',
56 u
'title': u
'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
57 u
'uploader': u
'timoxa40',
58 u
'uploader_id': u
'timoxa40',
59 u
'upload_date': u
'20100404',
60 u
'thumbnail': u
'http://frame7.loadup.ru/af/3f/1390466.3.3.jpg',
61 u
'description': u
'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1, видео TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
64 u
'videopassword': u
'qwerty',
67 # age limit + video-password
69 u
'url': u
'http://smotri.com/video/view/?id=v15408898bcf',
70 u
'file': u
'v15408898bcf.flv',
71 u
'md5': u
'91e909c9f0521adf5ee86fbe073aad70',
73 u
'title': u
'этот ролик не покажут по ТВ',
74 u
'uploader': u
'zzxxx',
75 u
'uploader_id': u
'ueggb',
76 u
'upload_date': u
'20101001',
77 u
'thumbnail': u
'http://frame3.loadup.ru/75/75/1540889.1.3.jpg',
79 u
'description': u
'этот ролик не покажут по ТВ, видео этот ролик не покажут по ТВ',
82 u
'videopassword': u
'333'
88 _PASSWORD_NOT_VERIFIED
= 1
89 _PASSWORD_DETECTED
= 2
92 def _search_meta(self
, name
, html
, display_name
=None):
93 if display_name
is None:
95 return self
._html
_search
_regex
(
96 r
'<meta itemprop="%s" content="([^"]+)" />' % re
.escape(name
),
97 html
, display_name
, fatal
=False)
98 return self
._html
_search
_meta
(name
, html
, display_name
)
100 def _real_extract(self
, url
):
101 mobj
= re
.match(self
._VALID
_URL
, url
)
102 video_id
= mobj
.group('videoid')
103 real_video_id
= mobj
.group('realvideoid')
105 # Download video JSON data
106 video_json_url
= 'http://smotri.com/vt.php?id=%s' % real_video_id
107 video_json_page
= self
._download
_webpage
(video_json_url
, video_id
, u
'Downloading video JSON')
108 video_json
= json
.loads(video_json_page
)
110 status
= video_json
['status']
111 if status
== self
._VIDEO
_NOT
_FOUND
:
112 raise ExtractorError(u
'Video %s does not exist' % video_id
, expected
=True)
113 elif status
== self
._PASSWORD
_DETECTED
: # The video is protected by a password, retry with
115 video_password
= self
._downloader
.params
.get('videopassword', None)
116 if not video_password
:
117 raise ExtractorError(u
'This video is protected by a password, use the --video-password option', expected
=True)
118 video_json_url
+= '&md5pass=%s' % hashlib
.md5(video_password
.encode('utf-8')).hexdigest()
119 video_json_page
= self
._download
_webpage
(video_json_url
, video_id
, u
'Downloading video JSON (video-password set)')
120 video_json
= json
.loads(video_json_page
)
121 status
= video_json
['status']
122 if status
== self
._PASSWORD
_NOT
_VERIFIED
:
123 raise ExtractorError(u
'Video password is invalid', expected
=True)
125 if status
!= self
._SUCCESS
:
126 raise ExtractorError(u
'Unexpected status value %s' % status
)
128 # Extract the URL of the video
129 video_url
= video_json
['file_data']
131 # Video JSON does not provide enough meta data
132 # We will extract some from the video web page instead
133 video_page_url
= 'http://' + mobj
.group('url')
134 video_page
= self
._download
_webpage
(video_page_url
, video_id
, u
'Downloading video page')
137 if re
.search(u
'EroConfirmText">', video_page
) is not None:
138 self
.report_age_confirmation()
139 confirm_string
= self
._html
_search
_regex
(
140 r
'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id
,
141 video_page
, u
'confirm string')
142 confirm_url
= video_page_url
+ '&confirm=%s' % confirm_string
143 video_page
= self
._download
_webpage
(confirm_url
, video_id
, u
'Downloading video page (age confirmed)')
146 adult_content
= False
148 # Extract the rest of meta data
149 video_title
= self
._search
_meta
(u
'name', video_page
, u
'title')
151 video_title
= video_url
.rsplit('/', 1)[-1]
153 video_description
= self
._search
_meta
(u
'description', video_page
)
154 END_TEXT
= u
' на сайте Smotri.com'
155 if video_description
.endswith(END_TEXT
):
156 video_description
= video_description
[:-len(END_TEXT
)]
157 START_TEXT
= u
'Смотреть онлайн ролик '
158 if video_description
.startswith(START_TEXT
):
159 video_description
= video_description
[len(START_TEXT
):]
160 video_thumbnail
= self
._search
_meta
(u
'thumbnail', video_page
)
162 upload_date_str
= self
._search
_meta
(u
'uploadDate', video_page
, u
'upload date')
163 upload_date_m
= re
.search(r
'(?P<year>\d{4})\.(?P<month>\d{2})\.(?P<day>\d{2})T', upload_date_str
)
164 video_upload_date
= (
166 upload_date_m
.group('year') +
167 upload_date_m
.group('month') +
168 upload_date_m
.group('day')
170 if upload_date_m
else None
173 duration_str
= self
._search
_meta
(u
'duration', video_page
)
174 duration_m
= re
.search(r
'T(?P<hours>[0-9]{2})H(?P<minutes>[0-9]{2})M(?P<seconds>[0-9]{2})S', duration_str
)
177 (int(duration_m
.group('hours')) * 60 * 60) +
178 (int(duration_m
.group('minutes')) * 60) +
179 int(duration_m
.group('seconds'))
181 if duration_m
else None
184 video_uploader
= self
._html
_search
_regex
(
185 u
'<div class="DescrUser"><div>Автор.*?onmouseover="popup_user_info[^"]+">(.*?)</a>',
186 video_page
, u
'uploader', fatal
=False, flags
=re
.MULTILINE|re
.DOTALL
)
188 video_uploader_id
= self
._html
_search
_regex
(
189 u
'<div class="DescrUser"><div>Автор.*?onmouseover="popup_user_info\\(.*?\'([^\']+)\'\\);">',
190 video_page
, u
'uploader id', fatal
=False, flags
=re
.MULTILINE|re
.DOTALL
)
192 video_view_count
= self
._html
_search
_regex
(
193 u
'Общее количество просмотров.*?<span class="Number">(\\d+)</span>',
194 video_page
, u
'view count', fatal
=False, flags
=re
.MULTILINE|re
.DOTALL
)
199 'title': video_title
,
200 'thumbnail': video_thumbnail
,
201 'description': video_description
,
202 'uploader': video_uploader
,
203 'upload_date': video_upload_date
,
204 'uploader_id': video_uploader_id
,
205 'duration': video_duration
,
206 'view_count': video_view_count
,
207 'age_limit': 18 if adult_content
else 0,
208 'video_page_url': video_page_url
212 class SmotriCommunityIE(InfoExtractor
):
213 IE_DESC
= u
'Smotri.com community videos'
214 IE_NAME
= u
'smotri:community'
215 _VALID_URL
= r
'^https?://(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)'
217 def _real_extract(self, url):
218 mobj = re.match(self._VALID_URL, url)
219 community_id = mobj.group('communityid
')
221 url = 'http
://smotri
.com
/export
/rss
/video
/by
/community
/-/%s/video
.xml
' % community_id
222 rss = self._download_xml(url, community_id, u'Downloading community RSS
')
224 entries = [self.url_result(video_url.text, 'Smotri
')
225 for video_url in rss.findall('./channel
/item
/link
')]
227 description_text = rss.find('./channel
/description
').text
228 community_title = self._html_search_regex(
229 u'^Видео сообщества
"([^"]+)"$', description_text, u'community title')
231 return self.playlist_result(entries, community_id, community_title)
234 class SmotriUserIE(InfoExtractor):
235 IE_DESC = u'Smotri.com user videos'
236 IE_NAME = u'smotri:user'
237 _VALID_URL = r'^https?://(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)'
239 def _real_extract(self, url):
240 mobj = re.match(self._VALID_URL, url)
241 user_id = mobj.group('userid')
243 url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id
244 rss = self._download_xml(url, user_id, u'Downloading user RSS')
246 entries = [self.url_result(video_url.text, 'Smotri')
247 for video_url in rss.findall('./channel/item/link')]
249 description_text = rss.find('./channel/description').text
250 user_nickname = self._html_search_regex(
251 u'^Видео режиссера (.*)$', description_text,
254 return self.playlist_result(entries, user_id, user_nickname)
257 class SmotriBroadcastIE(InfoExtractor):
258 IE_DESC = u'Smotri.com broadcasts'
259 IE_NAME = u'smotri:broadcast'
260 _VALID_URL = r'^https?://(?:www\.)?(?P<url>smotri\.com/live/(?P<broadcastid>[^/]+))/?.*'
262 def _real_extract(self, url):
263 mobj = re.match(self._VALID_URL, url)
264 broadcast_id = mobj.group('broadcastid')
266 broadcast_url = 'http://' + mobj.group('url')
267 broadcast_page = self._download_webpage(broadcast_url, broadcast_id, u'Downloading broadcast page')
269 if re.search(u'>Режиссер с логином <br/>"%s"<br/> <span>не существует<' % broadcast_id, broadcast_page) is not None:
270 raise ExtractorError(u'Broadcast %s does not exist' % broadcast_id, expected=True)
273 if re.search(u'EroConfirmText">', broadcast_page) is not None:
275 (username, password) = self._get_login_info()
277 raise ExtractorError(u'Erotic broadcasts allowed only
for registered users
, '
278 u'use
--username
and --password options to provide account credentials
.', expected=True)
282 u'login
-hint53
': '1',
283 u'confirm_erotic
': '1',
285 u'password
': password,
287 # Convert to UTF-8 *before* urlencode because Python 2.x's urlencode
289 login_form
= dict((k
.encode('utf-8'), v
.encode('utf-8')) for k
,v
in login_form_strs
.items())
290 login_data
= compat_urllib_parse
.urlencode(login_form
).encode('utf-8')
291 login_url
= broadcast_url
+ '/?no_redirect=1'
292 request
= compat_urllib_request
.Request(login_url
, login_data
)
293 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
294 broadcast_page
= self
._download
_webpage
(
295 request
, broadcast_id
, note
=u
'Logging in and confirming age')
297 if re
.search(u
'>Неверный логин или пароль<', broadcast_page
) is not None:
298 raise ExtractorError(u
'Unable to log in: bad username or password', expected
=True)
302 adult_content
= False
304 ticket
= self
._html
_search
_regex
(
305 u
'window\.broadcast_control\.addFlashVar\\(\'file\', \'([^\']+)\'\\);',
306 broadcast_page
, u
'broadcast ticket')
308 url
= 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket
310 broadcast_password
= self
._downloader
.params
.get('videopassword', None)
311 if broadcast_password
:
312 url
+= '&pass=%s' % hashlib
.md5(broadcast_password
.encode('utf-8')).hexdigest()
314 broadcast_json_page
= self
._download
_webpage
(url
, broadcast_id
, u
'Downloading broadcast JSON')
317 broadcast_json
= json
.loads(broadcast_json_page
)
319 protected_broadcast
= broadcast_json
['_pass_protected'] == 1
320 if protected_broadcast
and not broadcast_password
:
321 raise ExtractorError(u
'This broadcast is protected by a password, use the --video-password option', expected
=True)
323 broadcast_offline
= broadcast_json
['is_play'] == 0
324 if broadcast_offline
:
325 raise ExtractorError(u
'Broadcast %s is offline' % broadcast_id
, expected
=True)
327 rtmp_url
= broadcast_json
['_server']
328 if not rtmp_url
.startswith('rtmp://'):
329 raise ExtractorError(u
'Unexpected broadcast rtmp URL')
331 broadcast_playpath
= broadcast_json
['_streamName']
332 broadcast_thumbnail
= broadcast_json
['_imgURL']
333 broadcast_title
= broadcast_json
['title']
334 broadcast_description
= broadcast_json
['description']
335 broadcaster_nick
= broadcast_json
['nick']
336 broadcaster_login
= broadcast_json
['login']
337 rtmp_conn
= 'S:%s' % uuid
.uuid4().hex
339 if protected_broadcast
:
340 raise ExtractorError(u
'Bad broadcast password', expected
=True)
341 raise ExtractorError(u
'Unexpected broadcast JSON')
346 'title': broadcast_title
,
347 'thumbnail': broadcast_thumbnail
,
348 'description': broadcast_description
,
349 'uploader': broadcaster_nick
,
350 'uploader_id': broadcaster_login
,
351 'age_limit': 18 if adult_content
else 0,
353 'play_path': broadcast_playpath
,
355 'rtmp_conn': rtmp_conn