2016-08-09 21:38:19 -06:00
|
|
|
|
# coding: utf-8
|
2015-01-28 12:49:56 -07:00
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2016-08-09 21:38:19 -06:00
|
|
|
|
from ..utils import unified_timestamp
|
2019-07-15 10:03:03 -06:00
|
|
|
|
from .youtube import YoutubeIE
|
2015-01-28 12:49:56 -07:00
|
|
|
|
|
|
|
|
|
class CtsNewsIE(InfoExtractor):
|
2015-07-10 10:50:31 -06:00
|
|
|
|
IE_DESC = '華視新聞'
|
2016-03-21 09:36:32 -06:00
|
|
|
|
_VALID_URL = r'https?://news\.cts\.com\.tw/[a-z]+/[a-z]+/\d+/(?P<id>\d+)\.html'
|
2015-01-28 12:49:56 -07:00
|
|
|
|
_TESTS = [{
|
2015-01-29 14:38:05 -07:00
|
|
|
|
'url': 'http://news.cts.com.tw/cts/international/201501/201501291578109.html',
|
|
|
|
|
'md5': 'a9875cb790252b08431186d741beaabe',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '201501291578109',
|
|
|
|
|
'ext': 'mp4',
|
2019-07-15 10:03:03 -06:00
|
|
|
|
'title': '以色列.真主黨交火 3人死亡 - 華視新聞網',
|
|
|
|
|
'description': '以色列和黎巴嫩真主黨,爆發五年最嚴重衝突,雙方砲轟交火,兩名以軍死亡,還有一名西班牙籍的聯合國維和人員也不幸罹難。大陸陝西、河南、安徽、江蘇和湖北五個省份出現大暴雪,嚴重影響陸空交通,不過九華山卻出現...',
|
2015-01-29 14:38:05 -07:00
|
|
|
|
'timestamp': 1422528540,
|
|
|
|
|
'upload_date': '20150129',
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
# News count not appear on page but still available in database
|
2015-01-28 12:49:56 -07:00
|
|
|
|
'url': 'http://news.cts.com.tw/cts/international/201309/201309031304098.html',
|
|
|
|
|
'md5': '3aee7e0df7cdff94e43581f54c22619e',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '201309031304098',
|
|
|
|
|
'ext': 'mp4',
|
2019-07-15 10:03:03 -06:00
|
|
|
|
'title': '韓國31歲童顏男 貌如十多歲小孩 - 華視新聞網',
|
2016-08-09 21:38:19 -06:00
|
|
|
|
'description': '越有年紀的人,越希望看起來年輕一點,而南韓卻有一位31歲的男子,看起來像是11、12歲的小孩,身...',
|
2017-01-02 05:08:07 -07:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2015-01-28 12:49:56 -07:00
|
|
|
|
'timestamp': 1378205880,
|
|
|
|
|
'upload_date': '20130903',
|
|
|
|
|
}
|
2015-01-29 14:38:05 -07:00
|
|
|
|
}, {
|
|
|
|
|
# With Youtube embedded video
|
|
|
|
|
'url': 'http://news.cts.com.tw/cts/money/201501/201501291578003.html',
|
2016-08-09 21:38:19 -06:00
|
|
|
|
'md5': 'e4726b2ccd70ba2c319865e28f0a91d1',
|
2015-01-29 14:38:05 -07:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'OVbfO7d0_hQ',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'iPhone6熱銷 蘋果財報亮眼',
|
|
|
|
|
'description': 'md5:f395d4f485487bb0f992ed2c4b07aa7d',
|
2017-01-02 05:08:07 -07:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2015-01-29 14:38:05 -07:00
|
|
|
|
'upload_date': '20150128',
|
|
|
|
|
'uploader_id': 'TBSCTS',
|
|
|
|
|
'uploader': '中華電視公司',
|
2016-08-09 21:38:19 -06:00
|
|
|
|
},
|
|
|
|
|
'add_ie': ['Youtube'],
|
2015-01-28 12:49:56 -07:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
news_id = self._match_id(url)
|
|
|
|
|
page = self._download_webpage(url, news_id)
|
|
|
|
|
|
2016-08-09 21:38:19 -06:00
|
|
|
|
news_id = self._hidden_inputs(page).get('get_id')
|
|
|
|
|
|
|
|
|
|
if news_id:
|
|
|
|
|
mp4_feed = self._download_json(
|
|
|
|
|
'http://news.cts.com.tw/action/test_mp4feed.php',
|
|
|
|
|
news_id, note='Fetching feed', query={'news_id': news_id})
|
|
|
|
|
video_url = mp4_feed['source_url']
|
2015-01-29 14:38:05 -07:00
|
|
|
|
else:
|
|
|
|
|
self.to_screen('Not CTSPlayer video, trying Youtube...')
|
2019-07-15 10:03:03 -06:00
|
|
|
|
youtube_url = YoutubeIE._extract_url(page)
|
2015-01-28 12:49:56 -07:00
|
|
|
|
|
2016-08-09 21:38:19 -06:00
|
|
|
|
return self.url_result(youtube_url, ie='Youtube')
|
2015-01-28 12:49:56 -07:00
|
|
|
|
|
|
|
|
|
description = self._html_search_meta('description', page)
|
2016-08-09 21:38:19 -06:00
|
|
|
|
title = self._html_search_meta('title', page, fatal=True)
|
2015-01-28 12:49:56 -07:00
|
|
|
|
thumbnail = self._html_search_meta('image', page)
|
|
|
|
|
|
2015-01-29 14:38:05 -07:00
|
|
|
|
datetime_str = self._html_search_regex(
|
2016-08-09 21:38:19 -06:00
|
|
|
|
r'(\d{4}/\d{2}/\d{2} \d{2}:\d{2})', page, 'date and time', fatal=False)
|
|
|
|
|
timestamp = None
|
|
|
|
|
if datetime_str:
|
|
|
|
|
timestamp = unified_timestamp(datetime_str) - 8 * 3600
|
2015-01-29 14:38:05 -07:00
|
|
|
|
|
2015-01-28 12:49:56 -07:00
|
|
|
|
return {
|
|
|
|
|
'id': news_id,
|
2015-01-29 14:38:05 -07:00
|
|
|
|
'url': video_url,
|
2015-01-28 12:49:56 -07:00
|
|
|
|
'title': title,
|
|
|
|
|
'description': description,
|
|
|
|
|
'thumbnail': thumbnail,
|
2015-01-29 14:38:05 -07:00
|
|
|
|
'timestamp': timestamp,
|
2015-01-28 12:49:56 -07:00
|
|
|
|
}
|