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.

86 lines
2.9 KiB

10 years ago
  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. for v in switch.findall('./video'):
  44. proto = v.attrib.get('proto')
  45. if proto not in ['http', 'rtmp']:
  46. continue
  47. f = {
  48. 'width': int_or_none(v.attrib.get('width')),
  49. 'height': int_or_none(v.attrib.get('height')),
  50. 'filesize': int_or_none(v.attrib.get('size')),
  51. 'tbr': int_or_none(v.attrib.get('systemBitrate')) / 1000.0,
  52. 'ext': v.attrib.get('ext'),
  53. }
  54. src = v.attrib['src']
  55. if proto == 'http':
  56. if self._is_valid_url(src, video_id):
  57. f['url'] = src
  58. formats.append(f)
  59. elif proto == 'rtmp':
  60. f.update({
  61. 'url': v.attrib['streamer'],
  62. 'play_path': src,
  63. 'rtmp_real_time': True,
  64. })
  65. formats.append(f)
  66. self._sort_formats(formats)
  67. return {
  68. 'id': video_id,
  69. 'title': title,
  70. 'description': description,
  71. 'upload_date': upload_date,
  72. 'duration': duration,
  73. 'thumbnail': thumbnail,
  74. 'formats': formats,
  75. }