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.

124 lines
4.6 KiB

10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. )
  8. from ..utils import (
  9. determine_ext,
  10. ExtractorError,
  11. xpath_with_ns,
  12. )
  13. _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
  14. class ThePlatformIE(InfoExtractor):
  15. _VALID_URL = r'''(?x)
  16. (?:https?://(?:link|player)\.theplatform\.com/[sp]/[^/]+/
  17. (?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/)?
  18. |theplatform:)(?P<id>[^/\?&]+)'''
  19. _TEST = {
  20. # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
  21. 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
  22. 'info_dict': {
  23. 'id': 'e9I_cZgTgIPd',
  24. 'ext': 'flv',
  25. 'title': 'Blackberry\'s big, bold Z30',
  26. 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
  27. 'duration': 247,
  28. },
  29. 'params': {
  30. # rtmp download
  31. 'skip_download': True,
  32. },
  33. }
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. video_id = mobj.group('id')
  37. if mobj.group('config'):
  38. config_url = url + '&form=json'
  39. config_url = config_url.replace('swf/', 'config/')
  40. config_url = config_url.replace('onsite/', 'onsite/config/')
  41. config = self._download_json(config_url, video_id, 'Downloading config')
  42. smil_url = config['releaseUrl'] + '&format=SMIL&formats=MPEG4&manifest=f4m'
  43. else:
  44. smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
  45. 'format=smil&mbr=true'.format(video_id))
  46. meta = self._download_xml(smil_url, video_id)
  47. try:
  48. error_msg = next(
  49. n.attrib['abstract']
  50. for n in meta.findall(_x('.//smil:ref'))
  51. if n.attrib.get('title') == 'Geographic Restriction')
  52. except StopIteration:
  53. pass
  54. else:
  55. raise ExtractorError(error_msg, expected=True)
  56. info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id)
  57. info_json = self._download_webpage(info_url, video_id)
  58. info = json.loads(info_json)
  59. head = meta.find(_x('smil:head'))
  60. body = meta.find(_x('smil:body'))
  61. f4m_node = body.find(_x('smil:seq//smil:video'))
  62. if f4m_node is not None and '.f4m' in f4m_node.attrib['src']:
  63. f4m_url = f4m_node.attrib['src']
  64. if 'manifest.f4m?' not in f4m_url:
  65. f4m_url += '?'
  66. # the parameters are from syfy.com, other sites may use others,
  67. # they also work for nbc.com
  68. f4m_url += '&g=UXWGVKRWHFSP&hdcore=3.0.3'
  69. formats = self._extract_f4m_formats(f4m_url, video_id)
  70. else:
  71. formats = []
  72. switch = body.find(_x('smil:switch'))
  73. if switch is not None:
  74. base_url = head.find(_x('smil:meta')).attrib['base']
  75. for f in switch.findall(_x('smil:video')):
  76. attr = f.attrib
  77. width = int(attr['width'])
  78. height = int(attr['height'])
  79. vbr = int(attr['system-bitrate']) // 1000
  80. format_id = '%dx%d_%dk' % (width, height, vbr)
  81. formats.append({
  82. 'format_id': format_id,
  83. 'url': base_url,
  84. 'play_path': 'mp4:' + attr['src'],
  85. 'ext': 'flv',
  86. 'width': width,
  87. 'height': height,
  88. 'vbr': vbr,
  89. })
  90. else:
  91. switch = body.find(_x('smil:seq//smil:switch'))
  92. for f in switch.findall(_x('smil:video')):
  93. attr = f.attrib
  94. vbr = int(attr['system-bitrate']) // 1000
  95. ext = determine_ext(attr['src'])
  96. if ext == 'once':
  97. ext = 'mp4'
  98. formats.append({
  99. 'format_id': compat_str(vbr),
  100. 'url': attr['src'],
  101. 'vbr': vbr,
  102. 'ext': ext,
  103. })
  104. self._sort_formats(formats)
  105. return {
  106. 'id': video_id,
  107. 'title': info['title'],
  108. 'formats': formats,
  109. 'description': info['description'],
  110. 'thumbnail': info['defaultThumbnailUrl'],
  111. 'duration': info['duration'] // 1000,
  112. }