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.

80 lines
2.7 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. formats.append({
  50. 'url': base_url,
  51. 'play_path': 'mp4:' + attr['src'],
  52. 'ext': 'flv',
  53. 'width': int(attr['width']),
  54. 'height': int(attr['height']),
  55. 'vbr': int(attr['system-bitrate']),
  56. })
  57. formats.sort(key=lambda f: (f['height'], f['width'], f['vbr']))
  58. return {
  59. 'id': video_id,
  60. 'title': info['title'],
  61. 'formats': formats,
  62. 'description': info['description'],
  63. 'thumbnail': info['defaultThumbnailUrl'],
  64. 'duration': info['duration']//1000,
  65. }
  66. def _real_extract(self, url):
  67. mobj = re.match(self._VALID_URL, url)
  68. video_id = mobj.group('id')
  69. return self._get_info(video_id)