]>
Commit | Line | Data |
---|---|---|
80f772c2 | 1 | # coding: utf-8 |
b54a2da4 YCH |
2 | from __future__ import unicode_literals, division |
3 | ||
80f772c2 | 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 = { | |
b54a2da4 | 11 | 'url': 'http://www.crackle.com/comedians-in-cars-getting-coffee/2498934', |
80f772c2 | 12 | 'info_dict': { |
b54a2da4 | 13 | 'id': '2498934', |
80f772c2 | 14 | 'ext': 'mp4', |
b54a2da4 YCH |
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 | }, | |
80f772c2 | 27 | }, |
28 | 'params': { | |
29 | # m3u8 download | |
30 | 'skip_download': True, | |
31 | } | |
32 | } | |
33 | ||
80f772c2 | 34 | # extracted from http://legacyweb-us.crackle.com/flash/ReferrerRedirect.ashx |
906b87cf | 35 | _THUMBNAIL_TEMPLATE = 'http://images-us-am.crackle.com/%stnl_1920x1080.jpg?ts=20140107233116?c=635333335057637614' |
80f772c2 | 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) | |
b54a2da4 YCH |
57 | |
58 | config_doc = self._download_xml( | |
59 | 'http://legacyweb-us.crackle.com/flash/QueryReferrer.ashx?site=16', | |
60 | video_id, 'Downloading config') | |
61 | ||
80f772c2 | 62 | item = self._download_xml( |
47d205a6 | 63 | 'http://legacyweb-us.crackle.com/app/revamp/vidwallcache.aspx?flags=-1&fm=%s' % video_id, |
64 | video_id).find('i') | |
80f772c2 | 65 | title = item.attrib['t'] |
66 | ||
80f772c2 | 67 | subtitles = {} |
47d205a6 | 68 | formats = self._extract_m3u8_formats( |
b54a2da4 | 69 | 'http://content.uplynk.com/ext/%s/%s.m3u8' % (config_doc.attrib['strUplynkOwnerId'], video_id), |
a1188d0e | 70 | video_id, 'mp4', m3u8_id='hls', fatal=None) |
906b87cf | 71 | thumbnail = None |
80f772c2 | 72 | path = item.attrib.get('p') |
73 | if path: | |
906b87cf | 74 | thumbnail = self._THUMBNAIL_TEMPLATE % path |
80f772c2 | 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, | |
a1188d0e | 79 | 'format_id': 'http-' + mfs_path.split('.')[0], |
80f772c2 | 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] = [{ | |
b54a2da4 | 90 | 'url': '%s/%s%s_%s.xml' % (config_doc.attrib['strSubtitleServer'], path, locale, v), |
80f772c2 | 91 | 'ext': 'ttml', |
92 | }] | |
47d205a6 | 93 | self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id')) |
80f772c2 | 94 | |
95 | return { | |
96 | 'id': video_id, | |
97 | 'title': title, | |
98 | 'description': item.attrib.get('d'), | |
b54a2da4 | 99 | 'duration': int(item.attrib.get('r'), 16) / 1000 if item.attrib.get('r') else None, |
80f772c2 | 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')), | |
906b87cf | 103 | 'thumbnail': thumbnail, |
80f772c2 | 104 | 'subtitles': subtitles, |
105 | 'formats': formats, | |
106 | } |