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.

114 lines
4.1 KiB

  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 DigitallySpeakingIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:evt\.dispeak|events\.digitallyspeaking)\.com/(?:[^/]+/)+xml/(?P<id>[^.]+)\.xml'
  13. _TESTS = [{
  14. # From http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface
  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. # From http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC
  24. 'url': 'http://events.digitallyspeaking.com/gdc/sf11/xml/12396_1299111843500GMPX.xml',
  25. 'only_matching': True,
  26. }]
  27. def _parse_mp4(self, metadata):
  28. video_formats = []
  29. video_root = None
  30. mp4_video = xpath_text(metadata, './mp4video', default=None)
  31. if mp4_video is not None:
  32. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video)
  33. video_root = mobj.group('root')
  34. if video_root is None:
  35. http_host = xpath_text(metadata, 'httpHost', default=None)
  36. if http_host:
  37. video_root = 'http://%s/' % http_host
  38. if video_root is None:
  39. # Hard-coded in http://evt.dispeak.com/ubm/gdc/sf16/custom/player2.js
  40. # Works for GPUTechConf, too
  41. video_root = 'http://s3-2u.digitallyspeaking.com/'
  42. formats = metadata.findall('./MBRVideos/MBRVideo')
  43. if not formats:
  44. return None
  45. for a_format in formats:
  46. stream_name = xpath_text(a_format, 'streamName', fatal=True)
  47. video_path = re.match(r'mp4\:(?P<path>.*)', stream_name).group('path')
  48. url = video_root + video_path
  49. vbr = xpath_text(a_format, 'bitrate')
  50. video_formats.append({
  51. 'url': url,
  52. 'vbr': int_or_none(vbr),
  53. })
  54. return video_formats
  55. def _parse_flv(self, metadata):
  56. formats = []
  57. akamai_url = xpath_text(metadata, './akamaiHost', fatal=True)
  58. audios = metadata.findall('./audios/audio')
  59. for audio in audios:
  60. formats.append({
  61. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  62. 'play_path': remove_end(audio.get('url'), '.flv'),
  63. 'ext': 'flv',
  64. 'vcodec': 'none',
  65. 'format_id': audio.get('code'),
  66. })
  67. slide_video_path = xpath_text(metadata, './slideVideo', fatal=True)
  68. formats.append({
  69. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  70. 'play_path': remove_end(slide_video_path, '.flv'),
  71. 'ext': 'flv',
  72. 'format_note': 'slide deck video',
  73. 'quality': -2,
  74. 'preference': -2,
  75. 'format_id': 'slides',
  76. })
  77. speaker_video_path = xpath_text(metadata, './speakerVideo', fatal=True)
  78. formats.append({
  79. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  80. 'play_path': remove_end(speaker_video_path, '.flv'),
  81. 'ext': 'flv',
  82. 'format_note': 'speaker video',
  83. 'quality': -1,
  84. 'preference': -1,
  85. 'format_id': 'speaker',
  86. })
  87. return formats
  88. def _real_extract(self, url):
  89. video_id = self._match_id(url)
  90. xml_description = self._download_xml(url, video_id)
  91. metadata = xpath_element(xml_description, 'metadata')
  92. video_formats = self._parse_mp4(metadata)
  93. if video_formats is None:
  94. video_formats = self._parse_flv(metadata)
  95. return {
  96. 'id': video_id,
  97. 'formats': video_formats,
  98. 'title': xpath_text(metadata, 'title', fatal=True),
  99. 'duration': parse_duration(xpath_text(metadata, 'endTime')),
  100. 'creator': xpath_text(metadata, 'speaker'),
  101. }