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.

86 lines
2.9 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'(?:https?://link\.theplatform\.com/s/[^/]+/|theplatform:)(?P<id>[^/\?]+)'
  11. _TEST = {
  12. # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
  13. u'url': u'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
  14. u'info_dict': {
  15. u'id': u'e9I_cZgTgIPd',
  16. u'ext': u'flv',
  17. u'title': u'Blackberry\'s big, bold Z30',
  18. u'description': u'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
  19. u'duration': 247,
  20. },
  21. u'params': {
  22. # rtmp download
  23. u'skip_download': True,
  24. },
  25. }
  26. def _get_info(self, video_id):
  27. smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
  28. 'format=smil&mbr=true'.format(video_id))
  29. meta = self._download_xml(smil_url, video_id)
  30. try:
  31. error_msg = next(
  32. n.attrib['abstract']
  33. for n in meta.findall(_x('.//smil:ref'))
  34. if n.attrib.get('title') == u'Geographic Restriction')
  35. except StopIteration:
  36. pass
  37. else:
  38. raise ExtractorError(error_msg, expected=True)
  39. info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id)
  40. info_json = self._download_webpage(info_url, video_id)
  41. info = json.loads(info_json)
  42. head = meta.find(_x('smil:head'))
  43. body = meta.find(_x('smil:body'))
  44. base_url = head.find(_x('smil:meta')).attrib['base']
  45. switch = body.find(_x('smil:switch'))
  46. formats = []
  47. for f in switch.findall(_x('smil:video')):
  48. attr = f.attrib
  49. width = int(attr['width'])
  50. height = int(attr['height'])
  51. vbr = int(attr['system-bitrate']) // 1000
  52. format_id = '%dx%d_%dk' % (width, height, vbr)
  53. formats.append({
  54. 'format_id': format_id,
  55. 'url': base_url,
  56. 'play_path': 'mp4:' + attr['src'],
  57. 'ext': 'flv',
  58. 'width': width,
  59. 'height': height,
  60. 'vbr': vbr,
  61. })
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'title': info['title'],
  66. 'formats': formats,
  67. 'description': info['description'],
  68. 'thumbnail': info['defaultThumbnailUrl'],
  69. 'duration': info['duration']//1000,
  70. }
  71. def _real_extract(self, url):
  72. mobj = re.match(self._VALID_URL, url)
  73. video_id = mobj.group('id')
  74. return self._get_info(video_id)