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.

82 lines
2.8 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. )
  12. class VideoLecturesNetIE(InfoExtractor):
  13. _VALID_URL = r'http://(?:www\.)?videolectures\.net/(?P<id>[^/#?]+)/*(?:[#?].*)?$'
  14. IE_NAME = 'videolectures.net'
  15. _TESTS = [{
  16. 'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/',
  17. 'info_dict': {
  18. 'id': 'promogram_igor_mekjavic_eng',
  19. 'ext': 'mp4',
  20. 'title': 'Automatics, robotics and biocybernetics',
  21. 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
  22. 'upload_date': '20130627',
  23. 'duration': 565,
  24. 'thumbnail': 're:http://.*\.jpg',
  25. },
  26. }, {
  27. # video with invalid direct format links (HTTP 403)
  28. 'url': 'http://videolectures.net/russir2010_filippova_nlp/',
  29. 'info_dict': {
  30. 'id': 'russir2010_filippova_nlp',
  31. 'ext': 'flv',
  32. 'title': 'NLP at Google',
  33. 'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3',
  34. 'duration': 5352,
  35. 'thumbnail': 're:http://.*\.jpg',
  36. },
  37. 'params': {
  38. # rtmp download
  39. 'skip_download': True,
  40. },
  41. }, {
  42. 'url': 'http://videolectures.net/deeplearning2015_montreal/',
  43. 'info_dict': {
  44. 'id': 'deeplearning2015_montreal',
  45. 'title': 'Deep Learning Summer School, Montreal 2015',
  46. 'description': 'md5:90121a40cc6926df1bf04dcd8563ed3b',
  47. },
  48. 'playlist_count': 30,
  49. }]
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. smil_url = 'http://videolectures.net/%s/video/1/smil.xml' % video_id
  53. try:
  54. smil = self._download_smil(smil_url, video_id)
  55. except ExtractorError as e:
  56. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  57. # Probably a playlist
  58. webpage = self._download_webpage(url, video_id)
  59. entries = [
  60. self.url_result(compat_urlparse.urljoin(url, video_url), 'VideoLecturesNet')
  61. for _, video_url in re.findall(r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', webpage)]
  62. playlist_title = self._html_search_meta('title', webpage, 'title', fatal=True)
  63. playlist_description = self._html_search_meta('description', webpage, 'description')
  64. return self.playlist_result(entries, video_id, playlist_title, playlist_description)
  65. info = self._parse_smil(smil, smil_url, video_id)
  66. info['id'] = video_id
  67. switch = smil.find('.//switch')
  68. if switch is not None:
  69. info['duration'] = parse_duration(switch.attrib.get('dur'))
  70. return info