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.

251 lines
11 KiB

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
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
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
11 years ago
11 years ago
11 years ago
  1. # encoding: utf-8
  2. import re
  3. import json
  4. import hashlib
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError
  8. )
  9. class SmotriIE(InfoExtractor):
  10. IE_DESC = u'Smotri.com'
  11. IE_NAME = u'smotri'
  12. _VALID_URL = r'^https?://(?:www\.)?(?P<url>smotri\.com/video/view/\?id=(?P<videoid>v(?P<realvideoid>[0-9]+)[a-z0-9]{4}))'
  13. _TESTS = [
  14. # real video id 2610366
  15. {
  16. u'url': u'http://smotri.com/video/view/?id=v261036632ab',
  17. u'file': u'v261036632ab.mp4',
  18. u'md5': u'2a7b08249e6f5636557579c368040eb9',
  19. u'info_dict': {
  20. u'title': u'катастрофа с камер видеонаблюдения',
  21. u'uploader': u'rbc2008',
  22. u'uploader_id': u'rbc08',
  23. u'upload_date': u'20131118',
  24. u'description': u'катастрофа с камер видеонаблюдения, видео катастрофа с камер видеонаблюдения',
  25. u'thumbnail': u'http://frame6.loadup.ru/8b/a9/2610366.3.3.jpg',
  26. },
  27. },
  28. # real video id 57591
  29. {
  30. u'url': u'http://smotri.com/video/view/?id=v57591cb20',
  31. u'file': u'v57591cb20.flv',
  32. u'md5': u'830266dfc21f077eac5afd1883091bcd',
  33. u'info_dict': {
  34. u'title': u'test',
  35. u'uploader': u'Support Photofile@photofile',
  36. u'uploader_id': u'support-photofile',
  37. u'upload_date': u'20070704',
  38. u'description': u'test, видео test',
  39. u'thumbnail': u'http://frame4.loadup.ru/03/ed/57591.2.3.jpg',
  40. },
  41. },
  42. # video-password
  43. {
  44. u'url': u'http://smotri.com/video/view/?id=v1390466a13c',
  45. u'file': u'v1390466a13c.mp4',
  46. u'md5': u'f6331cef33cad65a0815ee482a54440b',
  47. u'info_dict': {
  48. u'title': u'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
  49. u'uploader': u'timoxa40',
  50. u'uploader_id': u'timoxa40',
  51. u'upload_date': u'20100404',
  52. u'thumbnail': u'http://frame7.loadup.ru/af/3f/1390466.3.3.jpg',
  53. u'description': u'TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1, видео TOCCA_A_NOI_-_LE_COSE_NON_VANNO_CAMBIAMOLE_ORA-1',
  54. },
  55. u'params': {
  56. u'videopassword': u'qwerty',
  57. },
  58. },
  59. # age limit + video-password
  60. {
  61. u'url': u'http://smotri.com/video/view/?id=v15408898bcf',
  62. u'file': u'v15408898bcf.flv',
  63. u'md5': u'91e909c9f0521adf5ee86fbe073aad70',
  64. u'info_dict': {
  65. u'title': u'этот ролик не покажут по ТВ',
  66. u'uploader': u'zzxxx',
  67. u'uploader_id': u'ueggb',
  68. u'upload_date': u'20101001',
  69. u'thumbnail': u'http://frame3.loadup.ru/75/75/1540889.1.3.jpg',
  70. u'age_limit': 18,
  71. u'description': u'этот ролик не покажут по ТВ, видео этот ролик не покажут по ТВ',
  72. },
  73. u'params': {
  74. u'videopassword': u'333'
  75. }
  76. }
  77. ]
  78. _SUCCESS = 0
  79. _PASSWORD_NOT_VERIFIED = 1
  80. _PASSWORD_DETECTED = 2
  81. _VIDEO_NOT_FOUND = 3
  82. def _search_meta(self, name, html, display_name=None):
  83. if display_name is None:
  84. display_name = name
  85. return self._html_search_regex(
  86. r'<meta itemprop="%s" content="([^"]+)" />' % re.escape(name),
  87. html, display_name, fatal=False)
  88. return self._html_search_meta(name, html, display_name)
  89. def _real_extract(self, url):
  90. mobj = re.match(self._VALID_URL, url)
  91. video_id = mobj.group('videoid')
  92. real_video_id = mobj.group('realvideoid')
  93. # Download video JSON data
  94. video_json_url = 'http://smotri.com/vt.php?id=%s' % real_video_id
  95. video_json_page = self._download_webpage(video_json_url, video_id, u'Downloading video JSON')
  96. video_json = json.loads(video_json_page)
  97. status = video_json['status']
  98. if status == self._VIDEO_NOT_FOUND:
  99. raise ExtractorError(u'Video %s does not exist' % video_id, expected=True)
  100. elif status == self._PASSWORD_DETECTED: # The video is protected by a password, retry with
  101. # video-password set
  102. video_password = self._downloader.params.get('videopassword', None)
  103. if not video_password:
  104. raise ExtractorError(u'This video is protected by a password, use the --video-password option', expected=True)
  105. video_json_url += '&md5pass=%s' % hashlib.md5(video_password.encode('utf-8')).hexdigest()
  106. video_json_page = self._download_webpage(video_json_url, video_id, u'Downloading video JSON (video-password set)')
  107. video_json = json.loads(video_json_page)
  108. status = video_json['status']
  109. if status == self._PASSWORD_NOT_VERIFIED:
  110. raise ExtractorError(u'Video password is invalid', expected=True)
  111. if status != self._SUCCESS:
  112. raise ExtractorError(u'Unexpected status value %s' % status)
  113. # Extract the URL of the video
  114. video_url = video_json['file_data']
  115. # Video JSON does not provide enough meta data
  116. # We will extract some from the video web page instead
  117. video_page_url = 'http://' + mobj.group('url')
  118. video_page = self._download_webpage(video_page_url, video_id, u'Downloading video page')
  119. # Adult content
  120. if re.search(u'EroConfirmText">', video_page) is not None:
  121. self.report_age_confirmation()
  122. confirm_string = self._html_search_regex(
  123. r'<a href="/video/view/\?id=%s&confirm=([^"]+)" title="[^"]+">' % video_id,
  124. video_page, u'confirm string')
  125. confirm_url = video_page_url + '&confirm=%s' % confirm_string
  126. video_page = self._download_webpage(confirm_url, video_id, u'Downloading video page (age confirmed)')
  127. adult_content = True
  128. else:
  129. adult_content = False
  130. # Extract the rest of meta data
  131. video_title = self._search_meta(u'name', video_page, u'title')
  132. if not video_title:
  133. video_title = video_url.rsplit('/', 1)[-1]
  134. video_description = self._search_meta(u'description', video_page)
  135. END_TEXT = u' на сайте Smotri.com'
  136. if video_description.endswith(END_TEXT):
  137. video_description = video_description[:-len(END_TEXT)]
  138. START_TEXT = u'Смотреть онлайн ролик '
  139. if video_description.startswith(START_TEXT):
  140. video_description = video_description[len(START_TEXT):]
  141. video_thumbnail = self._search_meta(u'thumbnail', video_page)
  142. upload_date_str = self._search_meta(u'uploadDate', video_page, u'upload date')
  143. upload_date_m = re.search(r'(?P<year>\d{4})\.(?P<month>\d{2})\.(?P<day>\d{2})T', upload_date_str)
  144. video_upload_date = (
  145. (
  146. upload_date_m.group('year') +
  147. upload_date_m.group('month') +
  148. upload_date_m.group('day')
  149. )
  150. if upload_date_m else None
  151. )
  152. duration_str = self._search_meta(u'duration', video_page)
  153. duration_m = re.search(r'T(?P<hours>[0-9]{2})H(?P<minutes>[0-9]{2})M(?P<seconds>[0-9]{2})S', duration_str)
  154. video_duration = (
  155. (
  156. (int(duration_m.group('hours')) * 60 * 60) +
  157. (int(duration_m.group('minutes')) * 60) +
  158. int(duration_m.group('seconds'))
  159. )
  160. if duration_m else None
  161. )
  162. video_uploader = self._html_search_regex(
  163. u'<div class="DescrUser"><div>Автор.*?onmouseover="popup_user_info[^"]+">(.*?)</a>',
  164. video_page, u'uploader', fatal=False, flags=re.MULTILINE|re.DOTALL)
  165. video_uploader_id = self._html_search_regex(
  166. u'<div class="DescrUser"><div>Автор.*?onmouseover="popup_user_info\\(.*?\'([^\']+)\'\\);">',
  167. video_page, u'uploader id', fatal=False, flags=re.MULTILINE|re.DOTALL)
  168. video_view_count = self._html_search_regex(
  169. u'Общее количество просмотров.*?<span class="Number">(\\d+)</span>',
  170. video_page, u'view count', fatal=False, flags=re.MULTILINE|re.DOTALL)
  171. return {
  172. 'id': video_id,
  173. 'url': video_url,
  174. 'title': video_title,
  175. 'thumbnail': video_thumbnail,
  176. 'description': video_description,
  177. 'uploader': video_uploader,
  178. 'upload_date': video_upload_date,
  179. 'uploader_id': video_uploader_id,
  180. 'video_duration': video_duration,
  181. 'view_count': video_view_count,
  182. 'age_limit': 18 if adult_content else 0,
  183. 'video_page_url': video_page_url
  184. }
  185. class SmotriCommunityIE(InfoExtractor):
  186. IE_DESC = u'Smotri.com community videos'
  187. IE_NAME = u'smotri:community'
  188. _VALID_URL = r'^https?://(?:www\.)?smotri\.com/community/video/(?P<communityid>[0-9A-Za-z_\'-]+)'
  189. def _real_extract(self, url):
  190. mobj = re.match(self._VALID_URL, url)
  191. community_id = mobj.group('communityid')
  192. url = 'http://smotri.com/export/rss/video/by/community/-/%s/video.xml' % community_id
  193. rss = self._download_xml(url, community_id, u'Downloading community RSS')
  194. entries = [self.url_result(video_url.text, 'Smotri')
  195. for video_url in rss.findall('./channel/item/link')]
  196. description_text = rss.find('./channel/description').text
  197. community_title = self._html_search_regex(
  198. u'^Видео сообщества "([^"]+)"$', description_text, u'community title')
  199. return self.playlist_result(entries, community_id, community_title)
  200. class SmotriUserIE(InfoExtractor):
  201. IE_DESC = u'Smotri.com user videos'
  202. IE_NAME = u'smotri:user'
  203. _VALID_URL = r'^https?://(?:www\.)?smotri\.com/user/(?P<userid>[0-9A-Za-z_\'-]+)'
  204. def _real_extract(self, url):
  205. mobj = re.match(self._VALID_URL, url)
  206. user_id = mobj.group('userid')
  207. url = 'http://smotri.com/export/rss/user/video/-/%s/video.xml' % user_id
  208. rss = self._download_xml(url, user_id, u'Downloading user RSS')
  209. entries = [self.url_result(video_url.text, 'Smotri')
  210. for video_url in rss.findall('./channel/item/link')]
  211. description_text = rss.find('./channel/description').text
  212. user_nickname = self._html_search_regex(
  213. u'^Видео режиссера (.*)$', description_text,
  214. u'user nickname')
  215. return self.playlist_result(entries, user_id, user_nickname)