springboardplatform.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. xpath_attr,
  7. xpath_text,
  8. xpath_element,
  9. unescapeHTML,
  10. unified_timestamp,
  11. )
  12. class SpringboardPlatformIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. cms\.springboardplatform\.com/
  16. (?:
  17. (?:previews|embed_iframe)/(?P<index>\d+)/video/(?P<id>\d+)|
  18. xml_feeds_advanced/index/(?P<index_2>\d+)/rss3/(?P<id_2>\d+)
  19. )
  20. '''
  21. _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//cms\.springboardplatform\.com/embed_iframe/\d+/video/\d+.*?)\1']
  22. _TESTS = [{
  23. 'url': 'http://cms.springboardplatform.com/previews/159/video/981017/0/0/1',
  24. 'md5': '5c3cb7b5c55740d482561099e920f192',
  25. 'info_dict': {
  26. 'id': '981017',
  27. 'ext': 'mp4',
  28. 'title': 'Redman "BUD like YOU" "Usher Good Kisser" REMIX',
  29. 'description': 'Redman "BUD like YOU" "Usher Good Kisser" REMIX',
  30. 'thumbnail': r're:^https?://.*\.jpg$',
  31. 'timestamp': 1409132328,
  32. 'upload_date': '20140827',
  33. 'duration': 193,
  34. },
  35. }, {
  36. 'url': 'http://cms.springboardplatform.com/embed_iframe/159/video/981017/rab007/rapbasement.com/1/1',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'http://cms.springboardplatform.com/embed_iframe/20/video/1731611/ki055/kidzworld.com/10',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'http://cms.springboardplatform.com/xml_feeds_advanced/index/159/rss3/981017/0/0/1/',
  43. 'only_matching': True,
  44. }]
  45. def _real_extract(self, url):
  46. mobj = self._match_valid_url(url)
  47. video_id = mobj.group('id') or mobj.group('id_2')
  48. index = mobj.group('index') or mobj.group('index_2')
  49. video = self._download_xml(
  50. 'http://cms.springboardplatform.com/xml_feeds_advanced/index/%s/rss3/%s'
  51. % (index, video_id), video_id)
  52. item = xpath_element(video, './/item', 'item', fatal=True)
  53. content = xpath_element(
  54. item, './{http://search.yahoo.com/mrss/}content', 'content',
  55. fatal=True)
  56. title = unescapeHTML(xpath_text(item, './title', 'title', fatal=True))
  57. video_url = content.attrib['url']
  58. if 'error_video.mp4' in video_url:
  59. raise ExtractorError(
  60. 'Video %s no longer exists' % video_id, expected=True)
  61. duration = int_or_none(content.get('duration'))
  62. tbr = int_or_none(content.get('bitrate'))
  63. filesize = int_or_none(content.get('fileSize'))
  64. width = int_or_none(content.get('width'))
  65. height = int_or_none(content.get('height'))
  66. description = unescapeHTML(xpath_text(
  67. item, './description', 'description'))
  68. thumbnail = xpath_attr(
  69. item, './{http://search.yahoo.com/mrss/}thumbnail', 'url',
  70. 'thumbnail')
  71. timestamp = unified_timestamp(xpath_text(
  72. item, './{http://cms.springboardplatform.com/namespaces.html}created',
  73. 'timestamp'))
  74. formats = [{
  75. 'url': video_url,
  76. 'format_id': 'http',
  77. 'tbr': tbr,
  78. 'filesize': filesize,
  79. 'width': width,
  80. 'height': height,
  81. }]
  82. m3u8_format = formats[0].copy()
  83. m3u8_format.update({
  84. 'url': re.sub(r'(https?://)cdn\.', r'\1hls.', video_url) + '.m3u8',
  85. 'ext': 'mp4',
  86. 'format_id': 'hls',
  87. 'protocol': 'm3u8_native',
  88. })
  89. formats.append(m3u8_format)
  90. return {
  91. 'id': video_id,
  92. 'title': title,
  93. 'description': description,
  94. 'thumbnail': thumbnail,
  95. 'timestamp': timestamp,
  96. 'duration': duration,
  97. 'formats': formats,
  98. }