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.

93 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. # https connection failed (Connection reset)
  7. _VALID_URL = r'http://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': 'md5:95e9b295c898b7ff294f09d450178d7d',
  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': 'md5:f183feeba3752b683827aab71adad584',
  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': '1d842c771dc94c8c3bca5af2cc1db9c5',
  36. 'add_ie': ['Youtube'],
  37. 'info_dict': {
  38. 'id': 'OVbfO7d0_hQ',
  39. 'ext': 'mp4',
  40. 'title': 'iPhone6熱銷 蘋果財報亮眼',
  41. 'description': 'md5:f395d4f485487bb0f992ed2c4b07aa7d',
  42. 'thumbnail': 're:^https?://.*\.jpg$',
  43. 'upload_date': '20150128',
  44. 'uploader_id': 'TBSCTS',
  45. 'uploader': '中華電視公司',
  46. }
  47. }]
  48. def _real_extract(self, url):
  49. news_id = self._match_id(url)
  50. page = self._download_webpage(url, news_id)
  51. if self._search_regex(r'(CTSPlayer2)', page, 'CTSPlayer2 identifier', default=None):
  52. feed_url = self._html_search_regex(
  53. r'(http://news\.cts\.com\.tw/action/mp4feed\.php\?news_id=\d+)',
  54. page, 'feed url')
  55. video_url = self._download_webpage(
  56. feed_url, news_id, note='Fetching feed')
  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. default=None)
  62. if not youtube_url:
  63. raise ExtractorError('The news includes no videos!', expected=True)
  64. return {
  65. '_type': 'url',
  66. 'url': youtube_url,
  67. 'ie_key': 'Youtube',
  68. }
  69. description = self._html_search_meta('description', page)
  70. title = self._html_search_meta('title', page)
  71. thumbnail = self._html_search_meta('image', page)
  72. datetime_str = self._html_search_regex(
  73. r'(\d{4}/\d{2}/\d{2} \d{2}:\d{2})', page, 'date and time')
  74. # Transform into ISO 8601 format with timezone info
  75. datetime_str = datetime_str.replace('/', '-') + ':00+0800'
  76. timestamp = parse_iso8601(datetime_str, delimiter=' ')
  77. return {
  78. 'id': news_id,
  79. 'url': video_url,
  80. 'title': title,
  81. 'description': description,
  82. 'thumbnail': thumbnail,
  83. 'timestamp': timestamp,
  84. }