]>
Commit | Line | Data |
---|---|---|
1 | # -*- coding: utf-8 -*- | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import parse_iso8601, ExtractorError | |
6 | ||
7 | ||
8 | class CtsNewsIE(InfoExtractor): | |
9 | IE_DESC = '華視新聞' | |
10 | # https connection failed (Connection reset) | |
11 | _VALID_URL = r'https?://news\.cts\.com\.tw/[a-z]+/[a-z]+/\d+/(?P<id>\d+)\.html' | |
12 | _TESTS = [{ | |
13 | 'url': 'http://news.cts.com.tw/cts/international/201501/201501291578109.html', | |
14 | 'md5': 'a9875cb790252b08431186d741beaabe', | |
15 | 'info_dict': { | |
16 | 'id': '201501291578109', | |
17 | 'ext': 'mp4', | |
18 | 'title': '以色列.真主黨交火 3人死亡', | |
19 | 'description': 'md5:95e9b295c898b7ff294f09d450178d7d', | |
20 | 'timestamp': 1422528540, | |
21 | 'upload_date': '20150129', | |
22 | } | |
23 | }, { | |
24 | # News count not appear on page but still available in database | |
25 | 'url': 'http://news.cts.com.tw/cts/international/201309/201309031304098.html', | |
26 | 'md5': '3aee7e0df7cdff94e43581f54c22619e', | |
27 | 'info_dict': { | |
28 | 'id': '201309031304098', | |
29 | 'ext': 'mp4', | |
30 | 'title': '韓國31歲童顏男 貌如十多歲小孩', | |
31 | 'description': 'md5:f183feeba3752b683827aab71adad584', | |
32 | 'thumbnail': 're:^https?://.*\.jpg$', | |
33 | 'timestamp': 1378205880, | |
34 | 'upload_date': '20130903', | |
35 | } | |
36 | }, { | |
37 | # With Youtube embedded video | |
38 | 'url': 'http://news.cts.com.tw/cts/money/201501/201501291578003.html', | |
39 | 'md5': '1d842c771dc94c8c3bca5af2cc1db9c5', | |
40 | 'add_ie': ['Youtube'], | |
41 | 'info_dict': { | |
42 | 'id': 'OVbfO7d0_hQ', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'iPhone6熱銷 蘋果財報亮眼', | |
45 | 'description': 'md5:f395d4f485487bb0f992ed2c4b07aa7d', | |
46 | 'thumbnail': 're:^https?://.*\.jpg$', | |
47 | 'upload_date': '20150128', | |
48 | 'uploader_id': 'TBSCTS', | |
49 | 'uploader': '中華電視公司', | |
50 | } | |
51 | }] | |
52 | ||
53 | def _real_extract(self, url): | |
54 | news_id = self._match_id(url) | |
55 | page = self._download_webpage(url, news_id) | |
56 | ||
57 | if self._search_regex(r'(CTSPlayer2)', page, 'CTSPlayer2 identifier', default=None): | |
58 | feed_url = self._html_search_regex( | |
59 | r'(http://news\.cts\.com\.tw/action/mp4feed\.php\?news_id=\d+)', | |
60 | page, 'feed url') | |
61 | video_url = self._download_webpage( | |
62 | feed_url, news_id, note='Fetching feed') | |
63 | else: | |
64 | self.to_screen('Not CTSPlayer video, trying Youtube...') | |
65 | youtube_url = self._search_regex( | |
66 | r'src="(//www\.youtube\.com/embed/[^"]+)"', page, 'youtube url', | |
67 | default=None) | |
68 | if not youtube_url: | |
69 | raise ExtractorError('The news includes no videos!', expected=True) | |
70 | ||
71 | return { | |
72 | '_type': 'url', | |
73 | 'url': youtube_url, | |
74 | 'ie_key': 'Youtube', | |
75 | } | |
76 | ||
77 | description = self._html_search_meta('description', page) | |
78 | title = self._html_search_meta('title', page) | |
79 | thumbnail = self._html_search_meta('image', page) | |
80 | ||
81 | datetime_str = self._html_search_regex( | |
82 | r'(\d{4}/\d{2}/\d{2} \d{2}:\d{2})', page, 'date and time') | |
83 | # Transform into ISO 8601 format with timezone info | |
84 | datetime_str = datetime_str.replace('/', '-') + ':00+0800' | |
85 | timestamp = parse_iso8601(datetime_str, delimiter=' ') | |
86 | ||
87 | return { | |
88 | 'id': news_id, | |
89 | 'url': video_url, | |
90 | 'title': title, | |
91 | 'description': description, | |
92 | 'thumbnail': thumbnail, | |
93 | 'timestamp': timestamp, | |
94 | } |