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.

106 lines
3.9 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\.)?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': '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. # extracted from http://legacyweb-us.crackle.com/flash/ReferrerRedirect.ashx
  31. _THUMBNAIL_TEMPLATE = 'http://images-us-am.crackle.com/%stnl_1920x1080.jpg?ts=20140107233116?c=635333335057637614'
  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. thumbnail = None
  64. path = item.attrib.get('p')
  65. if path:
  66. thumbnail = self._THUMBNAIL_TEMPLATE % path
  67. http_base_url = 'http://ahttp.crackle.com/' + path
  68. for mfs_path, mfs_info in self._MEDIA_FILE_SLOTS.items():
  69. formats.append({
  70. 'url': http_base_url + mfs_path,
  71. 'format_id': 'http-' + mfs_path.split('.')[0],
  72. 'width': mfs_info['width'],
  73. 'height': mfs_info['height'],
  74. })
  75. for cc in item.findall('cc'):
  76. locale = cc.attrib.get('l')
  77. v = cc.attrib.get('v')
  78. if locale and v:
  79. if locale not in subtitles:
  80. subtitles[locale] = []
  81. subtitles[locale] = [{
  82. 'url': '%s/%s%s_%s.xml' % (config_doc.attrib['strSubtitleServer'], path, locale, v),
  83. 'ext': 'ttml',
  84. }]
  85. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  86. return {
  87. 'id': video_id,
  88. 'title': title,
  89. 'description': item.attrib.get('d'),
  90. 'duration': int(item.attrib.get('r'), 16) / 1000 if item.attrib.get('r') else None,
  91. 'series': item.attrib.get('sn'),
  92. 'season_number': int_or_none(item.attrib.get('se')),
  93. 'episode_number': int_or_none(item.attrib.get('ep')),
  94. 'thumbnail': thumbnail,
  95. 'subtitles': subtitles,
  96. 'formats': formats,
  97. }