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.

94 lines
3.6 KiB

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