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.

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