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.

110 lines
4.0 KiB

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