]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/ctsnews.py
[ChangeLog] Actualize
[youtube-dl.git] / youtube_dl / extractor / ctsnews.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import unified_timestamp
6 from .youtube import YoutubeIE
7
8
9 class CtsNewsIE(InfoExtractor):
10     IE_DESC = '華視新聞'
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': '以色列和黎巴嫩真主黨,爆發五年最嚴重衝突,雙方砲轟交火,兩名以軍死亡,還有一名西班牙籍的聯合國維和人員也不幸罹難。大陸陝西、河南、安徽、江蘇和湖北五個省份出現大暴雪,嚴重影響陸空交通,不過九華山卻出現...',
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': '越有年紀的人,越希望看起來年輕一點,而南韓卻有一位31歲的男子,看起來像是11、12歲的小孩,身...',
32             'thumbnail': r'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': 'e4726b2ccd70ba2c319865e28f0a91d1',
40         'info_dict': {
41             'id': 'OVbfO7d0_hQ',
42             'ext': 'mp4',
43             'title': 'iPhone6熱銷 蘋果財報亮眼',
44             'description': 'md5:f395d4f485487bb0f992ed2c4b07aa7d',
45             'thumbnail': r're:^https?://.*\.jpg$',
46             'upload_date': '20150128',
47             'uploader_id': 'TBSCTS',
48             'uploader': '中華電視公司',
49         },
50         'add_ie': ['Youtube'],
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         news_id = self._hidden_inputs(page).get('get_id')
58
59         if news_id:
60             mp4_feed = self._download_json(
61                 'http://news.cts.com.tw/action/test_mp4feed.php',
62                 news_id, note='Fetching feed', query={'news_id': news_id})
63             video_url = mp4_feed['source_url']
64         else:
65             self.to_screen('Not CTSPlayer video, trying Youtube...')
66             youtube_url = YoutubeIE._extract_url(page)
67
68             return self.url_result(youtube_url, ie='Youtube')
69
70         description = self._html_search_meta('description', page)
71         title = self._html_search_meta('title', page, fatal=True)
72         thumbnail = self._html_search_meta('image', page)
73
74         datetime_str = self._html_search_regex(
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
79
80         return {
81             'id': news_id,
82             'url': video_url,
83             'title': title,
84             'description': description,
85             'thumbnail': thumbnail,
86             'timestamp': timestamp,
87         }