[turner,nba,cnn,adultswim] add base extractor to parse cvp feeds
[youtube-dl] / youtube_dl / extractor / cnn.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from .turner import TurnerBaseIE
7 from ..utils import url_basename
8
9
10 class CNNIE(TurnerBaseIE):
11     _VALID_URL = r'''(?x)https?://(?:(?P<sub_domain>edition|www|money)\.)?cnn\.com/(?:video/(?:data/.+?|\?)/)?videos?/
12         (?P<path>.+?/(?P<title>[^/]+?)(?:\.(?:[a-z\-]+)|(?=&)))'''
13
14     _TESTS = [{
15         'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn',
16         'md5': '3e6121ea48df7e2259fe73a0628605c4',
17         'info_dict': {
18             'id': 'nadal-1-on-1',
19             'ext': 'mp4',
20             'title': 'Nadal wins 8th French Open title',
21             'description': 'World Sport\'s Amanda Davies chats with 2013 French Open champion Rafael Nadal.',
22             'duration': 135,
23             'upload_date': '20130609',
24         },
25         'expected_warnings': ['Failed to download m3u8 information'],
26     }, {
27         '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',
28         'md5': 'b5cc60c60a3477d185af8f19a2a26f4e',
29         'info_dict': {
30             'id': 'sot-student-gives-epic-speech',
31             'ext': 'mp4',
32             'title': "Student's epic speech stuns new freshmen",
33             'description': "A Georgia Tech student welcomes the incoming freshmen with an epic speech backed by music from \"2001: A Space Odyssey.\"",
34             'upload_date': '20130821',
35         },
36         'expected_warnings': ['Failed to download m3u8 information'],
37     }, {
38         'url': 'http://www.cnn.com/video/data/2.0/video/living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln.html',
39         'md5': 'f14d02ebd264df951feb2400e2c25a1b',
40         'info_dict': {
41             'id': 'growing-america-nashville-salemtown-board-episode-1',
42             'ext': 'mp4',
43             'title': 'Nashville Ep. 1: Hand crafted skateboards',
44             'description': 'md5:e7223a503315c9f150acac52e76de086',
45             'upload_date': '20141222',
46         },
47         'expected_warnings': ['Failed to download m3u8 information'],
48     }, {
49         'url': 'http://money.cnn.com/video/news/2016/08/19/netflix-stunning-stats.cnnmoney/index.html',
50         'md5': '52a515dc1b0f001cd82e4ceda32be9d1',
51         'info_dict': {
52             'id': 'netflix-stunning-stats',
53             'ext': 'mp4',
54             'title': '5 stunning stats about Netflix',
55             'description': 'Did you know that Netflix has more than 80 million members? Here are five facts about the online video distributor that you probably didn\'t know.',
56             'upload_date': '20160819',
57         },
58         'params': {
59             # m3u8 download
60             'skip_download': True,
61         },
62     }, {
63         'url': 'http://cnn.com/video/?/video/politics/2015/03/27/pkg-arizona-senator-church-attendance-mandatory.ktvk',
64         'only_matching': True,
65     }, {
66         'url': 'http://cnn.com/video/?/video/us/2015/04/06/dnt-baker-refuses-anti-gay-order.wkmg',
67         'only_matching': True,
68     }, {
69         'url': 'http://edition.cnn.com/videos/arts/2016/04/21/olympic-games-cultural-a-z-brazil.cnn',
70         'only_matching': True,
71     }]
72
73     _CONFIG = {
74         # http://edition.cnn.com/.element/apps/cvp/3.0/cfg/spider/cnn/expansion/config.xml
75         'edition': {
76             'data_src': 'http://edition.cnn.com/video/data/3.0/video/%s/index.xml',
77             'media_src': 'http://pmd.cdn.turner.com/cnn/big',
78         },
79         # http://money.cnn.com/.element/apps/cvp2/cfg/config.xml
80         'money': {
81             'data_src': 'http://money.cnn.com/video/data/4.0/video/%s.xml',
82             'media_src': 'http://ht3.cdn.turner.com/money/big',
83         },
84     }
85
86     def _real_extract(self, url):
87         sub_domain, path, page_title = re.match(self._VALID_URL, url).groups()
88         if sub_domain not in ('money', 'edition'):
89             sub_domain = 'edition'
90         config = self._CONFIG[sub_domain]
91         return self._extract_cvp_info(
92             config['data_src'] % path, page_title, {
93                 'default': {
94                     'media_src': config['media_src'],
95                 }
96             })
97
98
99 class CNNBlogsIE(InfoExtractor):
100     _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
101     _TEST = {
102         'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
103         'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
104         'info_dict': {
105             'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
106             'ext': 'mp4',
107             'title': 'Criminalizing journalism?',
108             'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
109             'upload_date': '20140209',
110         },
111         'add_ie': ['CNN'],
112     }
113
114     def _real_extract(self, url):
115         webpage = self._download_webpage(url, url_basename(url))
116         cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
117         return {
118             '_type': 'url',
119             'url': cnn_url,
120             'ie_key': CNNIE.ie_key(),
121         }
122
123
124 class CNNArticleIE(InfoExtractor):
125     _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!videos?/)'
126     _TEST = {
127         'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
128         'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
129         'info_dict': {
130             'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
131             'ext': 'mp4',
132             'title': 'Obama: Cyberattack not an act of war',
133             'description': 'md5:51ce6750450603795cad0cdfbd7d05c5',
134             'upload_date': '20141221',
135         },
136         'add_ie': ['CNN'],
137     }
138
139     def _real_extract(self, url):
140         webpage = self._download_webpage(url, url_basename(url))
141         cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
142         return {
143             '_type': 'url',
144             'url': 'http://cnn.com/video/?/video/' + cnn_url,
145             'ie_key': CNNIE.ie_key(),
146         }