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