smotri.py 16 KB

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