springboardplatform.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. unescapeHTML,
  7. unified_timestamp,
  8. xpath_attr,
  9. xpath_element,
  10. xpath_text,
  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. f'http://cms.springboardplatform.com/xml_feeds_advanced/index/{index}/rss3/{video_id}', video_id)
  51. item = xpath_element(video, './/item', 'item', fatal=True)
  52. content = xpath_element(
  53. item, './{http://search.yahoo.com/mrss/}content', 'content',
  54. fatal=True)
  55. title = unescapeHTML(xpath_text(item, './title', 'title', fatal=True))
  56. video_url = content.attrib['url']
  57. if 'error_video.mp4' in video_url:
  58. raise ExtractorError(
  59. f'Video {video_id} no longer exists', expected=True)
  60. duration = int_or_none(content.get('duration'))
  61. tbr = int_or_none(content.get('bitrate'))
  62. filesize = int_or_none(content.get('fileSize'))
  63. width = int_or_none(content.get('width'))
  64. height = int_or_none(content.get('height'))
  65. description = unescapeHTML(xpath_text(
  66. item, './description', 'description'))
  67. thumbnail = xpath_attr(
  68. item, './{http://search.yahoo.com/mrss/}thumbnail', 'url',
  69. 'thumbnail')
  70. timestamp = unified_timestamp(xpath_text(
  71. item, './{http://cms.springboardplatform.com/namespaces.html}created',
  72. 'timestamp'))
  73. formats = [{
  74. 'url': video_url,
  75. 'format_id': 'http',
  76. 'tbr': tbr,
  77. 'filesize': filesize,
  78. 'width': width,
  79. 'height': height,
  80. }]
  81. m3u8_format = formats[0].copy()
  82. m3u8_format.update({
  83. 'url': re.sub(r'(https?://)cdn\.', r'\1hls.', video_url) + '.m3u8',
  84. 'ext': 'mp4',
  85. 'format_id': 'hls',
  86. 'protocol': 'm3u8_native',
  87. })
  88. formats.append(m3u8_format)
  89. return {
  90. 'id': video_id,
  91. 'title': title,
  92. 'description': description,
  93. 'thumbnail': thumbnail,
  94. 'timestamp': timestamp,
  95. 'duration': duration,
  96. 'formats': formats,
  97. }