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.

125 lines
4.1 KiB

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