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.

95 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  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/the-art-of-more/2496419',
  9. 'info_dict': {
  10. 'id': '2496419',
  11. 'ext': 'mp4',
  12. 'title': 'Heavy Lies the Head',
  13. 'description': 'md5:bb56aa0708fe7b9a4861535f15c3abca',
  14. },
  15. 'params': {
  16. # m3u8 download
  17. 'skip_download': True,
  18. }
  19. }
  20. # extracted from http://legacyweb-us.crackle.com/flash/QueryReferrer.ashx
  21. _SUBTITLE_SERVER = 'http://web-us-az.crackle.com'
  22. _UPLYNK_OWNER_ID = 'e8773f7770a44dbd886eee4fca16a66b'
  23. _THUMBNAIL_TEMPLATE = 'http://images-us-am.crackle.com/%stnl_1920x1080.jpg?ts=20140107233116?c=635333335057637614'
  24. # extracted from http://legacyweb-us.crackle.com/flash/ReferrerRedirect.ashx
  25. _MEDIA_FILE_SLOTS = {
  26. 'c544.flv': {
  27. 'width': 544,
  28. 'height': 306,
  29. },
  30. '360p.mp4': {
  31. 'width': 640,
  32. 'height': 360,
  33. },
  34. '480p.mp4': {
  35. 'width': 852,
  36. 'height': 478,
  37. },
  38. '480p_1mbps.mp4': {
  39. 'width': 852,
  40. 'height': 478,
  41. },
  42. }
  43. def _real_extract(self, url):
  44. video_id = self._match_id(url)
  45. item = self._download_xml(
  46. 'http://legacyweb-us.crackle.com/app/revamp/vidwallcache.aspx?flags=-1&fm=%s' % video_id,
  47. video_id).find('i')
  48. title = item.attrib['t']
  49. thumbnail = None
  50. subtitles = {}
  51. formats = self._extract_m3u8_formats(
  52. 'http://content.uplynk.com/ext/%s/%s.m3u8' % (self._UPLYNK_OWNER_ID, video_id),
  53. video_id, 'mp4', m3u8_id='hls', fatal=None)
  54. path = item.attrib.get('p')
  55. if path:
  56. thumbnail = self._THUMBNAIL_TEMPLATE % path
  57. http_base_url = 'http://ahttp.crackle.com/' + path
  58. for mfs_path, mfs_info in self._MEDIA_FILE_SLOTS.items():
  59. formats.append({
  60. 'url': http_base_url + mfs_path,
  61. 'format_id': 'http-' + mfs_path.split('.')[0],
  62. 'width': mfs_info['width'],
  63. 'height': mfs_info['height'],
  64. })
  65. for cc in item.findall('cc'):
  66. locale = cc.attrib.get('l')
  67. v = cc.attrib.get('v')
  68. if locale and v:
  69. if locale not in subtitles:
  70. subtitles[locale] = []
  71. subtitles[locale] = [{
  72. 'url': '%s/%s%s_%s.xml' % (self._SUBTITLE_SERVER, path, locale, v),
  73. 'ext': 'ttml',
  74. }]
  75. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  76. return {
  77. 'id': video_id,
  78. 'title': title,
  79. 'description': item.attrib.get('d'),
  80. 'duration': int(item.attrib.get('r'), 16) if item.attrib.get('r') else None,
  81. 'series': item.attrib.get('sn'),
  82. 'season_number': int_or_none(item.attrib.get('se')),
  83. 'episode_number': int_or_none(item.attrib.get('ep')),
  84. 'thumbnail': thumbnail,
  85. 'subtitles': subtitles,
  86. 'formats': formats,
  87. }