dispeak.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_duration,
  7. remove_end,
  8. xpath_element,
  9. xpath_text,
  10. )
  11. class DigitalSpeakingIE(InfoExtractor):
  12. _VALID_URL = r'http://evt.dispeak.com/([^/]+/)+xml/(?P<id>[^.]+).xml'
  13. _TEST = {
  14. # From http://evt.dispeak.com/ubm/gdc/sf16/xml/840376_BQRC.xml
  15. 'url': 'http://evt.dispeak.com/ubm/gdc/sf16/xml/840376_BQRC.xml',
  16. 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
  17. 'info_dict': {
  18. 'id': '840376_BQRC',
  19. 'ext': 'mp4',
  20. 'title': 'Tenacious Design and The Interface of \'Destiny\'',
  21. },
  22. }
  23. def _parse_mp4(self, metadata):
  24. video_formats = []
  25. video_root = None
  26. mp4_video = xpath_text(metadata, './mp4video', default=None)
  27. if mp4_video is not None:
  28. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video)
  29. video_root = mobj.group('root')
  30. if video_root is None:
  31. http_host = xpath_text(metadata, 'httpHost', default=None)
  32. if http_host:
  33. video_root = 'http://%s/' % http_host
  34. if video_root is None:
  35. # Hard-coded in http://evt.dispeak.com/ubm/gdc/sf16/custom/player2.js
  36. # Works for GPUTechConf, too
  37. video_root = 'http://s3-2u.digitallyspeaking.com/'
  38. formats = metadata.findall('./MBRVideos/MBRVideo')
  39. if not formats:
  40. return None
  41. for a_format in formats:
  42. stream_name = xpath_text(a_format, 'streamName', fatal=True)
  43. video_path = re.match(r'mp4\:(?P<path>.*)', stream_name).group('path')
  44. url = video_root + video_path
  45. vbr = xpath_text(a_format, 'bitrate')
  46. video_formats.append({
  47. 'url': url,
  48. 'vbr': int_or_none(vbr),
  49. })
  50. return video_formats
  51. def _parse_flv(self, metadata):
  52. formats = []
  53. akamai_url = xpath_text(metadata, './akamaiHost', fatal=True)
  54. audios = metadata.find('./audios')
  55. if audios is not None:
  56. for audio in audios:
  57. formats.append({
  58. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  59. 'play_path': remove_end(audio.get('url'), '.flv'),
  60. 'ext': 'flv',
  61. 'vcodec': 'none',
  62. 'format_id': audio.get('code'),
  63. })
  64. slide_video_path = xpath_text(metadata, './slideVideo', fatal=True)
  65. formats.append({
  66. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  67. 'play_path': remove_end(slide_video_path, '.flv'),
  68. 'ext': 'flv',
  69. 'format_note': 'slide deck video',
  70. 'quality': -2,
  71. 'preference': -2,
  72. 'format_id': 'slides',
  73. })
  74. speaker_video_path = xpath_text(metadata, './speakerVideo', fatal=True)
  75. formats.append({
  76. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  77. 'play_path': remove_end(speaker_video_path, '.flv'),
  78. 'ext': 'flv',
  79. 'format_note': 'speaker video',
  80. 'quality': -1,
  81. 'preference': -1,
  82. 'format_id': 'speaker',
  83. })
  84. return formats
  85. def _real_extract(self, url):
  86. video_id = self._match_id(url)
  87. xml_description = self._download_xml(url, video_id)
  88. metadata = xpath_element(xml_description, 'metadata')
  89. video_formats = self._parse_mp4(metadata)
  90. if video_formats is None:
  91. video_formats = self._parse_flv(metadata)
  92. return {
  93. 'id': video_id,
  94. 'formats': video_formats,
  95. 'title': xpath_text(metadata, 'title', fatal=True),
  96. 'duration': parse_duration(xpath_text(metadata, 'endTime')),
  97. 'creator': xpath_text(metadata, 'speaker'),
  98. }