]>
Commit | Line | Data |
---|---|---|
367cc95a YCH |
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 | _VALID_URL = r'http://news\.cts\.com\.tw/[a-z]+/[a-z]+/\d+/(?P<id>\d+)\.html' | |
10 | _TESTS = [{ | |
11 | 'url': 'http://news.cts.com.tw/cts/international/201309/201309031304098.html', | |
12 | 'md5': '3aee7e0df7cdff94e43581f54c22619e', | |
13 | 'info_dict': { | |
14 | 'id': '201309031304098', | |
15 | 'ext': 'mp4', | |
16 | 'title': '韓國31歲童顏男 貌如十多歲小孩', | |
17 | 'description': 'md5:f183feeba3752b683827aab71adad584', | |
18 | 'thumbnail': 're:^https?://.*\.jpg$', | |
19 | 'timestamp': 1378205880, | |
20 | 'upload_date': '20130903', | |
21 | } | |
22 | }] | |
23 | ||
24 | def _real_extract(self, url): | |
25 | news_id = self._match_id(url) | |
26 | page = self._download_webpage(url, news_id) | |
27 | ||
28 | if not self._search_regex(r'(CTSPlayer2)', page, 'CTSPlayer2 identifier', fatal=False): | |
29 | raise ExtractorError('The news includes no videos!') | |
30 | ||
31 | feed_pattern = r'(http://news.cts.com.tw/action/mp4feed.php\?news_id=\d+)' | |
32 | feed_url = self._html_search_regex(feed_pattern, page, 'feed url') | |
33 | feed_page = self._download_webpage(feed_url, news_id) | |
34 | ||
35 | description = self._html_search_meta('description', page) | |
36 | title = self._html_search_meta('title', page) | |
37 | thumbnail = self._html_search_meta('image', page) | |
38 | ||
39 | datetime_pattern = r'(\d{4}/\d{2}/\d{2} \d{2}:\d{2})' | |
40 | datetime_str = self._html_search_regex(datetime_pattern, page, 'date and time') | |
41 | time = (datetime_str + ':00+08:00').replace('/', '-') | |
42 | timestamp = parse_iso8601(time, delimiter=' ') | |
43 | ||
44 | return { | |
45 | 'id': news_id, | |
46 | 'title': title, | |
47 | 'description': description, | |
48 | 'url': feed_page, | |
49 | 'thumbnail': thumbnail, | |
50 | 'timestamp': timestamp | |
51 | } |