You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

357 lines
14 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. import hashlib
  6. import uuid
  7. from .common import InfoExtractor
  8. from ..utils import (
  9. compat_urllib_parse,
  10. compat_urllib_request,
  11. ExtractorError,
  12. int_or_none,
  13. unified_strdate,
  14. )
  15. class SmotriIE(InfoExtractor):
  16. IE_DESC = 'Smotri.com'
  17. IE_NAME = 'smotri'
  18. _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})'
  19. _NETRC_MACHINE = 'smotri'
  20. _TESTS = [
  21. # real video id 2610366
  22. {
  23. 'url': 'http://smotri.com/video/view/?id=v261036632ab',
  24. 'md5': '2a7b08249e6f5636557579c368040eb9',
  25. 'info_dict': {
  26. 'id': 'v261036632ab',
  27. 'ext': 'mp4',
  28. 'title': 'катастрофа с камер видеонаблюдения',
  29. 'uploader': 'rbc2008',
  30. 'uploader_id': 'rbc08',
  31. 'upload_date': '20131118',
  32. 'thumbnail': 'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg',
  33. },
  34. },
  35. # real video id 57591
  36. {
  37. 'url': 'http://smotri.com/video/view/?id=v57591cb20',
  38. 'md5': '830266dfc21f077eac5afd1883091bcd',
  39. 'info_dict': {
  40. 'id': 'v57591cb20',
  41. 'ext': 'flv',
  42. 'title': 'test',
  43. 'uploader': 'Support Photofile@photofile',
  44. 'uploader_id': 'support-photofile',
  45. 'upload_date': '20070704',
  46. 'thumbnail': 'http://frame4.loadup.ru/03/ed/57591.2.3.jpg',
  47. },
  48. },
  49. # video-password
  50. {
  51. 'url': 'http://smotri.com/video/view/?id=v1390466a13c',
  52. 'md5': 'f6331cef33cad65a0815ee482a54440b',
  53. 'info_dict': {
  54. 'id': 'v1390466a13c',
  55. 'ext': 'mp4',
  56. 'title': 'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
  57. 'uploader': 'timoxa40',
  58. 'uploader_id': 'timoxa40',
  59. 'upload_date': '20100404',
  60. 'thumbnail': 'http://frame7.loadup.ru/af/3f/1390466.3.3.jpg',
  61. },
  62. 'params': {
  63. 'videopassword': 'qwerty',
  64. },
  65. },
  66. # age limit + video-password
  67. {
  68. 'url': 'http://smotri.com/video/view/?id=v15408898bcf',
  69. 'md5': '91e909c9f0521adf5ee86fbe073aad70',
  70. 'info_dict': {
  71. 'id': 'v15408898bcf',
  72. 'ext': 'flv',
  73. 'title': 'этот ролик не покажут по ТВ',
  74. 'uploader': 'zzxxx',
  75. 'uploader_id': 'ueggb',
  76. 'upload_date': '20101001',
  77. 'thumbnail': 'http://frame3.loadup.ru/75/75/1540889.1.3.jpg',
  78. 'age_limit': 18,
  79. },
  80. 'params': {
  81. 'videopassword': '333'
  82. }
  83. },
  84. # swf player
  85. {
  86. 'url': 'http://pics.smotri.com/scrubber_custom8.swf?file=v9188090500',
  87. 'md5': '4d47034979d9390d14acdf59c4935bc2',
  88. 'info_dict': {
  89. 'id': 'v9188090500',
  90. 'ext': 'mp4',
  91. 'title': 'Shakira - Don\'t Bother',
  92. 'uploader': 'HannahL',
  93. 'uploader_id': 'lisaha95',
  94. 'upload_date': '20090331',
  95. 'thumbnail': 'http://frame8.loadup.ru/44/0b/918809.7.3.jpg',
  96. },
  97. },
  98. ]
  99. @classmethod
  100. def _extract_url(cls, webpage):
  101. mobj = re.search(
  102. r'<embed[^>]src=(["\'])(?P<url>http://pics\.smotri\.com/(?:player|scrubber_custom8)\.swf\?file=v.+?\1)',
  103. webpage)
  104. if mobj is not None:
  105. return mobj.group('url')
  106. mobj = re.search(
  107. r'''(?x)<div\s+class="video_file">http://smotri\.com/video/download/file/[^<]+</div>\s*
  108. <div\s+class="video_image">[^<]+</div>\s*
  109. <div\s+class="video_id">(?P<id>[^<]+)</div>''', webpage)
  110. if mobj is not None:
  111. return 'http://smotri.com/video/view/?id=%s' % mobj.group('id')
  112. def _search_meta(self, name, html, display_name=None):
  113. if display_name is None:
  114. display_name = name
  115. return self._html_search_regex(
  116. r'<meta itemprop="%s" content="([^"]+)" />' % re.escape(name),
  117. html, display_name, fatal=False)
  118. return self._html_search_meta(name, html, display_name)
  119. def _real_extract(self, url):
  120. video_id = self._match_id(url)
  121. video_form = {
  122. 'ticket': video_id,
  123. 'video_url': '1',
  124. 'frame_url': '1',
  125. 'devid': 'LoadupFlashPlayer',
  126. 'getvideoinfo': '1',
  127. }
  128. request = compat_urllib_request.Request(
  129. 'http://smotri.com/video/view/url/bot/', compat_urllib_parse.urlencode(video_form))
  130. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  131. video = self._download_json(request, video_id, 'Downloading video JSON')
  132. if video.get('_moderate_no') or not video.get('moderated'):
  133. raise ExtractorError('Video %s has not been approved by moderator' % video_id, expected=True)
  134. if video.get('error'):
  135. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  136. video_url = video.get('_vidURL') or video.get('_vidURL_mp4')
  137. title = video['title']
  138. thumbnail = video['_imgURL']
  139. upload_date = unified_strdate(video['added'])
  140. uploader = video['userNick']
  141. uploader_id = video['userLogin']
  142. duration = int_or_none(video['duration'])
  143. # Video JSON does not provide enough meta data
  144. # We will extract some from the video web page instead
  145. webpage_url = 'http://smotri.com/video/view/?id=%s' % video_id
  146. webpage = self._download_webpage(webpage_url, video_id, 'Downloading video page')
  147. # Warning if video is unavailable
  148. warning = self._html_search_regex(
  149. r'<div class="videoUnModer">(.*?)</div>', webpage,
  150. 'warning message', default=None)
  151. if warning is not None:
  152. self._downloader.report_warning(
  153. 'Video %s may not be available; smotri said: %s ' %
  154. (video_id, warning))
  155. # Adult content
  156. if re.search('EroConfirmText">', webpage) is not None:
  157. self.report_age_confirmation()
  158. confirm_string = self._html_search_regex(
  159. r'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id,
  160. webpage, 'confirm string')
  161. confirm_url = webpage_url + '&confirm=%s' % confirm_string
  162. webpage = self._download_webpage(confirm_url, video_id, 'Downloading video page (age confirmed)')
  163. adult_content = True
  164. else:
  165. adult_content = False
  166. view_count = self._html_search_regex(
  167. 'Общее количество просмотров.*?<span class="Number">(\\d+)</span>',
  168. webpage, 'view count', fatal=False, flags=re.MULTILINE | re.DOTALL)
  169. return {
  170. 'id': video_id,
  171. 'url': video_url,
  172. 'title': title,
  173. 'thumbnail': thumbnail,
  174. 'uploader': uploader,
  175. 'upload_date': upload_date,
  176. 'uploader_id': uploader_id,
  177. 'duration': duration,
  178. 'view_count': int_or_none(view_count),
  179. 'age_limit': 18 if adult_content else 0,
  180. }
  181. class SmotriCommunityIE(InfoExtractor):
  182. IE_DESC = 'Smotri.com community videos'
  183. IE_NAME = 'smotri:community'
  184. _VALID_URL = r'^https?://(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)'
  185. _TEST = {
  186. 'url': 'http://smotri.com/community/video/kommuna',
  187. 'info_dict': {
  188. 'id': 'kommuna',
  189. 'title': 'КПРФ',
  190. },
  191. 'playlist_mincount': 4,
  192. }
  193. def _real_extract(self, url):
  194. mobj = re.match(self._VALID_URL, url)
  195. community_id = mobj.group('communityid')
  196. url = 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id
  197. rss = self._download_xml(url, community_id, 'Downloading community RSS')
  198. entries = [self.url_result(video_url.text, 'Smotri')
  199. for video_url in rss.findall('./channel/item/link')]
  200. description_text = rss.find('./channel/description').text
  201. community_title = self._html_search_regex(
  202. '^Видео сообщества "([^"]+)"$', description_text, 'community title')
  203. return self.playlist_result(entries, community_id, community_title)
  204. class SmotriUserIE(InfoExtractor):
  205. IE_DESC = 'Smotri.com user videos'
  206. IE_NAME = 'smotri:user'
  207. _VALID_URL = r'^https?://(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)'
  208. _TESTS = [{
  209. 'url': 'http://smotri.com/user/inspector',
  210. 'info_dict': {
  211. 'id': 'inspector',
  212. 'title': 'Inspector',
  213. },
  214. 'playlist_mincount': 9,
  215. }]
  216. def _real_extract(self, url):
  217. mobj = re.match(self._VALID_URL, url)
  218. user_id = mobj.group('userid')
  219. url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id
  220. rss = self._download_xml(url, user_id, 'Downloading user RSS')
  221. entries = [self.url_result(video_url.text, 'Smotri')
  222. for video_url in rss.findall('./channel/item/link')]
  223. description_text = rss.find('./channel/description').text
  224. user_nickname = self._html_search_regex(
  225. '^Видео режиссера (.*)$', description_text,
  226. 'user nickname')
  227. return self.playlist_result(entries, user_id, user_nickname)
  228. class SmotriBroadcastIE(InfoExtractor):
  229. IE_DESC = 'Smotri.com broadcasts'
  230. IE_NAME = 'smotri:broadcast'
  231. _VALID_URL = r'^https?://(?:www\.)?(?P<url>smotri\.com/live/(?P<broadcastid>[^/]+))/?.*'
  232. def _real_extract(self, url):
  233. mobj = re.match(self._VALID_URL, url)
  234. broadcast_id = mobj.group('broadcastid')
  235. broadcast_url = 'http://' + mobj.group('url')
  236. broadcast_page = self._download_webpage(broadcast_url, broadcast_id, 'Downloading broadcast page')
  237. if re.search('>Режиссер с логином <br/>"%s"<br/> <span>не существует<' % broadcast_id, broadcast_page) is not None:
  238. raise ExtractorError('Broadcast %s does not exist' % broadcast_id, expected=True)
  239. # Adult content
  240. if re.search('EroConfirmText">', broadcast_page) is not None:
  241. (username, password) = self._get_login_info()
  242. if username is None:
  243. raise ExtractorError('Erotic broadcasts allowed only for registered users, '
  244. 'use --username and --password options to provide account credentials.', expected=True)
  245. login_form = {
  246. 'login-hint53': '1',
  247. 'confirm_erotic': '1',
  248. 'login': username,
  249. 'password': password,
  250. }
  251. request = compat_urllib_request.Request(broadcast_url + '/?no_redirect=1', compat_urllib_parse.urlencode(login_form))
  252. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  253. broadcast_page = self._download_webpage(request, broadcast_id, 'Logging in and confirming age')
  254. if re.search('>Неверный логин или пароль<', broadcast_page) is not None:
  255. raise ExtractorError('Unable to log in: bad username or password', expected=True)
  256. adult_content = True
  257. else:
  258. adult_content = False
  259. ticket = self._html_search_regex(
  260. 'window\.broadcast_control\.addFlashVar\\(\'file\', \'([^\']+)\'\\);',
  261. broadcast_page, 'broadcast ticket')
  262. url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket
  263. broadcast_password = self._downloader.params.get('videopassword', None)
  264. if broadcast_password:
  265. url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest()
  266. broadcast_json_page = self._download_webpage(url, broadcast_id, 'Downloading broadcast JSON')
  267. try:
  268. broadcast_json = json.loads(broadcast_json_page)
  269. protected_broadcast = broadcast_json['_pass_protected'] == 1
  270. if protected_broadcast and not broadcast_password:
  271. raise ExtractorError('This broadcast is protected by a password, use the --video-password option', expected=True)
  272. broadcast_offline = broadcast_json['is_play'] == 0
  273. if broadcast_offline:
  274. raise ExtractorError('Broadcast %s is offline' % broadcast_id, expected=True)
  275. rtmp_url = broadcast_json['_server']
  276. if not rtmp_url.startswith('rtmp://'):
  277. raise ExtractorError('Unexpected broadcast rtmp URL')
  278. broadcast_playpath = broadcast_json['_streamName']
  279. broadcast_thumbnail = broadcast_json['_imgURL']
  280. broadcast_title = broadcast_json['title']
  281. broadcast_description = broadcast_json['description']
  282. broadcaster_nick = broadcast_json['nick']
  283. broadcaster_login = broadcast_json['login']
  284. rtmp_conn = 'S:%s' % uuid.uuid4().hex
  285. except KeyError:
  286. if protected_broadcast:
  287. raise ExtractorError('Bad broadcast password', expected=True)
  288. raise ExtractorError('Unexpected broadcast JSON')
  289. return {
  290. 'id': broadcast_id,
  291. 'url': rtmp_url,
  292. 'title': broadcast_title,
  293. 'thumbnail': broadcast_thumbnail,
  294. 'description': broadcast_description,
  295. 'uploader': broadcaster_nick,
  296. 'uploader_id': broadcaster_login,
  297. 'age_limit': 18 if adult_content else 0,
  298. 'ext': 'flv',
  299. 'play_path': broadcast_playpath,
  300. 'rtmp_live': True,
  301. 'rtmp_conn': rtmp_conn
  302. }