]>
Commit | Line | Data |
---|---|---|
3798eadc PH |
1 | from __future__ import unicode_literals |
2 | ||
1a582dd4 | 3 | import re |
1a582dd4 JMF |
4 | |
5 | from .common import InfoExtractor | |
608d11f5 PH |
6 | from ..utils import ( |
7 | int_or_none, | |
8 | parse_duration, | |
0ae6b019 | 9 | url_basename, |
608d11f5 | 10 | ) |
1a582dd4 | 11 | |
273f603e | 12 | |
1a582dd4 | 13 | class CNNIE(InfoExtractor): |
7fc2cd81 S |
14 | _VALID_URL = r'''(?x)https?://(?:(?:edition|www)\.)?cnn\.com/video/(?:data/.+?|\?)/ |
15 | (?P<path>.+?/(?P<title>[^/]+?)(?:\.cnn(?:-ap)?|(?=&)))''' | |
1a582dd4 | 16 | |
273f603e | 17 | _TESTS = [{ |
3798eadc | 18 | 'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn', |
3798eadc PH |
19 | 'md5': '3e6121ea48df7e2259fe73a0628605c4', |
20 | 'info_dict': { | |
7fc2cd81 | 21 | 'id': 'sports/2013/06/09/nadal-1-on-1.cnn', |
acd40f64 | 22 | 'ext': 'mp4', |
3798eadc PH |
23 | 'title': 'Nadal wins 8th French Open title', |
24 | 'description': 'World Sport\'s Amanda Davies chats with 2013 French Open champion Rafael Nadal.', | |
25 | 'duration': 135, | |
26 | 'upload_date': '20130609', | |
1a582dd4 | 27 | }, |
9e1a5b84 | 28 | }, { |
877bfd69 | 29 | "url": "http://edition.cnn.com/video/?/video/us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+rss%2Fcnn_topstories+%28RSS%3A+Top+Stories%29", |
877bfd69 PH |
30 | "md5": "b5cc60c60a3477d185af8f19a2a26f4e", |
31 | "info_dict": { | |
acd40f64 PH |
32 | 'id': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology', |
33 | 'ext': 'mp4', | |
877bfd69 PH |
34 | "title": "Student's epic speech stuns new freshmen", |
35 | "description": "A Georgia Tech student welcomes the incoming freshmen with an epic speech backed by music from \"2001: A Space Odyssey.\"", | |
36 | "upload_date": "20130821", | |
273f603e PH |
37 | } |
38 | }] | |
1a582dd4 JMF |
39 | |
40 | def _real_extract(self, url): | |
41 | mobj = re.match(self._VALID_URL, url) | |
42 | path = mobj.group('path') | |
43 | page_title = mobj.group('title') | |
3798eadc | 44 | info_url = 'http://cnn.com/video/data/3.0/%s/index.xml' % path |
e26f8712 | 45 | info = self._download_xml(info_url, page_title) |
1a582dd4 JMF |
46 | |
47 | formats = [] | |
608d11f5 PH |
48 | rex = re.compile(r'''(?x) |
49 | (?P<width>[0-9]+)x(?P<height>[0-9]+) | |
50 | (?:_(?P<bitrate>[0-9]+)k)? | |
51 | ''') | |
1a582dd4 | 52 | for f in info.findall('files/file'): |
608d11f5 PH |
53 | video_url = 'http://ht.cdn.turner.com/cnn/big%s' % (f.text.strip()) |
54 | fdct = { | |
55 | 'format_id': f.attrib['bitrate'], | |
56 | 'url': video_url, | |
57 | } | |
58 | ||
59 | mf = rex.match(f.attrib['bitrate']) | |
60 | if mf: | |
61 | fdct['width'] = int(mf.group('width')) | |
62 | fdct['height'] = int(mf.group('height')) | |
63 | fdct['tbr'] = int_or_none(mf.group('bitrate')) | |
64 | else: | |
65 | mf = rex.search(f.text) | |
66 | if mf: | |
67 | fdct['width'] = int(mf.group('width')) | |
68 | fdct['height'] = int(mf.group('height')) | |
69 | fdct['tbr'] = int_or_none(mf.group('bitrate')) | |
70 | else: | |
71 | mi = re.match(r'ios_(audio|[0-9]+)$', f.attrib['bitrate']) | |
72 | if mi: | |
73 | if mi.group(1) == 'audio': | |
74 | fdct['vcodec'] = 'none' | |
75 | fdct['ext'] = 'm4a' | |
76 | else: | |
77 | fdct['tbr'] = int(mi.group(1)) | |
78 | ||
79 | formats.append(fdct) | |
80 | ||
81 | self._sort_formats(formats) | |
1a582dd4 | 82 | |
be6d7229 PH |
83 | thumbnails = [{ |
84 | 'height': int(t.attrib['height']), | |
85 | 'width': int(t.attrib['width']), | |
86 | 'url': t.text, | |
87 | } for t in info.findall('images/image')] | |
1a582dd4 | 88 | |
608d11f5 PH |
89 | metas_el = info.find('metas') |
90 | upload_date = ( | |
91 | metas_el.attrib.get('version') if metas_el is not None else None) | |
92 | ||
93 | duration_el = info.find('length') | |
94 | duration = parse_duration(duration_el.text) | |
95 | ||
96 | return { | |
97 | 'id': info.attrib['id'], | |
98 | 'title': info.find('headline').text, | |
99 | 'formats': formats, | |
be6d7229 | 100 | 'thumbnails': thumbnails, |
608d11f5 PH |
101 | 'description': info.find('description').text, |
102 | 'duration': duration, | |
103 | 'upload_date': upload_date, | |
104 | } | |
0ae6b019 JMF |
105 | |
106 | ||
107 | class CNNBlogsIE(InfoExtractor): | |
108 | _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+' | |
109 | _TEST = { | |
110 | 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/', | |
111 | 'md5': '3e56f97b0b6ffb4b79f4ea0749551084', | |
112 | 'info_dict': { | |
113 | 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn', | |
114 | 'ext': 'mp4', | |
115 | 'title': 'Criminalizing journalism?', | |
116 | 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.', | |
117 | 'upload_date': '20140209', | |
118 | }, | |
119 | 'add_ie': ['CNN'], | |
120 | } | |
121 | ||
122 | def _real_extract(self, url): | |
123 | webpage = self._download_webpage(url, url_basename(url)) | |
124 | cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url') | |
125 | return { | |
126 | '_type': 'url', | |
127 | 'url': cnn_url, | |
128 | 'ie_key': CNNIE.ie_key(), | |
129 | } | |
9532d723 AK |
130 | |
131 | ||
132 | class CNNArticleIE(InfoExtractor): | |
7fc2cd81 | 133 | _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!video/)' |
9532d723 AK |
134 | _TEST = { |
135 | 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/', | |
136 | 'md5': '275b326f85d80dff7592a9820f5dc887', | |
137 | 'info_dict': { | |
138 | 'id': 'bestoftv/2014/12/21/sotu-crowley-president-obama-north-korea-not-going-to-be-intimidated.cnn', | |
139 | 'ext': 'mp4', | |
140 | 'title': 'Obama: We\'re not going to be intimidated', | |
141 | 'description': 'md5:e735586f3dc936075fa654a4d91b21f9', | |
142 | 'upload_date': '20141220', | |
143 | }, | |
144 | 'add_ie': ['CNN'], | |
145 | } | |
146 | ||
147 | def _real_extract(self, url): | |
148 | webpage = self._download_webpage(url, url_basename(url)) | |
149 | cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url') | |
150 | return { | |
151 | '_type': 'url', | |
7fc2cd81 | 152 | 'url': 'http://cnn.com/video/?/video/' + cnn_url, |
9532d723 AK |
153 | 'ie_key': CNNIE.ie_key(), |
154 | } |