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.

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