]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cnn.py
Update upstream source from tag 'upstream/2019.06.08'
[youtubedl] / 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': 'sports/2013/06/09/nadal-1-on-1.cnn',
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': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology',
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': 'living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln',
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': '/video/news/2016/08/19/netflix-stunning-stats.cnnmoney',
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 _extract_timestamp(self, video_data):
87 # TODO: fix timestamp extraction
88 return None
89
90 def _real_extract(self, url):
91 sub_domain, path, page_title = re.match(self._VALID_URL, url).groups()
92 if sub_domain not in ('money', 'edition'):
93 sub_domain = 'edition'
94 config = self._CONFIG[sub_domain]
95 return self._extract_cvp_info(
96 config['data_src'] % path, page_title, {
97 'default': {
98 'media_src': config['media_src'],
99 }
100 })
101
102
103 class CNNBlogsIE(InfoExtractor):
104 _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
105 _TEST = {
106 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
107 'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
108 'info_dict': {
109 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
110 'ext': 'mp4',
111 'title': 'Criminalizing journalism?',
112 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
113 'upload_date': '20140209',
114 },
115 'expected_warnings': ['Failed to download m3u8 information'],
116 'add_ie': ['CNN'],
117 }
118
119 def _real_extract(self, url):
120 webpage = self._download_webpage(url, url_basename(url))
121 cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
122 return self.url_result(cnn_url, CNNIE.ie_key())
123
124
125 class CNNArticleIE(InfoExtractor):
126 _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!videos?/)'
127 _TEST = {
128 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
129 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
130 'info_dict': {
131 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
132 'ext': 'mp4',
133 'title': 'Obama: Cyberattack not an act of war',
134 'description': 'md5:0a802a40d2376f60e6b04c8d5bcebc4b',
135 'upload_date': '20141221',
136 },
137 'expected_warnings': ['Failed to download m3u8 information'],
138 'add_ie': ['CNN'],
139 }
140
141 def _real_extract(self, url):
142 webpage = self._download_webpage(url, url_basename(url))
143 cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
144 return self.url_result('http://cnn.com/video/?/video/' + cnn_url, CNNIE.ie_key())