]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nzherald.py
1 from .brightcove
import BrightcoveNewIE
2 from .common
import InfoExtractor
4 from ..compat
import compat_str
11 class NZHeraldIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:www\.)?nzherald\.co\.nz/[\w\/-]+\/(?P<id>[A-Z0-9]+)'
16 'url': 'https://www.nzherald.co.nz/nz/weather-heavy-rain-gales-across-nz-most-days-this-week/PTG7QWY4E2225YHZ5NAIRBTYTQ/',
18 'id': '6271084466001',
20 'title': 'MetService severe weather warning: September 6th - 7th',
21 'timestamp': 1630891576,
22 'upload_date': '20210906',
23 'uploader_id': '1308227299001',
24 'description': 'md5:db6ca335a22e2cdf37ab9d2bcda52902'
28 # Webpage has brightcove embed player url
29 'url': 'https://www.nzherald.co.nz/travel/pencarrow-coastal-trail/HDVTPJEPP46HJ2UEMK4EGD2DFI/',
31 'id': '6261791733001',
33 'title': 'Pencarrow Coastal Trail',
34 'timestamp': 1625102897,
35 'upload_date': '20210701',
36 'uploader_id': '1308227299001',
37 'description': 'md5:d361aaa0c6498f7ac1bc4fc0a0aec1e4'
41 # two video embeds of the same video
42 'url': 'https://www.nzherald.co.nz/nz/truck-driver-captured-cutting-off-motorist-on-state-highway-1-in-canterbury/FIHNJB7PLLPHWQPK4S7ZBDUC4I/',
44 'id': '6251114530001',
46 'title': 'Truck travelling north from Rakaia runs car off road',
47 'timestamp': 1619730509,
48 'upload_date': '20210429',
49 'uploader_id': '1308227299001',
50 'description': 'md5:4cae7dfb7613ac4c73b9e73a75c6b5d7'
53 'url': 'https://www.nzherald.co.nz/kahu/kaupapa-companies-my-taiao-supporting-maori-in-study-and-business/PQBO2J25WCG77VGRX7W7BVYEAI/',
56 'url': 'https://nzherald.co.nz/the-country/video/focus-nzs-first-mass-covid-19-vaccination-event/N5I7IL3BRFLZSD33TLDLYJDGK4/',
59 'url': 'https://www.nzherald.co.nz/the-vision-is-clear/news/tvic-damian-roper-planting-trees-an-addiction/AN2AAEPNRK5VLISDWQAJZB6ATQ',
64 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/1308227299001/S1BXZn8t_default/index.html?videoId=%s'
66 def _extract_bc_embed_url(self
, webpage
):
67 """The initial webpage may include the brightcove player embed url"""
68 bc_url
= BrightcoveNewIE
._extract
_url
(self
, webpage
)
69 return bc_url
or self
._search
_regex
(
70 r
'(?:embedUrl)\"\s*:\s*\"(?P<embed_url>%s)' % BrightcoveNewIE
._VALID
_URL
,
71 webpage
, 'embed url', default
=None, group
='embed_url')
73 def _real_extract(self
, url
):
74 article_id
= self
._match
_id
(url
)
75 webpage
= self
._download
_webpage
(url
, article_id
)
76 bc_url
= self
._extract
_bc
_embed
_url
(webpage
)
79 fusion_metadata
= self
._parse
_json
(
80 self
._search
_regex
(r
'Fusion\.globalContent\s*=\s*({.+?})\s*;', webpage
, 'fusion metadata'), article_id
)
82 video_metadata
= fusion_metadata
.get('video')
83 bc_video_id
= traverse_obj(
84 video_metadata
or fusion_metadata
, # fusion metadata is the video metadata for video-only pages
85 'brightcoveId', ('content_elements', ..., 'referent', 'id'),
86 get_all
=False, expected_type
=compat_str
)
89 if isinstance(video_metadata
, dict) and len(video_metadata
) == 0:
90 raise ExtractorError('This article does not have a video.', expected
=True)
92 raise ExtractorError('Failed to extract brightcove video id')
93 bc_url
= self
.BRIGHTCOVE_URL_TEMPLATE
% bc_video_id
95 return self
.url_result(bc_url
, 'BrightcoveNew')