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