crackle.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # coding: utf-8
  2. from __future__ import unicode_literals, division
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class CrackleIE(InfoExtractor):
  7. _VALID_URL = r'(?:crackle:|https?://(?:www\.)?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': '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. # extracted from http://legacyweb-us.crackle.com/flash/ReferrerRedirect.ashx
  32. _MEDIA_FILE_SLOTS = {
  33. 'c544.flv': {
  34. 'width': 544,
  35. 'height': 306,
  36. },
  37. '360p.mp4': {
  38. 'width': 640,
  39. 'height': 360,
  40. },
  41. '480p.mp4': {
  42. 'width': 852,
  43. 'height': 478,
  44. },
  45. '480p_1mbps.mp4': {
  46. 'width': 852,
  47. 'height': 478,
  48. },
  49. }
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. config_doc = self._download_xml(
  53. 'http://legacyweb-us.crackle.com/flash/QueryReferrer.ashx?site=16',
  54. video_id, 'Downloading config')
  55. item = self._download_xml(
  56. 'http://legacyweb-us.crackle.com/app/revamp/vidwallcache.aspx?flags=-1&fm=%s' % video_id,
  57. video_id).find('i')
  58. title = item.attrib['t']
  59. subtitles = {}
  60. formats = self._extract_m3u8_formats(
  61. 'http://content.uplynk.com/ext/%s/%s.m3u8' % (config_doc.attrib['strUplynkOwnerId'], video_id),
  62. video_id, 'mp4', m3u8_id='hls', fatal=None)
  63. path = item.attrib.get('p')
  64. if path:
  65. http_base_url = 'http://ahttp.crackle.com/' + path
  66. for mfs_path, mfs_info in self._MEDIA_FILE_SLOTS.items():
  67. formats.append({
  68. 'url': http_base_url + mfs_path,
  69. 'format_id': 'http-' + mfs_path.split('.')[0],
  70. 'width': mfs_info['width'],
  71. 'height': mfs_info['height'],
  72. })
  73. for cc in item.findall('cc'):
  74. locale = cc.attrib.get('l')
  75. v = cc.attrib.get('v')
  76. if locale and v:
  77. if locale not in subtitles:
  78. subtitles[locale] = []
  79. subtitles[locale] = [{
  80. 'url': '%s/%s%s_%s.xml' % (config_doc.attrib['strSubtitleServer'], path, locale, v),
  81. 'ext': 'ttml',
  82. }]
  83. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  84. media_details = self._download_json(
  85. 'https://web-api-us.crackle.com/Service.svc/details/media/%s/TW?format=json' % video_id,
  86. video_id, fatal=False)
  87. thumbnails = []
  88. if media_details:
  89. for key, value in media_details.items():
  90. mobj = re.match('^Thumbnail_(\d+)x(\d+)$', key)
  91. if mobj:
  92. width, height = list(map(int, mobj.groups()))
  93. thumbnails.append({
  94. 'id': '%dp' % height,
  95. 'url': value,
  96. 'width': width,
  97. 'height': height,
  98. })
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'description': item.attrib.get('d'),
  103. 'duration': int(item.attrib.get('r'), 16) / 1000 if item.attrib.get('r') else None,
  104. 'series': item.attrib.get('sn'),
  105. 'season_number': int_or_none(item.attrib.get('se')),
  106. 'episode_number': int_or_none(item.attrib.get('ep')),
  107. 'thumbnails': thumbnails,
  108. 'subtitles': subtitles,
  109. 'formats': formats,
  110. }