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.

143 lines
5.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. int_or_none,
  7. parse_age_limit,
  8. )
  9. class BreakIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?(?P<site>break|screenjunkies)\.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)'
  11. _TESTS = [{
  12. 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
  13. 'info_dict': {
  14. 'id': '2468056',
  15. 'ext': 'mp4',
  16. 'title': 'When Girls Act Like D-Bags',
  17. 'age_limit': 13,
  18. }
  19. }, {
  20. 'url': 'http://www.screenjunkies.com/video/best-quentin-tarantino-movie-2841915',
  21. 'md5': '5c2b686bec3d43de42bde9ec047536b0',
  22. 'info_dict': {
  23. 'id': '2841915',
  24. 'display_id': 'best-quentin-tarantino-movie',
  25. 'ext': 'mp4',
  26. 'title': 'Best Quentin Tarantino Movie',
  27. 'thumbnail': r're:^https?://.*\.jpg',
  28. 'duration': 3671,
  29. 'age_limit': 13,
  30. 'tags': list,
  31. },
  32. }, {
  33. 'url': 'http://www.screenjunkies.com/video/honest-trailers-the-dark-knight',
  34. 'info_dict': {
  35. 'id': '2348808',
  36. 'display_id': 'honest-trailers-the-dark-knight',
  37. 'ext': 'mp4',
  38. 'title': 'Honest Trailers - The Dark Knight',
  39. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  40. 'age_limit': 10,
  41. 'tags': list,
  42. },
  43. }, {
  44. # requires subscription but worked around
  45. 'url': 'http://www.screenjunkies.com/video/knocking-dead-ep-1-the-show-so-far-3003285',
  46. 'info_dict': {
  47. 'id': '3003285',
  48. 'display_id': 'knocking-dead-ep-1-the-show-so-far',
  49. 'ext': 'mp4',
  50. 'title': 'State of The Dead Recap: Knocking Dead Pilot',
  51. 'thumbnail': r're:^https?://.*\.jpg',
  52. 'duration': 3307,
  53. 'age_limit': 13,
  54. 'tags': list,
  55. },
  56. }, {
  57. 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
  58. 'only_matching': True,
  59. }]
  60. _DEFAULT_BITRATES = (48, 150, 320, 496, 864, 2240, 3264)
  61. def _real_extract(self, url):
  62. site, display_id, video_id = re.match(self._VALID_URL, url).groups()
  63. if not video_id:
  64. webpage = self._download_webpage(url, display_id)
  65. video_id = self._search_regex(
  66. (r'src=["\']/embed/(\d+)', r'data-video-content-id=["\'](\d+)'),
  67. webpage, 'video id')
  68. webpage = self._download_webpage(
  69. 'http://www.%s.com/embed/%s' % (site, video_id),
  70. display_id, 'Downloading video embed page')
  71. embed_vars = self._parse_json(
  72. self._search_regex(
  73. r'(?s)embedVars\s*=\s*({.+?})\s*</script>', webpage, 'embed vars'),
  74. display_id)
  75. youtube_id = embed_vars.get('youtubeId')
  76. if youtube_id:
  77. return self.url_result(youtube_id, 'Youtube')
  78. title = embed_vars['contentName']
  79. formats = []
  80. bitrates = []
  81. for f in embed_vars.get('media', []):
  82. if not f.get('uri') or f.get('mediaPurpose') != 'play':
  83. continue
  84. bitrate = int_or_none(f.get('bitRate'))
  85. if bitrate:
  86. bitrates.append(bitrate)
  87. formats.append({
  88. 'url': f['uri'],
  89. 'format_id': 'http-%d' % bitrate if bitrate else 'http',
  90. 'width': int_or_none(f.get('width')),
  91. 'height': int_or_none(f.get('height')),
  92. 'tbr': bitrate,
  93. 'format': 'mp4',
  94. })
  95. if not bitrates:
  96. # When subscriptionLevel > 0, i.e. plus subscription is required
  97. # media list will be empty. However, hds and hls uris are still
  98. # available. We can grab them assuming bitrates to be default.
  99. bitrates = self._DEFAULT_BITRATES
  100. auth_token = embed_vars.get('AuthToken')
  101. def construct_manifest_url(base_url, ext):
  102. pieces = [base_url]
  103. pieces.extend([compat_str(b) for b in bitrates])
  104. pieces.append('_kbps.mp4.%s?%s' % (ext, auth_token))
  105. return ','.join(pieces)
  106. if bitrates and auth_token:
  107. hds_url = embed_vars.get('hdsUri')
  108. if hds_url:
  109. formats.extend(self._extract_f4m_formats(
  110. construct_manifest_url(hds_url, 'f4m'),
  111. display_id, f4m_id='hds', fatal=False))
  112. hls_url = embed_vars.get('hlsUri')
  113. if hls_url:
  114. formats.extend(self._extract_m3u8_formats(
  115. construct_manifest_url(hls_url, 'm3u8'),
  116. display_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  117. self._sort_formats(formats)
  118. return {
  119. 'id': video_id,
  120. 'display_id': display_id,
  121. 'title': title,
  122. 'thumbnail': embed_vars.get('thumbUri'),
  123. 'duration': int_or_none(embed_vars.get('videoLengthInSeconds')) or None,
  124. 'age_limit': parse_age_limit(embed_vars.get('audienceRating')),
  125. 'tags': embed_vars.get('tags', '').split(','),
  126. 'formats': formats,
  127. }