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