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.

202 lines
7.3 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_HTTPError,
  6. compat_str,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. js_to_json,
  12. parse_duration,
  13. parse_iso8601,
  14. )
  15. class ViideaIE(InfoExtractor):
  16. _VALID_URL = r'''(?x)https?://(?:www\.)?(?:
  17. videolectures\.net|
  18. flexilearn\.viidea\.net|
  19. presentations\.ocwconsortium\.org|
  20. video\.travel-zoom\.si|
  21. video\.pomp-forum\.si|
  22. tv\.nil\.si|
  23. video\.hekovnik.com|
  24. video\.szko\.si|
  25. kpk\.viidea\.com|
  26. inside\.viidea\.net|
  27. video\.kiberpipa\.org|
  28. bvvideo\.si|
  29. kongres\.viidea\.net|
  30. edemokracija\.viidea\.com
  31. )(?:/lecture)?/(?P<id>[^/]+)(?:/video/(?P<part>\d+))?/*(?:[#?].*)?$'''
  32. _TESTS = [{
  33. 'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/',
  34. 'info_dict': {
  35. 'id': '20171',
  36. 'display_id': 'promogram_igor_mekjavic_eng',
  37. 'ext': 'mp4',
  38. 'title': 'Automatics, robotics and biocybernetics',
  39. 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
  40. 'thumbnail': r're:http://.*\.jpg',
  41. 'timestamp': 1372349289,
  42. 'upload_date': '20130627',
  43. 'duration': 565,
  44. },
  45. 'params': {
  46. # m3u8 download
  47. 'skip_download': True,
  48. },
  49. }, {
  50. # video with invalid direct format links (HTTP 403)
  51. 'url': 'http://videolectures.net/russir2010_filippova_nlp/',
  52. 'info_dict': {
  53. 'id': '14891',
  54. 'display_id': 'russir2010_filippova_nlp',
  55. 'ext': 'flv',
  56. 'title': 'NLP at Google',
  57. 'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3',
  58. 'thumbnail': r're:http://.*\.jpg',
  59. 'timestamp': 1284375600,
  60. 'upload_date': '20100913',
  61. 'duration': 5352,
  62. },
  63. 'params': {
  64. # rtmp download
  65. 'skip_download': True,
  66. },
  67. }, {
  68. # event playlist
  69. 'url': 'http://videolectures.net/deeplearning2015_montreal/',
  70. 'info_dict': {
  71. 'id': '23181',
  72. 'title': 'Deep Learning Summer School, Montreal 2015',
  73. 'description': 'md5:0533a85e4bd918df52a01f0e1ebe87b7',
  74. 'thumbnail': r're:http://.*\.jpg',
  75. 'timestamp': 1438560000,
  76. },
  77. 'playlist_count': 30,
  78. }, {
  79. # multi part lecture
  80. 'url': 'http://videolectures.net/mlss09uk_bishop_ibi/',
  81. 'info_dict': {
  82. 'id': '9737',
  83. 'display_id': 'mlss09uk_bishop_ibi',
  84. 'title': 'Introduction To Bayesian Inference',
  85. 'thumbnail': r're:http://.*\.jpg',
  86. 'timestamp': 1251622800,
  87. },
  88. 'playlist': [{
  89. 'info_dict': {
  90. 'id': '9737_part1',
  91. 'display_id': 'mlss09uk_bishop_ibi_part1',
  92. 'ext': 'wmv',
  93. 'title': 'Introduction To Bayesian Inference (Part 1)',
  94. 'thumbnail': r're:http://.*\.jpg',
  95. 'duration': 4622,
  96. 'timestamp': 1251622800,
  97. 'upload_date': '20090830',
  98. },
  99. }, {
  100. 'info_dict': {
  101. 'id': '9737_part2',
  102. 'display_id': 'mlss09uk_bishop_ibi_part2',
  103. 'ext': 'wmv',
  104. 'title': 'Introduction To Bayesian Inference (Part 2)',
  105. 'thumbnail': r're:http://.*\.jpg',
  106. 'duration': 5641,
  107. 'timestamp': 1251622800,
  108. 'upload_date': '20090830',
  109. },
  110. }],
  111. 'playlist_count': 2,
  112. }]
  113. def _real_extract(self, url):
  114. lecture_slug, explicit_part_id = re.match(self._VALID_URL, url).groups()
  115. webpage = self._download_webpage(url, lecture_slug)
  116. cfg = self._parse_json(self._search_regex(
  117. [r'cfg\s*:\s*({.+?})\s*,\s*[\da-zA-Z_]+\s*:\s*\(?\s*function',
  118. r'cfg\s*:\s*({[^}]+})'],
  119. webpage, 'cfg'), lecture_slug, js_to_json)
  120. lecture_id = compat_str(cfg['obj_id'])
  121. base_url = self._proto_relative_url(cfg['livepipe'], 'http:')
  122. try:
  123. lecture_data = self._download_json(
  124. '%s/site/api/lecture/%s?format=json' % (base_url, lecture_id),
  125. lecture_id)['lecture'][0]
  126. except ExtractorError as e:
  127. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
  128. msg = self._parse_json(
  129. e.cause.read().decode('utf-8'), lecture_id)
  130. raise ExtractorError(msg['detail'], expected=True)
  131. raise
  132. lecture_info = {
  133. 'id': lecture_id,
  134. 'display_id': lecture_slug,
  135. 'title': lecture_data['title'],
  136. 'timestamp': parse_iso8601(lecture_data.get('time')),
  137. 'description': lecture_data.get('description_wiki'),
  138. 'thumbnail': lecture_data.get('thumb'),
  139. }
  140. playlist_entries = []
  141. lecture_type = lecture_data.get('type')
  142. parts = [compat_str(video) for video in cfg.get('videos', [])]
  143. if parts:
  144. multipart = len(parts) > 1
  145. def extract_part(part_id):
  146. smil_url = '%s/%s/video/%s/smil.xml' % (base_url, lecture_slug, part_id)
  147. smil = self._download_smil(smil_url, lecture_id)
  148. info = self._parse_smil(smil, smil_url, lecture_id)
  149. self._sort_formats(info['formats'])
  150. info['id'] = lecture_id if not multipart else '%s_part%s' % (lecture_id, part_id)
  151. info['display_id'] = lecture_slug if not multipart else '%s_part%s' % (lecture_slug, part_id)
  152. if multipart:
  153. info['title'] += ' (Part %s)' % part_id
  154. switch = smil.find('.//switch')
  155. if switch is not None:
  156. info['duration'] = parse_duration(switch.attrib.get('dur'))
  157. item_info = lecture_info.copy()
  158. item_info.update(info)
  159. return item_info
  160. if explicit_part_id or not multipart:
  161. result = extract_part(explicit_part_id or parts[0])
  162. else:
  163. result = {
  164. '_type': 'multi_video',
  165. 'entries': [extract_part(part) for part in parts],
  166. }
  167. result.update(lecture_info)
  168. # Immediately return explicitly requested part or non event item
  169. if explicit_part_id or lecture_type != 'evt':
  170. return result
  171. playlist_entries.append(result)
  172. # It's probably a playlist
  173. if not parts or lecture_type == 'evt':
  174. playlist_webpage = self._download_webpage(
  175. '%s/site/ajax/drilldown/?id=%s' % (base_url, lecture_id), lecture_id)
  176. entries = [
  177. self.url_result(compat_urlparse.urljoin(url, video_url), 'Viidea')
  178. for _, video_url in re.findall(
  179. r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', playlist_webpage)]
  180. playlist_entries.extend(entries)
  181. playlist = self.playlist_result(playlist_entries, lecture_id)
  182. playlist.update(lecture_info)
  183. return playlist