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.

144 lines
5.0 KiB

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