o
    i                     @   sD   d dl Z ddlmZ ddlmZ ddlmZmZ G dd deZdS )	    N   )BrightcoveNewIE)InfoExtractor   )ExtractorErrortraverse_objc                   @   s   e Zd ZdZdZddddddd	d
g ddd
dddddddd	ddddgdd
dddddddd	ddd d!d"d#dd$d%d&d'd	g d(dd)d*
dd+d,d-d.d,d-d/d,d-gZd0Zd1d2 Zd3d4 Zd5S )6
NZHeraldIEnzheraldz?https?://(?:www\.)?nzherald\.co\.nz/[\w\/-]+\/(?P<id>[A-Z0-9]+)z|https://www.nzherald.co.nz/nz/queen-elizabeth-death-nz-public-holiday-announced-for-september-26/CEOPBSXO2JDCLNK3H7E3BIE2FA/6312191736112mp4z-Focus: PM holds post-Cabinet press conferenceg(\m@202209121308227299001igczre:https?://.*\.jpg$z$md5:2f17713fcbfcfbe38bb9e7dfccbb0f2e)
idexttitledurationupload_dateuploader_id	timestamptags	thumbnaildescription)url	info_dictzUhttps://www.nzherald.co.nz/travel/pencarrow-coastal-trail/HDVTPJEPP46HJ2UEMK4EGD2DFI/6261791733001zPencarrow Coastal Traili1`20210701z$md5:d361aaa0c6498f7ac1bc4fc0a0aec1e4travelvideogK7AE@)
r   r   r   r   r   r   r   r   r   r   zhttps://www.nzherald.co.nz/nz/truck-driver-captured-cutting-off-motorist-on-state-highway-1-in-canterbury/FIHNJB7PLLPHWQPK4S7ZBDUC4I/6251114530001z4Truck travelling north from Rakaia runs car off roadiM `20210429z$md5:4cae7dfb7613ac4c73b9e73a75c6b5d7)r   r   r   r   r   r   r   zvideo removed)r   r   skipz}https://www.nzherald.co.nz/nz/politics/reserve-bank-rejects-political-criticisms-stands-by-review/2JO5Q4WLZRCBBNWTLACZMOP4RA/6315123873112iŐiczBFocus: Luxon on re-appointment of Reserve Bank governor Adrian Orr20221107z$md5:df2f1f7033a8160c66e28e4743f5d934)r   znz herald focuspoliticszpolitics videosgL7A`X@)
r   r   r   r   r   r   r   r   r   r   z}https://www.nzherald.co.nz/kahu/kaupapa-companies-my-taiao-supporting-maori-in-study-and-business/PQBO2J25WCG77VGRX7W7BVYEAI/T)r   only_matchingzthttps://nzherald.co.nz/the-country/video/focus-nzs-first-mass-covid-19-vaccination-event/N5I7IL3BRFLZSD33TLDLYJDGK4/z|https://www.nzherald.co.nz/the-vision-is-clear/news/tvic-damian-roper-planting-trees-an-addiction/AN2AAEPNRK5VLISDWQAJZB6ATQzRhttp://players.brightcove.net/1308227299001/S1BXZn8t_default/index.html?videoId=%sc                 C   s.   t | |}|p| jdt j d|ddddS )z?The initial webpage may include the brightcove player embed urlz%(?:embedUrl)\"\s*:\s*\"(?P<embed_url>)z	embed urlN	embed_url)defaultgroup)r   _extract_url_search_regex
_VALID_URL)selfwebpagebc_url r/   M/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/nzherald.py_extract_bc_embed_urlT   s
   z NZHeraldIE._extract_bc_embed_urlc           	      C   s   |  |}| ||}| |}|se| | d|d|}|d}|s>t|dtd}|r>| jd|t	
|dddd	d
}t|pB|dddtd}|s`t|tr\t|dkr\tdddtd| j| }| |dS )Nz'Fusion\.globalContent\s*=\s*({.+?})\s*;zfusion metadatar   )customVideoembedr   )expected_typezEhttps://www.nzherald.co.nz/pf/api/v3/content/fetch/full-content-by-idnzh)r   site)query_website)r7   brightcoveId)content_elements.referentr   F)get_allr4   r   z#This article does not have a video.T)expectedz%Failed to extract brightcove video idBrightcoveNew)	_match_id_download_webpager1   _parse_jsonr*   getr   str_download_jsonjsondumps
isinstancedictlenr   BRIGHTCOVE_URL_TEMPLATE
url_result)	r,   r   
article_idr-   r.   fusion_metadatavideo_metadatacustom_video_idbc_video_idr/   r/   r0   _real_extract[   s4   



zNZHeraldIE._real_extractN)	__name__
__module____qualname__IE_NAMEr+   _TESTSrJ   r1   rQ   r/   r/   r/   r0   r      s    	Gr   )	rE   
brightcover   commonr   utilsr   r   r   r/   r/   r/   r0   <module>   s
    