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