onenewsnz.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from .brightcove import BrightcoveNewIE
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. traverse_obj
  6. )
  7. class OneNewsNZIE(InfoExtractor):
  8. IE_NAME = '1News'
  9. IE_DESC = '1news.co.nz article videos'
  10. _VALID_URL = r'https?://(?:www\.)?(?:1|one)news\.co\.nz/\d+/\d+/\d+/(?P<id>[^/?#&]+)'
  11. _TESTS = [
  12. { # Brightcove video
  13. 'url': 'https://www.1news.co.nz/2022/09/29/cows-painted-green-on-parliament-lawn-in-climate-protest/',
  14. 'info_dict': {
  15. 'id': 'cows-painted-green-on-parliament-lawn-in-climate-protest',
  16. 'title': '\'Cows\' painted green on Parliament lawn in climate protest',
  17. },
  18. 'playlist': [{
  19. 'info_dict': {
  20. 'id': '6312993358112',
  21. 'title': 'Activists dressed as cows painted green outside Parliament in climate protest',
  22. 'ext': 'mp4',
  23. 'tags': 'count:6',
  24. 'uploader_id': '963482464001',
  25. 'timestamp': 1664416255,
  26. 'upload_date': '20220929',
  27. 'duration': 38.272,
  28. 'thumbnail': r're:^https?://.*\.jpg$',
  29. 'description': 'Greenpeace accused the Government of "greenwashing" instead of taking climate action.',
  30. }
  31. }]
  32. }, {
  33. # YouTube video
  34. 'url': 'https://www.1news.co.nz/2022/09/30/now-is-the-time-to-care-about-womens-rugby/',
  35. 'info_dict': {
  36. 'id': 'now-is-the-time-to-care-about-womens-rugby',
  37. 'title': 'Now is the time to care about women\'s rugby',
  38. },
  39. 'playlist': [{
  40. 'info_dict': {
  41. 'id': 's4wEB9neTfU',
  42. 'title': 'Why I love women’s rugby: Black Fern Ruahei Demant',
  43. 'ext': 'mp4',
  44. 'channel_follower_count': int,
  45. 'channel_url': 'https://www.youtube.com/channel/UC2BQ3U9IxoYIJyulv0bN5PQ',
  46. 'tags': 'count:12',
  47. 'uploader': 'Re: News',
  48. 'upload_date': '20211215',
  49. 'uploader_id': 'UC2BQ3U9IxoYIJyulv0bN5PQ',
  50. 'uploader_url': 'http://www.youtube.com/channel/UC2BQ3U9IxoYIJyulv0bN5PQ',
  51. 'channel_id': 'UC2BQ3U9IxoYIJyulv0bN5PQ',
  52. 'channel': 'Re: News',
  53. 'like_count': int,
  54. 'thumbnail': 'https://i.ytimg.com/vi/s4wEB9neTfU/maxresdefault.jpg',
  55. 'age_limit': 0,
  56. 'view_count': int,
  57. 'categories': ['Sports'],
  58. 'duration': 222,
  59. 'description': 'md5:8874410e5740ed1d8fd0df839f849813',
  60. 'availability': 'public',
  61. 'playable_in_embed': True,
  62. 'live_status': 'not_live',
  63. }
  64. }]
  65. }, {
  66. # 2 Brightcove videos
  67. 'url': 'https://www.1news.co.nz/2022/09/29/raw-videos-capture-hurricane-ians-fury-as-it-slams-florida/',
  68. 'info_dict': {
  69. 'id': 'raw-videos-capture-hurricane-ians-fury-as-it-slams-florida',
  70. 'title': 'Raw videos capture Hurricane Ian\'s fury as it slams Florida',
  71. },
  72. 'playlist_mincount': 2,
  73. }, {
  74. 'url': 'https://www.onenews.co.nz/2022/09/29/cows-painted-green-on-parliament-lawn-in-climate-protest/',
  75. 'only_matching': True,
  76. }]
  77. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/0xpHIR6IB_default/index.html?videoId=%s'
  78. def _real_extract(self, url):
  79. display_id = self._match_id(url)
  80. webpage = self._download_webpage(url, display_id)
  81. fusion_metadata = self._search_json(r'Fusion\.globalContent\s*=', webpage, 'fusion metadata', display_id)
  82. entries = []
  83. for item in traverse_obj(fusion_metadata, 'content_elements') or []:
  84. item_type = traverse_obj(item, 'subtype')
  85. if item_type == 'video':
  86. brightcove_config = traverse_obj(item, ('embed', 'config'))
  87. brightcove_url = self.BRIGHTCOVE_URL_TEMPLATE % (
  88. traverse_obj(brightcove_config, 'brightcoveAccount') or '963482464001',
  89. traverse_obj(brightcove_config, 'brightcoveVideoId')
  90. )
  91. entries.append(self.url_result(brightcove_url, BrightcoveNewIE))
  92. elif item_type == 'youtube':
  93. video_id_or_url = traverse_obj(item, ('referent', 'id'), ('raw_oembed', '_id'))
  94. if video_id_or_url:
  95. entries.append(self.url_result(video_id_or_url, ie='Youtube'))
  96. if not entries:
  97. raise ExtractorError('This article does not have a video.', expected=True)
  98. playlist_title = (
  99. traverse_obj(fusion_metadata, ('headlines', 'basic'))
  100. or self._generic_title('', webpage)
  101. )
  102. return self.playlist_result(entries, display_id, playlist_title)