dispeak.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. parse_duration,
  6. remove_end,
  7. xpath_element,
  8. xpath_text,
  9. )
  10. class DigitallySpeakingIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:s?evt\.dispeak|events\.digitallyspeaking)\.com/(?:[^/]+/)+xml/(?P<id>[^.]+)\.xml'
  12. _TESTS = [{
  13. # From http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface
  14. 'url': 'http://evt.dispeak.com/ubm/gdc/sf16/xml/840376_BQRC.xml',
  15. 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
  16. 'info_dict': {
  17. 'id': '840376_BQRC',
  18. 'ext': 'mp4',
  19. 'title': 'Tenacious Design and The Interface of \'Destiny\'',
  20. },
  21. }, {
  22. # From http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC
  23. 'url': 'http://events.digitallyspeaking.com/gdc/sf11/xml/12396_1299111843500GMPX.xml',
  24. 'only_matching': True,
  25. }, {
  26. # From http://www.gdcvault.com/play/1013700/Advanced-Material
  27. 'url': 'http://sevt.dispeak.com/ubm/gdc/eur10/xml/11256_1282118587281VNIT.xml',
  28. 'only_matching': True,
  29. }, {
  30. # From https://gdcvault.com/play/1016624, empty speakerVideo
  31. 'url': 'https://sevt.dispeak.com/ubm/gdc/online12/xml/201210-822101_1349794556671DDDD.xml',
  32. 'info_dict': {
  33. 'id': '201210-822101_1349794556671DDDD',
  34. 'ext': 'flv',
  35. 'title': 'Pre-launch - Preparing to Take the Plunge',
  36. },
  37. }, {
  38. # From http://www.gdcvault.com/play/1014846/Conference-Keynote-Shigeru, empty slideVideo
  39. 'url': 'http://events.digitallyspeaking.com/gdc/project25/xml/p25-miyamoto1999_1282467389849HSVB.xml',
  40. 'only_matching': True,
  41. }]
  42. def _parse_mp4(self, metadata):
  43. video_formats = []
  44. video_root = None
  45. mp4_video = xpath_text(metadata, './mp4video', default=None)
  46. if mp4_video is not None:
  47. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video)
  48. video_root = mobj.group('root')
  49. if video_root is None:
  50. http_host = xpath_text(metadata, 'httpHost', default=None)
  51. if http_host:
  52. video_root = f'http://{http_host}/'
  53. if video_root is None:
  54. # Hard-coded in http://evt.dispeak.com/ubm/gdc/sf16/custom/player2.js
  55. # Works for GPUTechConf, too
  56. video_root = 'http://s3-2u.digitallyspeaking.com/'
  57. formats = metadata.findall('./MBRVideos/MBRVideo')
  58. if not formats:
  59. return None
  60. for a_format in formats:
  61. stream_name = xpath_text(a_format, 'streamName', fatal=True)
  62. video_path = re.match(r'mp4\:(?P<path>.*)', stream_name).group('path')
  63. url = video_root + video_path
  64. bitrate = xpath_text(a_format, 'bitrate')
  65. tbr = int_or_none(bitrate)
  66. vbr = int_or_none(self._search_regex(
  67. r'-(\d+)\.mp4', video_path, 'vbr', default=None))
  68. video_formats.append({
  69. 'format_id': bitrate,
  70. 'url': url,
  71. 'tbr': tbr,
  72. 'vbr': vbr,
  73. })
  74. return video_formats
  75. def _parse_flv(self, metadata):
  76. formats = []
  77. akamai_url = xpath_text(metadata, './akamaiHost', fatal=True)
  78. audios = metadata.findall('./audios/audio')
  79. for audio in audios:
  80. formats.append({
  81. 'url': f'rtmp://{akamai_url}/ondemand?ovpfv=1.1',
  82. 'play_path': remove_end(audio.get('url'), '.flv'),
  83. 'ext': 'flv',
  84. 'vcodec': 'none',
  85. 'quality': 1,
  86. 'format_id': audio.get('code'),
  87. })
  88. for video_key, format_id, preference in (
  89. ('slide', 'slides', -2), ('speaker', 'speaker', -1)):
  90. video_path = xpath_text(metadata, f'./{video_key}Video')
  91. if not video_path:
  92. continue
  93. formats.append({
  94. 'url': f'rtmp://{akamai_url}/ondemand?ovpfv=1.1',
  95. 'play_path': remove_end(video_path, '.flv'),
  96. 'ext': 'flv',
  97. 'format_note': f'{video_key} video',
  98. 'quality': preference,
  99. 'format_id': format_id,
  100. })
  101. return formats
  102. def _real_extract(self, url):
  103. video_id = self._match_id(url)
  104. xml_description = self._download_xml(url, video_id)
  105. metadata = xpath_element(xml_description, 'metadata')
  106. video_formats = self._parse_mp4(metadata)
  107. if video_formats is None:
  108. video_formats = self._parse_flv(metadata)
  109. return {
  110. 'id': video_id,
  111. 'formats': video_formats,
  112. 'title': xpath_text(metadata, 'title', fatal=True),
  113. 'duration': parse_duration(xpath_text(metadata, 'endTime')),
  114. 'creator': xpath_text(metadata, 'speaker'),
  115. }