viidea.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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_part1',
  34. 'ext': 'mp4',
  35. 'title': 'Automatics, robotics and biocybernetics',
  36. 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
  37. 'upload_date': '20130627',
  38. 'duration': 565,
  39. 'thumbnail': 're:http://.*\.jpg',
  40. },
  41. }, {
  42. # video with invalid direct format links (HTTP 403)
  43. 'url': 'http://videolectures.net/russir2010_filippova_nlp/',
  44. 'info_dict': {
  45. 'id': '14891_part1',
  46. 'ext': 'flv',
  47. 'title': 'NLP at Google',
  48. 'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3',
  49. 'duration': 5352,
  50. 'thumbnail': 're:http://.*\.jpg',
  51. },
  52. 'params': {
  53. # rtmp download
  54. 'skip_download': True,
  55. },
  56. }, {
  57. 'url': 'http://videolectures.net/deeplearning2015_montreal/',
  58. 'info_dict': {
  59. 'id': '23181',
  60. 'title': 'Deep Learning Summer School, Montreal 2015',
  61. 'description': 'md5:0533a85e4bd918df52a01f0e1ebe87b7',
  62. 'timestamp': 1438560000,
  63. },
  64. 'playlist_count': 30,
  65. }, {
  66. # multi part lecture
  67. 'url': 'http://videolectures.net/mlss09uk_bishop_ibi/',
  68. 'info_dict': {
  69. 'id': '9737',
  70. 'title': 'Introduction To Bayesian Inference',
  71. 'timestamp': 1251622800,
  72. },
  73. 'playlist': [{
  74. 'info_dict': {
  75. 'id': '9737_part1',
  76. 'ext': 'wmv',
  77. 'title': 'Introduction To Bayesian Inference',
  78. },
  79. }, {
  80. 'info_dict': {
  81. 'id': '9737_part2',
  82. 'ext': 'wmv',
  83. 'title': 'Introduction To Bayesian Inference',
  84. },
  85. }],
  86. 'playlist_count': 2,
  87. }]
  88. def _real_extract(self, url):
  89. lecture_slug, part = re.match(self._VALID_URL, url).groups()
  90. webpage = self._download_webpage(url, lecture_slug)
  91. cfg = self._parse_json(self._search_regex([r'cfg\s*:\s*({.+?}),[\da-zA-Z_]:\(?function', r'cfg\s*:\s*({[^}]+})'], webpage, 'cfg'), lecture_slug, js_to_json)
  92. lecture_id = compat_str(cfg['obj_id'])
  93. base_url = self._proto_relative_url(cfg['livepipe'], 'http:')
  94. lecture_data = self._download_json('%s/site/api/lecture/%s?format=json' % (base_url, lecture_id), lecture_id)['lecture'][0]
  95. lecture_info = {
  96. 'id': lecture_id,
  97. 'display_id': lecture_slug,
  98. 'title': lecture_data['title'],
  99. 'timestamp': parse_iso8601(lecture_data.get('time')),
  100. 'description': lecture_data.get('description_wiki'),
  101. 'thumbnail': lecture_data.get('thumb'),
  102. }
  103. entries = []
  104. parts = cfg.get('videos')
  105. if parts:
  106. if len(parts) == 1:
  107. part = compat_str(parts[0])
  108. if part:
  109. smil_url = '%s/%s/video/%s/smil.xml' % (base_url, lecture_slug, part)
  110. smil = self._download_smil(smil_url, lecture_id)
  111. info = self._parse_smil(smil, smil_url, lecture_id)
  112. info['id'] = '%s_part%s' % (lecture_id, part)
  113. switch = smil.find('.//switch')
  114. if switch is not None:
  115. info['duration'] = parse_duration(switch.attrib.get('dur'))
  116. return info
  117. else:
  118. for part in parts:
  119. entries.append(self.url_result('%s/%s/video/%s' % (base_url, lecture_slug, part), 'Viidea'))
  120. lecture_info['_type'] = 'multi_video'
  121. if not parts or lecture_data.get('type') == 'evt':
  122. # Probably a playlist
  123. playlist_webpage = self._download_webpage('%s/site/ajax/drilldown/?id=%s' % (base_url, lecture_id), lecture_id)
  124. entries = [
  125. self.url_result(compat_urlparse.urljoin(url, video_url), 'Viidea')
  126. for _, video_url in re.findall(r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', playlist_webpage)]
  127. lecture_info['_type'] = 'playlist'
  128. lecture_info['entries'] = entries
  129. return lecture_info