videolecturesnet.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. _TEST = {
  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. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. smil_url = 'http://videolectures.net/%s/video/1/smil.xml' % video_id
  30. try:
  31. smil = self._download_smil(smil_url, video_id)
  32. except ExtractorError as e:
  33. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  34. # Probably a playlist
  35. webpage = self._download_webpage(url, video_id)
  36. entries = [
  37. self.url_result(compat_urlparse.urljoin(url, video_url), 'VideoLecturesNet')
  38. for _, video_url in re.findall(r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', webpage)]
  39. playlist_title = self._html_search_meta('title', webpage, 'title', fatal=True)
  40. playlist_description = self._html_search_meta('description', webpage, 'description')
  41. return self.playlist_result(entries, video_id, playlist_title, playlist_description)
  42. info = self._parse_smil(smil, smil_url, video_id)
  43. info['id'] = video_id
  44. switch = smil.find('.//switch')
  45. if switch is not None:
  46. info['duration'] = parse_duration(switch.attrib.get('dur'))
  47. return info