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.

370 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(
  239. 'Broadcast %s does not exist' % broadcast_id, expected=True)
  240. # Adult content
  241. if re.search('EroConfirmText">', broadcast_page) is not None:
  242. (username, password) = self._get_login_info()
  243. if username is None:
  244. raise ExtractorError(
  245. 'Erotic broadcasts allowed only for registered users, '
  246. 'use --username and --password options to provide account credentials.',
  247. expected=True)
  248. login_form = {
  249. 'login-hint53': '1',
  250. 'confirm_erotic': '1',
  251. 'login': username,
  252. 'password': password,
  253. }
  254. request = compat_urllib_request.Request(
  255. broadcast_url + '/?no_redirect=1', compat_urllib_parse.urlencode(login_form))
  256. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  257. broadcast_page = self._download_webpage(
  258. request, broadcast_id, 'Logging in and confirming age')
  259. if re.search('>Неверный логин или пароль<', broadcast_page) is not None:
  260. raise ExtractorError('Unable to log in: bad username or password', expected=True)
  261. adult_content = True
  262. else:
  263. adult_content = False
  264. ticket = self._html_search_regex(
  265. r"window\.broadcast_control\.addFlashVar\('file'\s*,\s*'([^']+)'\)",
  266. broadcast_page, 'broadcast ticket')
  267. url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket
  268. broadcast_password = self._downloader.params.get('videopassword', None)
  269. if broadcast_password:
  270. url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest()
  271. broadcast_json_page = self._download_webpage(
  272. url, broadcast_id, 'Downloading broadcast JSON')
  273. try:
  274. broadcast_json = json.loads(broadcast_json_page)
  275. protected_broadcast = broadcast_json['_pass_protected'] == 1
  276. if protected_broadcast and not broadcast_password:
  277. raise ExtractorError(
  278. 'This broadcast is protected by a password, use the --video-password option',
  279. expected=True)
  280. broadcast_offline = broadcast_json['is_play'] == 0
  281. if broadcast_offline:
  282. raise ExtractorError('Broadcast %s is offline' % broadcast_id, expected=True)
  283. rtmp_url = broadcast_json['_server']
  284. mobj = re.search(r'^rtmp://[^/]+/(?P<app>.+)/?$', rtmp_url)
  285. if not mobj:
  286. raise ExtractorError('Unexpected broadcast rtmp URL')
  287. broadcast_playpath = broadcast_json['_streamName']
  288. broadcast_app = '%s/%s' % (mobj.group('app'), broadcast_json['_vidURL'])
  289. broadcast_thumbnail = broadcast_json['_imgURL']
  290. broadcast_title = self._live_title(broadcast_json['title'])
  291. broadcast_description = broadcast_json['description']
  292. broadcaster_nick = broadcast_json['nick']
  293. broadcaster_login = broadcast_json['login']
  294. rtmp_conn = 'S:%s' % uuid.uuid4().hex
  295. except KeyError:
  296. if protected_broadcast:
  297. raise ExtractorError('Bad broadcast password', expected=True)
  298. raise ExtractorError('Unexpected broadcast JSON')
  299. return {
  300. 'id': broadcast_id,
  301. 'url': rtmp_url,
  302. 'title': broadcast_title,
  303. 'thumbnail': broadcast_thumbnail,
  304. 'description': broadcast_description,
  305. 'uploader': broadcaster_nick,
  306. 'uploader_id': broadcaster_login,
  307. 'age_limit': 18 if adult_content else 0,
  308. 'ext': 'flv',
  309. 'play_path': broadcast_playpath,
  310. 'player_url': 'http://pics.smotri.com/broadcast_play.swf',
  311. 'app': broadcast_app,
  312. 'rtmp_live': True,
  313. 'rtmp_conn': rtmp_conn,
  314. 'is_live': True,
  315. }