ctsnews.py 3.5 KB

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