]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/cnn.py
[generic] Set rss `guid` as video id (#2741)
[yt-dlp.git] / yt_dlp / extractor / cnn.py
CommitLineData
3798eadc
PH
1from __future__ import unicode_literals
2
1a582dd4
JMF
3
4from .common import InfoExtractor
29825140
RA
5from .turner import TurnerBaseIE
6from ..utils import url_basename
1a582dd4 7
273f603e 8
29825140 9class CNNIE(TurnerBaseIE):
292a2301 10 _VALID_URL = r'''(?x)https?://(?:(?P<sub_domain>edition|www|money)\.)?cnn\.com/(?:video/(?:data/.+?|\?)/)?videos?/
abca34cb 11 (?P<path>.+?/(?P<title>[^/]+?)(?:\.(?:[a-z\-]+)|(?=&)))'''
1a582dd4 12
273f603e 13 _TESTS = [{
3798eadc 14 'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn',
3798eadc
PH
15 'md5': '3e6121ea48df7e2259fe73a0628605c4',
16 'info_dict': {
3c77a54d 17 'id': 'sports/2013/06/09/nadal-1-on-1.cnn',
acd40f64 18 'ext': 'mp4',
3798eadc
PH
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',
1a582dd4 23 },
29825140 24 'expected_warnings': ['Failed to download m3u8 information'],
9e1a5b84 25 }, {
611c1dd9
S
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': {
3c77a54d 29 'id': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology',
acd40f64 30 'ext': 'mp4',
611c1dd9
S
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',
29825140
RA
34 },
35 'expected_warnings': ['Failed to download m3u8 information'],
429ddfd3
S
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': {
3c77a54d 40 'id': 'living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln',
429ddfd3
S
41 'ext': 'mp4',
42 'title': 'Nashville Ep. 1: Hand crafted skateboards',
43 'description': 'md5:e7223a503315c9f150acac52e76de086',
44 'upload_date': '20141222',
29825140
RA
45 },
46 'expected_warnings': ['Failed to download m3u8 information'],
292a2301
RA
47 }, {
48 'url': 'http://money.cnn.com/video/news/2016/08/19/netflix-stunning-stats.cnnmoney/index.html',
49 'md5': '52a515dc1b0f001cd82e4ceda32be9d1',
50 'info_dict': {
3c77a54d 51 'id': '/video/news/2016/08/19/netflix-stunning-stats.cnnmoney',
292a2301
RA
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',
29825140
RA
56 },
57 'params': {
58 # m3u8 download
59 'skip_download': True,
60 },
ecb750a4
PH
61 }, {
62 'url': 'http://cnn.com/video/?/video/politics/2015/03/27/pkg-arizona-senator-church-attendance-mandatory.ktvk',
63 'only_matching': True,
29713e42
PH
64 }, {
65 'url': 'http://cnn.com/video/?/video/us/2015/04/06/dnt-baker-refuses-anti-gay-order.wkmg',
66 'only_matching': True,
292a2301
RA
67 }, {
68 'url': 'http://edition.cnn.com/videos/arts/2016/04/21/olympic-games-cultural-a-z-brazil.cnn',
69 'only_matching': True,
273f603e 70 }]
1a582dd4 71
292a2301
RA
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
da30a20a
RA
85 def _extract_timestamp(self, video_data):
86 # TODO: fix timestamp extraction
87 return None
88
1a582dd4 89 def _real_extract(self, url):
5ad28e7f 90 sub_domain, path, page_title = self._match_valid_url(url).groups()
292a2301
RA
91 if sub_domain not in ('money', 'edition'):
92 sub_domain = 'edition'
93 config = self._CONFIG[sub_domain]
29825140
RA
94 return self._extract_cvp_info(
95 config['data_src'] % path, page_title, {
96 'default': {
97 'media_src': config['media_src'],
29f7c58a 98 },
99 'f4m': {
100 'host': 'cnn-vh.akamaihd.net',
101 },
29825140 102 })
0ae6b019
JMF
103
104
105class 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': {
3c77a54d 111 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
0ae6b019
JMF
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 },
1fe48afe 117 'expected_warnings': ['Failed to download m3u8 information'],
0ae6b019
JMF
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')
d226c560 124 return self.url_result(cnn_url, CNNIE.ie_key())
9532d723
AK
125
126
127class CNNArticleIE(InfoExtractor):
292a2301 128 _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!videos?/)'
9532d723
AK
129 _TEST = {
130 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
5fe51125 131 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
9532d723 132 'info_dict': {
3c77a54d 133 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
9532d723 134 'ext': 'mp4',
5fe51125 135 'title': 'Obama: Cyberattack not an act of war',
1fe48afe 136 'description': 'md5:0a802a40d2376f60e6b04c8d5bcebc4b',
5fe51125 137 'upload_date': '20141221',
9532d723 138 },
1fe48afe 139 'expected_warnings': ['Failed to download m3u8 information'],
9532d723
AK
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')
d226c560 146 return self.url_result('http://cnn.com/video/?/video/' + cnn_url, CNNIE.ie_key())