]>
Commit | Line | Data |
---|---|---|
69d8eeee | 1 | # coding: utf-8 |
367cc95a YCH |
2 | from __future__ import unicode_literals |
3 | ||
4 | from .common import InfoExtractor | |
69d8eeee | 5 | from ..utils import unified_timestamp |
367cc95a YCH |
6 | |
7 | ||
8 | class CtsNewsIE(InfoExtractor): | |
e1ba1523 | 9 | IE_DESC = '華視新聞' |
5886b38d | 10 | _VALID_URL = r'https?://news\.cts\.com\.tw/[a-z]+/[a-z]+/\d+/(?P<id>\d+)\.html' |
367cc95a | 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人死亡', | |
69d8eeee | 18 | 'description': '以色列和黎巴嫩真主黨,爆發五年最嚴重衝突,雙方砲轟交火,兩名以軍死亡,還有一名西班牙籍的聯合國維和人...', |
e683a48d YCH |
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歲童顏男 貌如十多歲小孩', | |
69d8eeee | 30 | 'description': '越有年紀的人,越希望看起來年輕一點,而南韓卻有一位31歲的男子,看起來像是11、12歲的小孩,身...', |
ec85ded8 | 31 | 'thumbnail': r're:^https?://.*\.jpg$', |
367cc95a YCH |
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', | |
69d8eeee | 38 | 'md5': 'e4726b2ccd70ba2c319865e28f0a91d1', |
e683a48d YCH |
39 | 'info_dict': { |
40 | 'id': 'OVbfO7d0_hQ', | |
41 | 'ext': 'mp4', | |
42 | 'title': 'iPhone6熱銷 蘋果財報亮眼', | |
43 | 'description': 'md5:f395d4f485487bb0f992ed2c4b07aa7d', | |
ec85ded8 | 44 | 'thumbnail': r're:^https?://.*\.jpg$', |
e683a48d YCH |
45 | 'upload_date': '20150128', |
46 | 'uploader_id': 'TBSCTS', | |
47 | 'uploader': '中華電視公司', | |
69d8eeee YCH |
48 | }, |
49 | 'add_ie': ['Youtube'], | |
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 | ||
69d8eeee YCH |
56 | news_id = self._hidden_inputs(page).get('get_id') |
57 | ||
58 | if news_id: | |
59 | mp4_feed = self._download_json( | |
60 | 'http://news.cts.com.tw/action/test_mp4feed.php', | |
61 | news_id, note='Fetching feed', query={'news_id': news_id}) | |
62 | video_url = mp4_feed['source_url'] | |
e683a48d YCH |
63 | else: |
64 | self.to_screen('Not CTSPlayer video, trying Youtube...') | |
65 | youtube_url = self._search_regex( | |
69d8eeee | 66 | r'src="(//www\.youtube\.com/embed/[^"]+)"', page, 'youtube url') |
367cc95a | 67 | |
69d8eeee | 68 | return self.url_result(youtube_url, ie='Youtube') |
367cc95a YCH |
69 | |
70 | description = self._html_search_meta('description', page) | |
69d8eeee | 71 | title = self._html_search_meta('title', page, fatal=True) |
367cc95a YCH |
72 | thumbnail = self._html_search_meta('image', page) |
73 | ||
e683a48d | 74 | datetime_str = self._html_search_regex( |
69d8eeee YCH |
75 | r'(\d{4}/\d{2}/\d{2} \d{2}:\d{2})', page, 'date and time', fatal=False) |
76 | timestamp = None | |
77 | if datetime_str: | |
78 | timestamp = unified_timestamp(datetime_str) - 8 * 3600 | |
e683a48d | 79 | |
367cc95a YCH |
80 | return { |
81 | 'id': news_id, | |
e683a48d | 82 | 'url': video_url, |
367cc95a YCH |
83 | 'title': title, |
84 | 'description': description, | |
367cc95a | 85 | 'thumbnail': thumbnail, |
e683a48d | 86 | 'timestamp': timestamp, |
367cc95a | 87 | } |