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.

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