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.

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