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.

391 lines
15 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. # not approved by moderator, but available
  89. {
  90. 'url': 'http://smotri.com/video/view/?id=v28888533b73',
  91. 'md5': 'f44bc7adac90af518ef1ecf04893bb34',
  92. 'info_dict': {
  93. 'id': 'v28888533b73',
  94. 'ext': 'mp4',
  95. 'title': 'Russian Spies Killed By ISIL Child Soldier',
  96. 'uploader': 'Mopeder',
  97. 'uploader_id': 'mopeder',
  98. 'duration': 71,
  99. 'thumbnail': 'http://frame9.loadup.ru/d7/32/2888853.2.3.jpg',
  100. },
  101. },
  102. # swf player
  103. {
  104. 'url': 'http://pics.smotri.com/scrubber_custom8.swf?file=v9188090500',
  105. 'md5': '4d47034979d9390d14acdf59c4935bc2',
  106. 'info_dict': {
  107. 'id': 'v9188090500',
  108. 'ext': 'mp4',
  109. 'title': 'Shakira - Don\'t Bother',
  110. 'uploader': 'HannahL',
  111. 'uploader_id': 'lisaha95',
  112. 'upload_date': '20090331',
  113. 'thumbnail': 'http://frame8.loadup.ru/44/0b/918809.7.3.jpg',
  114. },
  115. },
  116. ]
  117. @classmethod
  118. def _extract_url(cls, webpage):
  119. mobj = re.search(
  120. r'<embed[^>]src=(["\'])(?P<url>http://pics\.smotri\.com/(?:player|scrubber_custom8)\.swf\?file=v.+?\1)',
  121. webpage)
  122. if mobj is not None:
  123. return mobj.group('url')
  124. mobj = re.search(
  125. r'''(?x)<div\s+class="video_file">http://smotri\.com/video/download/file/[^<]+</div>\s*
  126. <div\s+class="video_image">[^<]+</div>\s*
  127. <div\s+class="video_id">(?P<id>[^<]+)</div>''', webpage)
  128. if mobj is not None:
  129. return 'http://smotri.com/video/view/?id=%s' % mobj.group('id')
  130. def _search_meta(self, name, html, display_name=None):
  131. if display_name is None:
  132. display_name = name
  133. return self._html_search_regex(
  134. r'<meta itemprop="%s" content="([^"]+)" />' % re.escape(name),
  135. html, display_name, fatal=False)
  136. return self._html_search_meta(name, html, display_name)
  137. def _real_extract(self, url):
  138. video_id = self._match_id(url)
  139. video_form = {
  140. 'ticket': video_id,
  141. 'video_url': '1',
  142. 'frame_url': '1',
  143. 'devid': 'LoadupFlashPlayer',
  144. 'getvideoinfo': '1',
  145. }
  146. request = compat_urllib_request.Request(
  147. 'http://smotri.com/video/view/url/bot/', compat_urllib_parse.urlencode(video_form))
  148. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  149. video = self._download_json(request, video_id, 'Downloading video JSON')
  150. video_url = video.get('_vidURL') or video.get('_vidURL_mp4')
  151. if not video_url:
  152. if video.get('_moderate_no') or not video.get('moderated'):
  153. raise ExtractorError(
  154. 'Video %s has not been approved by moderator' % video_id, expected=True)
  155. if video.get('error'):
  156. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  157. title = video['title']
  158. thumbnail = video['_imgURL']
  159. upload_date = unified_strdate(video['added'])
  160. uploader = video['userNick']
  161. uploader_id = video['userLogin']
  162. duration = int_or_none(video['duration'])
  163. # Video JSON does not provide enough meta data
  164. # We will extract some from the video web page instead
  165. webpage_url = 'http://smotri.com/video/view/?id=%s' % video_id
  166. webpage = self._download_webpage(webpage_url, video_id, 'Downloading video page')
  167. # Warning if video is unavailable
  168. warning = self._html_search_regex(
  169. r'<div class="videoUnModer">(.*?)</div>', webpage,
  170. 'warning message', default=None)
  171. if warning is not None:
  172. self._downloader.report_warning(
  173. 'Video %s may not be available; smotri said: %s ' %
  174. (video_id, warning))
  175. # Adult content
  176. if re.search('EroConfirmText">', webpage) is not None:
  177. self.report_age_confirmation()
  178. confirm_string = self._html_search_regex(
  179. r'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id,
  180. webpage, 'confirm string')
  181. confirm_url = webpage_url + '&confirm=%s' % confirm_string
  182. webpage = self._download_webpage(confirm_url, video_id, 'Downloading video page (age confirmed)')
  183. adult_content = True
  184. else:
  185. adult_content = False
  186. view_count = self._html_search_regex(
  187. 'Общее количество просмотров.*?<span class="Number">(\\d+)</span>',
  188. webpage, 'view count', fatal=False, flags=re.MULTILINE | re.DOTALL)
  189. return {
  190. 'id': video_id,
  191. 'url': video_url,
  192. 'title': title,
  193. 'thumbnail': thumbnail,
  194. 'uploader': uploader,
  195. 'upload_date': upload_date,
  196. 'uploader_id': uploader_id,
  197. 'duration': duration,
  198. 'view_count': int_or_none(view_count),
  199. 'age_limit': 18 if adult_content else 0,
  200. }
  201. class SmotriCommunityIE(InfoExtractor):
  202. IE_DESC = 'Smotri.com community videos'
  203. IE_NAME = 'smotri:community'
  204. _VALID_URL = r'^https?://(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)'
  205. _TEST = {
  206. 'url': 'http://smotri.com/community/video/kommuna',
  207. 'info_dict': {
  208. 'id': 'kommuna',
  209. 'title': 'КПРФ',
  210. },
  211. 'playlist_mincount': 4,
  212. }
  213. def _real_extract(self, url):
  214. mobj = re.match(self._VALID_URL, url)
  215. community_id = mobj.group('communityid')
  216. url = 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id
  217. rss = self._download_xml(url, community_id, 'Downloading community RSS')
  218. entries = [self.url_result(video_url.text, 'Smotri')
  219. for video_url in rss.findall('./channel/item/link')]
  220. description_text = rss.find('./channel/description').text
  221. community_title = self._html_search_regex(
  222. '^Видео сообщества "([^"]+)"$', description_text, 'community title')
  223. return self.playlist_result(entries, community_id, community_title)
  224. class SmotriUserIE(InfoExtractor):
  225. IE_DESC = 'Smotri.com user videos'
  226. IE_NAME = 'smotri:user'
  227. _VALID_URL = r'^https?://(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)'
  228. _TESTS = [{
  229. 'url': 'http://smotri.com/user/inspector',
  230. 'info_dict': {
  231. 'id': 'inspector',
  232. 'title': 'Inspector',
  233. },
  234. 'playlist_mincount': 9,
  235. }]
  236. def _real_extract(self, url):
  237. mobj = re.match(self._VALID_URL, url)
  238. user_id = mobj.group('userid')
  239. url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id
  240. rss = self._download_xml(url, user_id, 'Downloading user RSS')
  241. entries = [self.url_result(video_url.text, 'Smotri')
  242. for video_url in rss.findall('./channel/item/link')]
  243. description_text = rss.find('./channel/description').text
  244. user_nickname = self._html_search_regex(
  245. '^Видео режиссера (.*)$', description_text,
  246. 'user nickname')
  247. return self.playlist_result(entries, user_id, user_nickname)
  248. class SmotriBroadcastIE(InfoExtractor):
  249. IE_DESC = 'Smotri.com broadcasts'
  250. IE_NAME = 'smotri:broadcast'
  251. _VALID_URL = r'^https?://(?:www\.)?(?P<url>smotri\.com/live/(?P<broadcastid>[^/]+))/?.*'
  252. def _real_extract(self, url):
  253. mobj = re.match(self._VALID_URL, url)
  254. broadcast_id = mobj.group('broadcastid')
  255. broadcast_url = 'http://' + mobj.group('url')
  256. broadcast_page = self._download_webpage(broadcast_url, broadcast_id, 'Downloading broadcast page')
  257. if re.search('>Режиссер с логином <br/>"%s"<br/> <span>не существует<' % broadcast_id, broadcast_page) is not None:
  258. raise ExtractorError(
  259. 'Broadcast %s does not exist' % broadcast_id, expected=True)
  260. # Adult content
  261. if re.search('EroConfirmText">', broadcast_page) is not None:
  262. (username, password) = self._get_login_info()
  263. if username is None:
  264. raise ExtractorError(
  265. 'Erotic broadcasts allowed only for registered users, '
  266. 'use --username and --password options to provide account credentials.',
  267. expected=True)
  268. login_form = {
  269. 'login-hint53': '1',
  270. 'confirm_erotic': '1',
  271. 'login': username,
  272. 'password': password,
  273. }
  274. request = compat_urllib_request.Request(
  275. broadcast_url + '/?no_redirect=1', compat_urllib_parse.urlencode(login_form))
  276. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  277. broadcast_page = self._download_webpage(
  278. request, broadcast_id, 'Logging in and confirming age')
  279. if re.search('>Неверный логин или пароль<', broadcast_page) is not None:
  280. raise ExtractorError('Unable to log in: bad username or password', expected=True)
  281. adult_content = True
  282. else:
  283. adult_content = False
  284. ticket = self._html_search_regex(
  285. r"window\.broadcast_control\.addFlashVar\('file'\s*,\s*'([^']+)'\)",
  286. broadcast_page, 'broadcast ticket')
  287. url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket
  288. broadcast_password = self._downloader.params.get('videopassword', None)
  289. if broadcast_password:
  290. url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest()
  291. broadcast_json_page = self._download_webpage(
  292. url, broadcast_id, 'Downloading broadcast JSON')
  293. try:
  294. broadcast_json = json.loads(broadcast_json_page)
  295. protected_broadcast = broadcast_json['_pass_protected'] == 1
  296. if protected_broadcast and not broadcast_password:
  297. raise ExtractorError(
  298. 'This broadcast is protected by a password, use the --video-password option',
  299. expected=True)
  300. broadcast_offline = broadcast_json['is_play'] == 0
  301. if broadcast_offline:
  302. raise ExtractorError('Broadcast %s is offline' % broadcast_id, expected=True)
  303. rtmp_url = broadcast_json['_server']
  304. mobj = re.search(r'^rtmp://[^/]+/(?P<app>.+)/?$', rtmp_url)
  305. if not mobj:
  306. raise ExtractorError('Unexpected broadcast rtmp URL')
  307. broadcast_playpath = broadcast_json['_streamName']
  308. broadcast_app = '%s/%s' % (mobj.group('app'), broadcast_json['_vidURL'])
  309. broadcast_thumbnail = broadcast_json['_imgURL']
  310. broadcast_title = self._live_title(broadcast_json['title'])
  311. broadcast_description = broadcast_json['description']
  312. broadcaster_nick = broadcast_json['nick']
  313. broadcaster_login = broadcast_json['login']
  314. rtmp_conn = 'S:%s' % uuid.uuid4().hex
  315. except KeyError:
  316. if protected_broadcast:
  317. raise ExtractorError('Bad broadcast password', expected=True)
  318. raise ExtractorError('Unexpected broadcast JSON')
  319. return {
  320. 'id': broadcast_id,
  321. 'url': rtmp_url,
  322. 'title': broadcast_title,
  323. 'thumbnail': broadcast_thumbnail,
  324. 'description': broadcast_description,
  325. 'uploader': broadcaster_nick,
  326. 'uploader_id': broadcaster_login,
  327. 'age_limit': 18 if adult_content else 0,
  328. 'ext': 'flv',
  329. 'play_path': broadcast_playpath,
  330. 'player_url': 'http://pics.smotri.com/broadcast_play.swf',
  331. 'app': broadcast_app,
  332. 'rtmp_live': True,
  333. 'rtmp_conn': rtmp_conn,
  334. 'is_live': True,
  335. }