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.

70 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. find_xpath_attr,
  6. int_or_none,
  7. parse_duration,
  8. unified_strdate,
  9. )
  10. class VideoLecturesNetIE(InfoExtractor):
  11. _VALID_URL = r'http://(?:www\.)?videolectures\.net/(?P<id>[^/#?]+)/'
  12. IE_NAME = 'videolectures.net'
  13. _TEST = {
  14. 'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/',
  15. 'info_dict': {
  16. 'id': 'promogram_igor_mekjavic_eng',
  17. 'ext': 'mp4',
  18. 'title': 'Automatics, robotics and biocybernetics',
  19. 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
  20. 'upload_date': '20130627',
  21. 'duration': 565,
  22. 'thumbnail': 're:http://.*\.jpg',
  23. },
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. smil_url = 'http://videolectures.net/%s/video/1/smil.xml' % video_id
  29. smil = self._download_xml(smil_url, video_id)
  30. title = find_xpath_attr(smil, './/meta', 'name', 'title').attrib['content']
  31. description_el = find_xpath_attr(smil, './/meta', 'name', 'abstract')
  32. description = (
  33. None if description_el is None
  34. else description_el.attrib['content'])
  35. upload_date = unified_strdate(
  36. find_xpath_attr(smil, './/meta', 'name', 'date').attrib['content'])
  37. switch = smil.find('.//switch')
  38. duration = parse_duration(switch.attrib.get('dur'))
  39. thumbnail_el = find_xpath_attr(switch, './image', 'type', 'thumbnail')
  40. thumbnail = (
  41. None if thumbnail_el is None else thumbnail_el.attrib.get('src'))
  42. formats = [{
  43. 'url': v.attrib['src'],
  44. 'width': int_or_none(v.attrib.get('width')),
  45. 'height': int_or_none(v.attrib.get('height')),
  46. 'filesize': int_or_none(v.attrib.get('size')),
  47. 'tbr': int_or_none(v.attrib.get('systemBitrate')) / 1000.0,
  48. 'ext': v.attrib.get('ext'),
  49. } for v in switch.findall('./video')
  50. if v.attrib.get('proto') == 'http']
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'description': description,
  55. 'upload_date': upload_date,
  56. 'duration': duration,
  57. 'thumbnail': thumbnail,
  58. 'formats': formats,
  59. }