logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

dispeak.py (5080B)


  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. # From https://gdcvault.com/play/1016624, empty speakerVideo
  32. 'url': 'https://sevt.dispeak.com/ubm/gdc/online12/xml/201210-822101_1349794556671DDDD.xml',
  33. 'info_dict': {
  34. 'id': '201210-822101_1349794556671DDDD',
  35. 'ext': 'flv',
  36. 'title': 'Pre-launch - Preparing to Take the Plunge',
  37. },
  38. }, {
  39. # From http://www.gdcvault.com/play/1014846/Conference-Keynote-Shigeru, empty slideVideo
  40. 'url': 'http://events.digitallyspeaking.com/gdc/project25/xml/p25-miyamoto1999_1282467389849HSVB.xml',
  41. 'only_matching': True,
  42. }]
  43. def _parse_mp4(self, metadata):
  44. video_formats = []
  45. video_root = None
  46. mp4_video = xpath_text(metadata, './mp4video', default=None)
  47. if mp4_video is not None:
  48. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video)
  49. video_root = mobj.group('root')
  50. if video_root is None:
  51. http_host = xpath_text(metadata, 'httpHost', default=None)
  52. if http_host:
  53. video_root = 'http://%s/' % http_host
  54. if video_root is None:
  55. # Hard-coded in http://evt.dispeak.com/ubm/gdc/sf16/custom/player2.js
  56. # Works for GPUTechConf, too
  57. video_root = 'http://s3-2u.digitallyspeaking.com/'
  58. formats = metadata.findall('./MBRVideos/MBRVideo')
  59. if not formats:
  60. return None
  61. for a_format in formats:
  62. stream_name = xpath_text(a_format, 'streamName', fatal=True)
  63. video_path = re.match(r'mp4\:(?P<path>.*)', stream_name).group('path')
  64. url = video_root + video_path
  65. bitrate = xpath_text(a_format, 'bitrate')
  66. tbr = int_or_none(bitrate)
  67. vbr = int_or_none(self._search_regex(
  68. r'-(\d+)\.mp4', video_path, 'vbr', default=None))
  69. abr = tbr - vbr if tbr and vbr else None
  70. video_formats.append({
  71. 'format_id': bitrate,
  72. 'url': url,
  73. 'tbr': tbr,
  74. 'vbr': vbr,
  75. 'abr': abr,
  76. })
  77. return video_formats
  78. def _parse_flv(self, metadata):
  79. formats = []
  80. akamai_url = xpath_text(metadata, './akamaiHost', fatal=True)
  81. audios = metadata.findall('./audios/audio')
  82. for audio in audios:
  83. formats.append({
  84. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  85. 'play_path': remove_end(audio.get('url'), '.flv'),
  86. 'ext': 'flv',
  87. 'vcodec': 'none',
  88. 'format_id': audio.get('code'),
  89. })
  90. for video_key, format_id, preference in (
  91. ('slide', 'slides', -2), ('speaker', 'speaker', -1)):
  92. video_path = xpath_text(metadata, './%sVideo' % video_key)
  93. if not video_path:
  94. continue
  95. formats.append({
  96. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  97. 'play_path': remove_end(video_path, '.flv'),
  98. 'ext': 'flv',
  99. 'format_note': '%s video' % video_key,
  100. 'quality': preference,
  101. 'preference': preference,
  102. 'format_id': format_id,
  103. })
  104. return formats
  105. def _real_extract(self, url):
  106. video_id = self._match_id(url)
  107. xml_description = self._download_xml(url, video_id)
  108. metadata = xpath_element(xml_description, 'metadata')
  109. video_formats = self._parse_mp4(metadata)
  110. if video_formats is None:
  111. video_formats = self._parse_flv(metadata)
  112. return {
  113. 'id': video_id,
  114. 'formats': video_formats,
  115. 'title': xpath_text(metadata, 'title', fatal=True),
  116. 'duration': parse_duration(xpath_text(metadata, 'endTime')),
  117. 'creator': xpath_text(metadata, 'speaker'),
  118. }