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.

188 lines
6.8 KiB

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