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.

68 lines
2.4 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. xpath_with_ns,
  6. )
  7. _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
  8. class ThePlatformIE(InfoExtractor):
  9. _VALID_URL = r'(?:https?://link\.theplatform\.com/s/[^/]+/|theplatform:)(?P<id>[^/\?]+)'
  10. _TEST = {
  11. # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
  12. u'url': u'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
  13. u'info_dict': {
  14. u'id': u'e9I_cZgTgIPd',
  15. u'ext': u'flv',
  16. u'title': u'Blackberry\'s big, bold Z30',
  17. u'description': u'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
  18. u'duration': 247,
  19. },
  20. u'params': {
  21. # rtmp download
  22. u'skip_download': True,
  23. },
  24. }
  25. def _get_info(self, video_id):
  26. smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
  27. 'format=smil&mbr=true'.format(video_id))
  28. meta = self._download_xml(smil_url, video_id)
  29. info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id)
  30. info_json = self._download_webpage(info_url, video_id)
  31. info = json.loads(info_json)
  32. head = meta.find(_x('smil:head'))
  33. body = meta.find(_x('smil:body'))
  34. base_url = head.find(_x('smil:meta')).attrib['base']
  35. switch = body.find(_x('smil:switch'))
  36. formats = []
  37. for f in switch.findall(_x('smil:video')):
  38. attr = f.attrib
  39. formats.append({
  40. 'url': base_url,
  41. 'play_path': 'mp4:' + attr['src'],
  42. 'ext': 'flv',
  43. 'width': int(attr['width']),
  44. 'height': int(attr['height']),
  45. 'vbr': int(attr['system-bitrate']),
  46. })
  47. formats.sort(key=lambda f: (f['height'], f['width'], f['vbr']))
  48. return {
  49. 'id': video_id,
  50. 'title': info['title'],
  51. 'formats': formats,
  52. 'description': info['description'],
  53. 'thumbnail': info['defaultThumbnailUrl'],
  54. 'duration': info['duration']//1000,
  55. }
  56. def _real_extract(self, url):
  57. mobj = re.match(self._VALID_URL, url)
  58. video_id = mobj.group('id')
  59. return self._get_info(video_id)