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.

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