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.

125 lines
4.6 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. bitrate = xpath_text(a_format, 'bitrate')
  54. tbr = int_or_none(bitrate)
  55. vbr = int_or_none(self._search_regex(
  56. r'-(\d+)\.mp4', video_path, 'vbr', default=None))
  57. abr = tbr - vbr if tbr and vbr else None
  58. video_formats.append({
  59. 'format_id': bitrate,
  60. 'url': url,
  61. 'tbr': tbr,
  62. 'vbr': vbr,
  63. 'abr': abr,
  64. })
  65. return video_formats
  66. def _parse_flv(self, metadata):
  67. formats = []
  68. akamai_url = xpath_text(metadata, './akamaiHost', fatal=True)
  69. audios = metadata.findall('./audios/audio')
  70. for audio in audios:
  71. formats.append({
  72. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  73. 'play_path': remove_end(audio.get('url'), '.flv'),
  74. 'ext': 'flv',
  75. 'vcodec': 'none',
  76. 'format_id': audio.get('code'),
  77. })
  78. slide_video_path = xpath_text(metadata, './slideVideo', fatal=True)
  79. formats.append({
  80. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  81. 'play_path': remove_end(slide_video_path, '.flv'),
  82. 'ext': 'flv',
  83. 'format_note': 'slide deck video',
  84. 'quality': -2,
  85. 'preference': -2,
  86. 'format_id': 'slides',
  87. })
  88. speaker_video_path = xpath_text(metadata, './speakerVideo', fatal=True)
  89. formats.append({
  90. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  91. 'play_path': remove_end(speaker_video_path, '.flv'),
  92. 'ext': 'flv',
  93. 'format_note': 'speaker video',
  94. 'quality': -1,
  95. 'preference': -1,
  96. 'format_id': 'speaker',
  97. })
  98. return formats
  99. def _real_extract(self, url):
  100. video_id = self._match_id(url)
  101. xml_description = self._download_xml(url, video_id)
  102. metadata = xpath_element(xml_description, 'metadata')
  103. video_formats = self._parse_mp4(metadata)
  104. if video_formats is None:
  105. video_formats = self._parse_flv(metadata)
  106. return {
  107. 'id': video_id,
  108. 'formats': video_formats,
  109. 'title': xpath_text(metadata, 'title', fatal=True),
  110. 'duration': parse_duration(xpath_text(metadata, 'endTime')),
  111. 'creator': xpath_text(metadata, 'speaker'),
  112. }