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.

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