]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/crackle.py
debian/changelog: Fix spelling of Re-enable to please lintian.
[youtubedl] / youtube_dl / extractor / crackle.py
1 # coding: utf-8
2 from __future__ import unicode_literals, division
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6
7
8 class CrackleIE(InfoExtractor):
9 _VALID_URL = r'(?:crackle:|https?://(?:www\.)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
10 _TEST = {
11 'url': 'http://www.crackle.com/comedians-in-cars-getting-coffee/2498934',
12 'info_dict': {
13 'id': '2498934',
14 'ext': 'mp4',
15 'title': 'Everybody Respects A Bloody Nose',
16 '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.',
17 'thumbnail': 're:^https?://.*\.jpg',
18 'duration': 906,
19 'series': 'Comedians In Cars Getting Coffee',
20 'season_number': 8,
21 'episode_number': 4,
22 'subtitles': {
23 'en-US': [{
24 'ext': 'ttml',
25 }]
26 },
27 },
28 'params': {
29 # m3u8 download
30 'skip_download': True,
31 }
32 }
33
34 # extracted from http://legacyweb-us.crackle.com/flash/ReferrerRedirect.ashx
35 _THUMBNAIL_TEMPLATE = 'http://images-us-am.crackle.com/%stnl_1920x1080.jpg?ts=20140107233116?c=635333335057637614'
36 _MEDIA_FILE_SLOTS = {
37 'c544.flv': {
38 'width': 544,
39 'height': 306,
40 },
41 '360p.mp4': {
42 'width': 640,
43 'height': 360,
44 },
45 '480p.mp4': {
46 'width': 852,
47 'height': 478,
48 },
49 '480p_1mbps.mp4': {
50 'width': 852,
51 'height': 478,
52 },
53 }
54
55 def _real_extract(self, url):
56 video_id = self._match_id(url)
57
58 config_doc = self._download_xml(
59 'http://legacyweb-us.crackle.com/flash/QueryReferrer.ashx?site=16',
60 video_id, 'Downloading config')
61
62 item = self._download_xml(
63 'http://legacyweb-us.crackle.com/app/revamp/vidwallcache.aspx?flags=-1&fm=%s' % video_id,
64 video_id).find('i')
65 title = item.attrib['t']
66
67 subtitles = {}
68 formats = self._extract_m3u8_formats(
69 'http://content.uplynk.com/ext/%s/%s.m3u8' % (config_doc.attrib['strUplynkOwnerId'], video_id),
70 video_id, 'mp4', m3u8_id='hls', fatal=None)
71 thumbnail = None
72 path = item.attrib.get('p')
73 if path:
74 thumbnail = self._THUMBNAIL_TEMPLATE % path
75 http_base_url = 'http://ahttp.crackle.com/' + path
76 for mfs_path, mfs_info in self._MEDIA_FILE_SLOTS.items():
77 formats.append({
78 'url': http_base_url + mfs_path,
79 'format_id': 'http-' + mfs_path.split('.')[0],
80 'width': mfs_info['width'],
81 'height': mfs_info['height'],
82 })
83 for cc in item.findall('cc'):
84 locale = cc.attrib.get('l')
85 v = cc.attrib.get('v')
86 if locale and v:
87 if locale not in subtitles:
88 subtitles[locale] = []
89 subtitles[locale] = [{
90 'url': '%s/%s%s_%s.xml' % (config_doc.attrib['strSubtitleServer'], path, locale, v),
91 'ext': 'ttml',
92 }]
93 self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
94
95 return {
96 'id': video_id,
97 'title': title,
98 'description': item.attrib.get('d'),
99 'duration': int(item.attrib.get('r'), 16) / 1000 if item.attrib.get('r') else None,
100 'series': item.attrib.get('sn'),
101 'season_number': int_or_none(item.attrib.get('se')),
102 'episode_number': int_or_none(item.attrib.get('ep')),
103 'thumbnail': thumbnail,
104 'subtitles': subtitles,
105 'formats': formats,
106 }