]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/cnn.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / cnn.py
CommitLineData
1a582dd4 1from .common import InfoExtractor
29825140 2from .turner import TurnerBaseIE
c7f540ea 3from ..utils import merge_dicts, try_call, url_basename
1a582dd4 4
273f603e 5
29825140 6class CNNIE(TurnerBaseIE):
292a2301 7 _VALID_URL = r'''(?x)https?://(?:(?P<sub_domain>edition|www|money)\.)?cnn\.com/(?:video/(?:data/.+?|\?)/)?videos?/
abca34cb 8 (?P<path>.+?/(?P<title>[^/]+?)(?:\.(?:[a-z\-]+)|(?=&)))'''
1a582dd4 9
273f603e 10 _TESTS = [{
3798eadc 11 'url': 'http://edition.cnn.com/video/?/video/sports/2013/06/09/nadal-1-on-1.cnn',
3798eadc
PH
12 'md5': '3e6121ea48df7e2259fe73a0628605c4',
13 'info_dict': {
3c77a54d 14 'id': 'sports/2013/06/09/nadal-1-on-1.cnn',
acd40f64 15 'ext': 'mp4',
3798eadc
PH
16 'title': 'Nadal wins 8th French Open title',
17 'description': 'World Sport\'s Amanda Davies chats with 2013 French Open champion Rafael Nadal.',
18 'duration': 135,
19 'upload_date': '20130609',
1a582dd4 20 },
29825140 21 'expected_warnings': ['Failed to download m3u8 information'],
9e1a5b84 22 }, {
611c1dd9
S
23 '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',
24 'md5': 'b5cc60c60a3477d185af8f19a2a26f4e',
25 'info_dict': {
3c77a54d 26 'id': 'us/2013/08/21/sot-student-gives-epic-speech.georgia-institute-of-technology',
acd40f64 27 'ext': 'mp4',
611c1dd9
S
28 'title': "Student's epic speech stuns new freshmen",
29 'description': "A Georgia Tech student welcomes the incoming freshmen with an epic speech backed by music from \"2001: A Space Odyssey.\"",
30 'upload_date': '20130821',
29825140
RA
31 },
32 'expected_warnings': ['Failed to download m3u8 information'],
429ddfd3
S
33 }, {
34 'url': 'http://www.cnn.com/video/data/2.0/video/living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln.html',
35 'md5': 'f14d02ebd264df951feb2400e2c25a1b',
36 'info_dict': {
3c77a54d 37 'id': 'living/2014/12/22/growing-america-nashville-salemtown-board-episode-1.hln',
429ddfd3
S
38 'ext': 'mp4',
39 'title': 'Nashville Ep. 1: Hand crafted skateboards',
40 'description': 'md5:e7223a503315c9f150acac52e76de086',
41 'upload_date': '20141222',
29825140
RA
42 },
43 'expected_warnings': ['Failed to download m3u8 information'],
292a2301
RA
44 }, {
45 'url': 'http://money.cnn.com/video/news/2016/08/19/netflix-stunning-stats.cnnmoney/index.html',
46 'md5': '52a515dc1b0f001cd82e4ceda32be9d1',
47 'info_dict': {
3c77a54d 48 'id': '/video/news/2016/08/19/netflix-stunning-stats.cnnmoney',
292a2301
RA
49 'ext': 'mp4',
50 'title': '5 stunning stats about Netflix',
51 '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.',
52 'upload_date': '20160819',
29825140
RA
53 },
54 'params': {
55 # m3u8 download
56 'skip_download': True,
57 },
ecb750a4
PH
58 }, {
59 'url': 'http://cnn.com/video/?/video/politics/2015/03/27/pkg-arizona-senator-church-attendance-mandatory.ktvk',
60 'only_matching': True,
29713e42
PH
61 }, {
62 'url': 'http://cnn.com/video/?/video/us/2015/04/06/dnt-baker-refuses-anti-gay-order.wkmg',
63 'only_matching': True,
292a2301
RA
64 }, {
65 'url': 'http://edition.cnn.com/videos/arts/2016/04/21/olympic-games-cultural-a-z-brazil.cnn',
66 'only_matching': True,
273f603e 67 }]
1a582dd4 68
292a2301
RA
69 _CONFIG = {
70 # http://edition.cnn.com/.element/apps/cvp/3.0/cfg/spider/cnn/expansion/config.xml
71 'edition': {
72 'data_src': 'http://edition.cnn.com/video/data/3.0/video/%s/index.xml',
73 'media_src': 'http://pmd.cdn.turner.com/cnn/big',
74 },
75 # http://money.cnn.com/.element/apps/cvp2/cfg/config.xml
76 'money': {
77 'data_src': 'http://money.cnn.com/video/data/4.0/video/%s.xml',
78 'media_src': 'http://ht3.cdn.turner.com/money/big',
79 },
80 }
81
da30a20a
RA
82 def _extract_timestamp(self, video_data):
83 # TODO: fix timestamp extraction
84 return None
85
1a582dd4 86 def _real_extract(self, url):
5ad28e7f 87 sub_domain, path, page_title = self._match_valid_url(url).groups()
292a2301
RA
88 if sub_domain not in ('money', 'edition'):
89 sub_domain = 'edition'
90 config = self._CONFIG[sub_domain]
29825140
RA
91 return self._extract_cvp_info(
92 config['data_src'] % path, page_title, {
93 'default': {
94 'media_src': config['media_src'],
29f7c58a 95 },
96 'f4m': {
97 'host': 'cnn-vh.akamaihd.net',
98 },
29825140 99 })
0ae6b019
JMF
100
101
102class CNNBlogsIE(InfoExtractor):
103 _VALID_URL = r'https?://[^\.]+\.blogs\.cnn\.com/.+'
104 _TEST = {
105 'url': 'http://reliablesources.blogs.cnn.com/2014/02/09/criminalizing-journalism/',
106 'md5': '3e56f97b0b6ffb4b79f4ea0749551084',
107 'info_dict': {
3c77a54d 108 'id': 'bestoftv/2014/02/09/criminalizing-journalism.cnn',
0ae6b019
JMF
109 'ext': 'mp4',
110 'title': 'Criminalizing journalism?',
111 'description': 'Glenn Greenwald responds to comments made this week on Capitol Hill that journalists could be criminal accessories.',
112 'upload_date': '20140209',
113 },
1fe48afe 114 'expected_warnings': ['Failed to download m3u8 information'],
0ae6b019
JMF
115 'add_ie': ['CNN'],
116 }
117
118 def _real_extract(self, url):
119 webpage = self._download_webpage(url, url_basename(url))
120 cnn_url = self._html_search_regex(r'data-url="(.+?)"', webpage, 'cnn url')
d226c560 121 return self.url_result(cnn_url, CNNIE.ie_key())
9532d723
AK
122
123
124class CNNArticleIE(InfoExtractor):
292a2301 125 _VALID_URL = r'https?://(?:(?:edition|www)\.)?cnn\.com/(?!videos?/)'
9532d723
AK
126 _TEST = {
127 'url': 'http://www.cnn.com/2014/12/21/politics/obama-north-koreas-hack-not-war-but-cyber-vandalism/',
5fe51125 128 'md5': '689034c2a3d9c6dc4aa72d65a81efd01',
9532d723 129 'info_dict': {
3c77a54d 130 'id': 'bestoftv/2014/12/21/ip-north-korea-obama.cnn',
9532d723 131 'ext': 'mp4',
5fe51125 132 'title': 'Obama: Cyberattack not an act of war',
1fe48afe 133 'description': 'md5:0a802a40d2376f60e6b04c8d5bcebc4b',
5fe51125 134 'upload_date': '20141221',
9532d723 135 },
1fe48afe 136 'expected_warnings': ['Failed to download m3u8 information'],
9532d723
AK
137 'add_ie': ['CNN'],
138 }
139
140 def _real_extract(self, url):
141 webpage = self._download_webpage(url, url_basename(url))
142 cnn_url = self._html_search_regex(r"video:\s*'([^']+)'", webpage, 'cnn url')
d226c560 143 return self.url_result('http://cnn.com/video/?/video/' + cnn_url, CNNIE.ie_key())
c7f540ea
H
144
145
146class CNNIndonesiaIE(InfoExtractor):
147 _VALID_URL = r'https?://www\.cnnindonesia\.com/[\w-]+/(?P<upload_date>\d{8})\d+-\d+-(?P<id>\d+)/(?P<display_id>[\w-]+)'
148 _TESTS = [{
149 'url': 'https://www.cnnindonesia.com/ekonomi/20220909212635-89-845885/alasan-harga-bbm-di-indonesia-masih-disubsidi',
150 'info_dict': {
151 'id': '845885',
152 'ext': 'mp4',
153 'description': 'md5:e7954bfa6f1749bc9ef0c079a719c347',
154 'upload_date': '20220909',
155 'title': 'Alasan Harga BBM di Indonesia Masih Disubsidi',
156 'timestamp': 1662859088,
157 'duration': 120.0,
158 'thumbnail': r're:https://akcdn\.detik\.net\.id/visual/2022/09/09/thumbnail-ekopedia-alasan-harga-bbm-disubsidi_169\.jpeg',
159 'tags': ['ekopedia', 'subsidi bbm', 'subsidi', 'bbm', 'bbm subsidi', 'harga pertalite naik'],
160 'age_limit': 0,
161 'release_timestamp': 1662859088,
162 'release_date': '20220911',
163 'uploader': 'Asfahan Yahsyi',
164 }
165 }, {
166 'url': 'https://www.cnnindonesia.com/internasional/20220911104341-139-846189/video-momen-charles-disambut-meriah-usai-dilantik-jadi-raja-inggris',
167 'info_dict': {
168 'id': '846189',
169 'ext': 'mp4',
170 'upload_date': '20220911',
171 'duration': 76.0,
172 'timestamp': 1662869995,
173 'description': 'md5:ece7b003b3ee7d81c6a5cfede7d5397d',
174 'thumbnail': r're:https://akcdn\.detik\.net\.id/visual/2022/09/11/thumbnail-video-1_169\.jpeg',
175 'title': 'VIDEO: Momen Charles Disambut Meriah usai Dilantik jadi Raja Inggris',
176 'tags': ['raja charles', 'raja charles iii', 'ratu elizabeth', 'ratu elizabeth meninggal dunia', 'raja inggris', 'inggris'],
177 'age_limit': 0,
178 'release_date': '20220911',
179 'uploader': 'REUTERS',
180 'release_timestamp': 1662869995,
181 }
182 }]
183
184 def _real_extract(self, url):
185 upload_date, video_id, display_id = self._match_valid_url(url).group('upload_date', 'id', 'display_id')
186 webpage = self._download_webpage(url, display_id)
187
188 json_ld_list = list(self._yield_json_ld(webpage, display_id))
189 json_ld_data = self._json_ld(json_ld_list, display_id)
190 embed_url = next(
191 json_ld.get('embedUrl') for json_ld in json_ld_list if json_ld.get('@type') == 'VideoObject')
192
193 return merge_dicts(json_ld_data, {
194 '_type': 'url_transparent',
195 'url': embed_url,
196 'upload_date': upload_date,
197 'tags': try_call(lambda: self._html_search_meta('keywords', webpage).split(', '))
198 })