7 from .common import InfoExtractor
14 class SmotriIE(InfoExtractor):
15 IE_DESC = u'Smotri.com'
17 _VALID_URL = r'^(?:http://)?(?:www\.)?(?P<url>smotri\.com/video/view/\?id=(?P<videoid>v(?P<realvideoid>[0-9]+)[a-z0-9]{4}))'
20 # real video id 2610366
22 u'url': u'http://smotri.com/video/view/?id=v261036632ab',
23 u'file': u'v261036632ab.mp4',
24 u'md5': u'46a72e83a6ad8862b64fa6953fa93f8a',
26 u'title': u'катастрофа с камер видеонаблюдения',
27 u'uploader': u'rbc2008',
28 u'uploader_id': u'rbc08',
29 u'upload_date': u'20131118',
30 u'thumbnail': u'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg'
35 u'url': u'http://smotri.com/video/view/?id=v57591cb20',
36 u'file': u'v57591cb20.flv',
37 u'md5': u'9eae59f6dda7087bf39a140e2fff5757',
40 u'uploader': u'Support Photofile@photofile',
41 u'uploader_id': u'support-photofile',
42 u'upload_date': u'20070704',
43 u'thumbnail': u'http://frame4.loadup.ru/03/ed/57591.2.3.jpg'
48 u'url': u'http://smotri.com/video/view/?id=v1390466a13c',
49 u'file': u'v1390466a13c.mp4',
50 u'md5': u'fe4dd9357558d5ee3c8fc0ef0d39de66',
52 u'title': u'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
53 u'uploader': u'timoxa40',
54 u'uploader_id': u'timoxa40',
55 u'upload_date': u'20100404',
56 u'thumbnail': u'http://frame7.loadup.ru/af/3f/1390466.3.3.jpg'
59 u'videopassword': u'qwerty',
62 # age limit + video-password
64 u'url': u'http://smotri.com/video/view/?id=v15408898bcf',
65 u'file': u'v15408898bcf.flv',
66 u'md5': u'c66a5d61379ac6fde06f07eebe436316',
68 u'title': u'этот ролик не покажут по ТВ',
69 u'uploader': u'zzxxx',
70 u'uploader_id': u'ueggb',
71 u'upload_date': u'20101001',
72 u'thumbnail': u'http://frame3.loadup.ru/75/75/1540889.1.3.jpg',
76 u'videopassword': u'333'
82 _PASSWORD_NOT_VERIFIED = 1
83 _PASSWORD_DETECTED = 2
86 def _search_meta(self, name, html, display_name=None):
87 if display_name is None:
89 return self._html_search_regex(
90 r'<meta itemprop="%s" content="([^"]+)" />' % re.escape(name),
91 html, display_name, fatal=False)
93 def _real_extract(self, url):
94 mobj = re.match(self._VALID_URL, url)
95 video_id = mobj.group('videoid')
96 real_video_id = mobj.group('realvideoid')
98 # Download video JSON data
99 video_json_url = 'http://smotri.com/vt.php?id=%s' % real_video_id
100 video_json_page = self._download_webpage(video_json_url, video_id, u'Downloading video JSON')
101 video_json = json.loads(video_json_page)
103 status = video_json['status']
104 if status == self._VIDEO_NOT_FOUND:
105 raise ExtractorError(u'Video %s does not exist' % video_id, expected=True)
106 elif status == self._PASSWORD_DETECTED: # The video is protected by a password, retry with
108 video_password = self._downloader.params.get('videopassword', None)
109 if not video_password:
110 raise ExtractorError(u'This video is protected by a password, use the --video-password option', expected=True)
111 video_json_url += '&md5pass=%s' % hashlib.md5(video_password).hexdigest()
112 video_json_page = self._download_webpage(video_json_url, video_id, u'Downloading video JSON (video-password set)')
113 video_json = json.loads(video_json_page)
114 status = video_json['status']
115 if status == self._PASSWORD_NOT_VERIFIED:
116 raise ExtractorError(u'Video password is invalid', expected=True)
118 if status != self._SUCCESS:
119 raise ExtractorError(u'Unexpected status value %s' % status)
121 # Extract the URL of the video
122 video_url = video_json['file_data']
123 video_ext = determine_ext(video_url)
125 # Video JSON does not provide enough meta data
126 # We will extract some from the video web page instead
127 video_page_url = 'http://' + mobj.group('url')
128 video_page = self._download_webpage(video_page_url, video_id, u'Downloading video page')
131 if re.search(u'EroConfirmText">', video_page) is not None:
132 self.report_age_confirmation()
133 confirm_string = self._html_search_regex(
134 ur'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id,
135 video_page, u'confirm string')
136 confirm_url = video_page_url + '&confirm=%s' % confirm_string
137 video_page = self._download_webpage(confirm_url, video_id, u'Downloading video page (age confirmed)')
140 adult_content = False
142 # Extract the rest of meta data
143 video_title = self._search_meta(u'name', video_page, u'title')
145 video_title = video_url.rsplit('/', 1)[-1]
147 video_description = self._search_meta(u'description', video_page)
148 video_thumbnail = self._search_meta(u'thumbnail', video_page)
150 upload_date_str = self._search_meta(u'uploadDate', video_page, u'upload date')
151 upload_date_m = re.search(r'(?P<year>\d{4})\.(?P<month>\d{2})\.(?P<day>\d{2})T', upload_date_str)
152 video_upload_date = (
154 upload_date_m.group('year') +
155 upload_date_m.group('month') +
156 upload_date_m.group('day')
158 if upload_date_m else None
161 duration_str = self._search_meta(u'duration', video_page)
162 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)
165 (int(duration_m.group('hours')) * 60 * 60) +
166 (int(duration_m.group('minutes')) * 60) +
167 int(duration_m.group('seconds'))
169 if duration_m else None
172 video_uploader = self._html_search_regex(
173 ur'<div class="DescrUser"><div>Автор.*?onmouseover="popup_user_info[^"]+">(.*?)</a>',
174 video_page, u'uploader', fatal=False, flags=re.MULTILINE|re.DOTALL)
176 video_uploader_id = self._html_search_regex(
177 ur'<div class="DescrUser"><div>Автор.*?onmouseover="popup_user_info\(.*?\'([^\']+)\'\);">',
178 video_page, u'uploader id', fatal=False, flags=re.MULTILINE|re.DOTALL)
180 video_view_count = self._html_search_regex(
181 ur'Общее количество просмотров.*?<span class="Number">(\d+)</span>',
182 video_page, u'view count', fatal=False, flags=re.MULTILINE|re.DOTALL)
187 'title': video_title,
189 'thumbnail': video_thumbnail,
190 'description': video_description,
191 'uploader': video_uploader,
192 'upload_date': video_upload_date,
193 'uploader_id': video_uploader_id,
194 'video_duration': video_duration,
195 'view_count': video_view_count,
196 'age_limit': 18 if adult_content else 0,
197 'video_page_url': video_page_url
200 class SmotriCommunityIE(InfoExtractor):
201 IE_DESC = u'Smotri.com community videos'
202 IE_NAME = u'smotri:community'
203 _VALID_URL = r'^(?:http://)?(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)'
205 def _real_extract(self, url):
206 mobj = re.match(self._VALID_URL, url)
207 community_id = mobj.group('communityid')
209 url = 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id
210 rss = self._download_xml(url, community_id, u'Downloading community RSS')
212 entries = [self.url_result(video_url.text, 'Smotri')
213 for video_url in rss.findall('./channel/item/link')]
215 community_title = self._html_search_regex(
216 ur'^Видео сообщества "([^"]+)"$', rss.find('./channel/description').text, u'community title')
218 return self.playlist_result(entries, community_id, community_title)
220 class SmotriUserIE(InfoExtractor):
221 IE_DESC = u'Smotri.com user videos'
222 IE_NAME = u'smotri:user'
223 _VALID_URL = r'^(?:http://)?(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)'
225 def _real_extract(self, url):
226 mobj = re.match(self._VALID_URL, url);
227 user_id = mobj.group('userid')
229 url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id
230 rss = self._download_xml(url, user_id, u'Downloading user RSS')
232 entries = [self.url_result(video_url.text, 'Smotri')
233 for video_url in rss.findall('./channel/item/link')]
235 user_nickname = self._html_search_regex(
236 ur'^Видео режиссера (.*)$', rss.find('./channel/description').text, u'user nickname')
238 return self.playlist_result(entries, user_id, user_nickname)