You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import unified_timestamp
  5. class CtsNewsIE(InfoExtractor):
  6. IE_DESC = '華視新聞'
  7. _VALID_URL = r'https?://news\.cts\.com\.tw/[a-z]+/[a-z]+/\d+/(?P<id>\d+)\.html'
  8. _TESTS = [{
  9. 'url': 'http://news.cts.com.tw/cts/international/201501/201501291578109.html',
  10. 'md5': 'a9875cb790252b08431186d741beaabe',
  11. 'info_dict': {
  12. 'id': '201501291578109',
  13. 'ext': 'mp4',
  14. 'title': '以色列.真主黨交火 3人死亡',
  15. 'description': '以色列和黎巴嫩真主黨,爆發五年最嚴重衝突,雙方砲轟交火,兩名以軍死亡,還有一名西班牙籍的聯合國維和人...',
  16. 'timestamp': 1422528540,
  17. 'upload_date': '20150129',
  18. }
  19. }, {
  20. # News count not appear on page but still available in database
  21. 'url': 'http://news.cts.com.tw/cts/international/201309/201309031304098.html',
  22. 'md5': '3aee7e0df7cdff94e43581f54c22619e',
  23. 'info_dict': {
  24. 'id': '201309031304098',
  25. 'ext': 'mp4',
  26. 'title': '韓國31歲童顏男 貌如十多歲小孩',
  27. 'description': '越有年紀的人,越希望看起來年輕一點,而南韓卻有一位31歲的男子,看起來像是11、12歲的小孩,身...',
  28. 'thumbnail': 're:^https?://.*\.jpg$',
  29. 'timestamp': 1378205880,
  30. 'upload_date': '20130903',
  31. }
  32. }, {
  33. # With Youtube embedded video
  34. 'url': 'http://news.cts.com.tw/cts/money/201501/201501291578003.html',
  35. 'md5': 'e4726b2ccd70ba2c319865e28f0a91d1',
  36. 'info_dict': {
  37. 'id': 'OVbfO7d0_hQ',
  38. 'ext': 'mp4',
  39. 'title': 'iPhone6熱銷 蘋果財報亮眼',
  40. 'description': 'md5:f395d4f485487bb0f992ed2c4b07aa7d',
  41. 'thumbnail': 're:^https?://.*\.jpg$',
  42. 'upload_date': '20150128',
  43. 'uploader_id': 'TBSCTS',
  44. 'uploader': '中華電視公司',
  45. },
  46. 'add_ie': ['Youtube'],
  47. }]
  48. def _real_extract(self, url):
  49. news_id = self._match_id(url)
  50. page = self._download_webpage(url, news_id)
  51. news_id = self._hidden_inputs(page).get('get_id')
  52. if news_id:
  53. mp4_feed = self._download_json(
  54. 'http://news.cts.com.tw/action/test_mp4feed.php',
  55. news_id, note='Fetching feed', query={'news_id': news_id})
  56. video_url = mp4_feed['source_url']
  57. else:
  58. self.to_screen('Not CTSPlayer video, trying Youtube...')
  59. youtube_url = self._search_regex(
  60. r'src="(//www\.youtube\.com/embed/[^"]+)"', page, 'youtube url')
  61. return self.url_result(youtube_url, ie='Youtube')
  62. description = self._html_search_meta('description', page)
  63. title = self._html_search_meta('title', page, fatal=True)
  64. thumbnail = self._html_search_meta('image', page)
  65. datetime_str = self._html_search_regex(
  66. r'(\d{4}/\d{2}/\d{2} \d{2}:\d{2})', page, 'date and time', fatal=False)
  67. timestamp = None
  68. if datetime_str:
  69. timestamp = unified_timestamp(datetime_str) - 8 * 3600
  70. return {
  71. 'id': news_id,
  72. 'url': video_url,
  73. 'title': title,
  74. 'description': description,
  75. 'thumbnail': thumbnail,
  76. 'timestamp': timestamp,
  77. }