]>
Commit | Line | Data |
---|---|---|
a63d9bd0 YC |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | try_get, | |
4 | unified_timestamp, | |
5 | ) | |
6 | ||
7 | ||
8 | class CGTNIE(InfoExtractor): | |
9 | _VALID_URL = r'https?://news\.cgtn\.com/news/[0-9]{4}-[0-9]{2}-[0-9]{2}/[a-zA-Z0-9-]+-(?P<id>[a-zA-Z0-9-]+)/index\.html' | |
10 | _TESTS = [ | |
11 | { | |
12 | 'url': 'https://news.cgtn.com/news/2021-03-09/Up-and-Out-of-Poverty-Ep-1-A-solemn-promise-YuOUaOzGQU/index.html', | |
13 | 'info_dict': { | |
14 | 'id': 'YuOUaOzGQU', | |
15 | 'ext': 'mp4', | |
16 | 'title': 'Up and Out of Poverty Ep. 1: A solemn promise', | |
17 | 'thumbnail': r're:^https?://.*\.jpg$', | |
18 | 'timestamp': 1615295940, | |
19 | 'upload_date': '20210309', | |
20 | }, | |
21 | 'params': { | |
22 | 'skip_download': True | |
23 | } | |
24 | }, { | |
25 | 'url': 'https://news.cgtn.com/news/2021-06-06/China-Indonesia-vow-to-further-deepen-maritime-cooperation-10REvJCewCY/index.html', | |
26 | 'info_dict': { | |
27 | 'id': '10REvJCewCY', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'China, Indonesia vow to further deepen maritime cooperation', | |
30 | 'thumbnail': r're:^https?://.*\.png$', | |
31 | 'description': 'China and Indonesia vowed to upgrade their cooperation into the maritime sector and also for political security, economy, and cultural and people-to-people exchanges.', | |
32 | 'author': 'CGTN', | |
33 | 'category': 'China', | |
34 | 'timestamp': 1622950200, | |
35 | 'upload_date': '20210606', | |
36 | }, | |
37 | 'params': { | |
38 | 'skip_download': False | |
39 | } | |
40 | } | |
41 | ] | |
42 | ||
43 | def _real_extract(self, url): | |
44 | video_id = self._match_id(url) | |
45 | webpage = self._download_webpage(url, video_id) | |
46 | ||
47 | download_url = self._html_search_regex(r'data-video ="(?P<url>.+m3u8)"', webpage, 'download_url') | |
48 | datetime_str = self._html_search_regex(r'<span class="date">\s*(.+?)\s*</span>', webpage, 'datetime_str', fatal=False) | |
49 | ||
50 | return { | |
51 | 'id': video_id, | |
52 | 'title': self._og_search_title(webpage), | |
53 | 'description': self._og_search_description(webpage, default=None), | |
54 | 'thumbnail': self._og_search_thumbnail(webpage), | |
55 | 'formats': self._extract_m3u8_formats(download_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls'), | |
56 | 'category': self._html_search_regex(r'<span class="section">\s*(.+?)\s*</span>', | |
57 | webpage, 'category', fatal=False), | |
58 | 'author': self._html_search_regex(r'<div class="news-author-name">\s*(.+?)\s*</div>', | |
59 | webpage, 'author', default=None, fatal=False), | |
60 | 'timestamp': try_get(unified_timestamp(datetime_str), lambda x: x - 8 * 3600), | |
61 | } |