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.

139 lines
4.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals, division
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class CrackleIE(InfoExtractor):
  6. _VALID_URL = r'(?:crackle:|https?://(?:(?:www|m)\.)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
  7. _TEST = {
  8. 'url': 'http://www.crackle.com/comedians-in-cars-getting-coffee/2498934',
  9. 'info_dict': {
  10. 'id': '2498934',
  11. 'ext': 'mp4',
  12. 'title': 'Everybody Respects A Bloody Nose',
  13. 'description': 'Jerry is kaffeeklatsching in L.A. with funnyman J.B. Smoove (Saturday Night Live, Real Husbands of Hollywood). They’re headed for brew at 10 Speed Coffee in a 1964 Studebaker Avanti.',
  14. 'thumbnail': r're:^https?://.*\.jpg',
  15. 'duration': 906,
  16. 'series': 'Comedians In Cars Getting Coffee',
  17. 'season_number': 8,
  18. 'episode_number': 4,
  19. 'subtitles': {
  20. 'en-US': [{
  21. 'ext': 'ttml',
  22. }]
  23. },
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. }
  29. }
  30. _THUMBNAIL_RES = [
  31. (120, 90),
  32. (208, 156),
  33. (220, 124),
  34. (220, 220),
  35. (240, 180),
  36. (250, 141),
  37. (315, 236),
  38. (320, 180),
  39. (360, 203),
  40. (400, 300),
  41. (421, 316),
  42. (460, 330),
  43. (460, 460),
  44. (462, 260),
  45. (480, 270),
  46. (587, 330),
  47. (640, 480),
  48. (700, 330),
  49. (700, 394),
  50. (854, 480),
  51. (1024, 1024),
  52. (1920, 1080),
  53. ]
  54. # extracted from http://legacyweb-us.crackle.com/flash/ReferrerRedirect.ashx
  55. _MEDIA_FILE_SLOTS = {
  56. 'c544.flv': {
  57. 'width': 544,
  58. 'height': 306,
  59. },
  60. '360p.mp4': {
  61. 'width': 640,
  62. 'height': 360,
  63. },
  64. '480p.mp4': {
  65. 'width': 852,
  66. 'height': 478,
  67. },
  68. '480p_1mbps.mp4': {
  69. 'width': 852,
  70. 'height': 478,
  71. },
  72. }
  73. def _real_extract(self, url):
  74. video_id = self._match_id(url)
  75. config_doc = self._download_xml(
  76. 'http://legacyweb-us.crackle.com/flash/QueryReferrer.ashx?site=16',
  77. video_id, 'Downloading config')
  78. item = self._download_xml(
  79. 'http://legacyweb-us.crackle.com/app/revamp/vidwallcache.aspx?flags=-1&fm=%s' % video_id,
  80. video_id, headers=self.geo_verification_headers()).find('i')
  81. title = item.attrib['t']
  82. subtitles = {}
  83. formats = self._extract_m3u8_formats(
  84. 'http://content.uplynk.com/ext/%s/%s.m3u8' % (config_doc.attrib['strUplynkOwnerId'], video_id),
  85. video_id, 'mp4', m3u8_id='hls', fatal=None)
  86. thumbnails = []
  87. path = item.attrib.get('p')
  88. if path:
  89. for width, height in self._THUMBNAIL_RES:
  90. res = '%dx%d' % (width, height)
  91. thumbnails.append({
  92. 'id': res,
  93. 'url': 'http://images-us-am.crackle.com/%stnl_%s.jpg' % (path, res),
  94. 'width': width,
  95. 'height': height,
  96. 'resolution': res,
  97. })
  98. http_base_url = 'http://ahttp.crackle.com/' + path
  99. for mfs_path, mfs_info in self._MEDIA_FILE_SLOTS.items():
  100. formats.append({
  101. 'url': http_base_url + mfs_path,
  102. 'format_id': 'http-' + mfs_path.split('.')[0],
  103. 'width': mfs_info['width'],
  104. 'height': mfs_info['height'],
  105. })
  106. for cc in item.findall('cc'):
  107. locale = cc.attrib.get('l')
  108. v = cc.attrib.get('v')
  109. if locale and v:
  110. if locale not in subtitles:
  111. subtitles[locale] = []
  112. for url_ext, ext in (('vtt', 'vtt'), ('xml', 'tt')):
  113. subtitles.setdefault(locale, []).append({
  114. 'url': '%s/%s%s_%s.%s' % (config_doc.attrib['strSubtitleServer'], path, locale, v, url_ext),
  115. 'ext': ext,
  116. })
  117. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  118. return {
  119. 'id': video_id,
  120. 'title': title,
  121. 'description': item.attrib.get('d'),
  122. 'duration': int(item.attrib.get('r'), 16) / 1000 if item.attrib.get('r') else None,
  123. 'series': item.attrib.get('sn'),
  124. 'season_number': int_or_none(item.attrib.get('se')),
  125. 'episode_number': int_or_none(item.attrib.get('ep')),
  126. 'thumbnails': thumbnails,
  127. 'subtitles': subtitles,
  128. 'formats': formats,
  129. }