U
    g                     @   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	dd(d)d*gdd+d,
dd-d.d/d0d.d/d1d.d/gZd2Zd3d4 Zd5d6 Zd7S )8
NZHeraldIEZ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/Z6312191736112Zmp4z-Focus: PM holds post-Cabinet press conferenceg(\m@Z20220912Z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/Z6261791733001zPencarrow Coastal Traili1`Z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/Z6251114530001z4Truck travelling north from Rakaia runs car off roadiM `Z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/Z6315123873112iŐiczBFocus: Luxon on re-appointment of Reserve Bank governor Adrian OrrZ20221107z$md5:df2f1f7033a8160c66e28e4743f5d934znz herald focusZ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   Z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 urlNZ	embed_url)defaultgroup)r   Z_extract_url_search_regex
_VALID_URL)selfwebpagebc_url r    =/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/nzherald.py_extract_bc_embed_urlT   s       z NZHeraldIE._extract_bc_embed_urlc           	      C   s   |  |}| ||}| |}|s| | d|d|}|d}|s|t|dtd}|r|| jd|t	
|dddd	d
}t|p|dddtd}|st|trt|dkrtdddntd| j| }| |dS )Nz'Fusion\.globalContent\s*=\s*({.+?})\s*;zfusion metadatar   )ZcustomVideoembedr	   )expected_typezEhttps://www.nzherald.co.nz/pf/api/v3/content/fetch/full-content-by-idZnzh)r	   site)queryZ_website)r&   ZbrightcoveId)Zcontent_elements.Zreferentr	   F)get_allr$   r   z#This article does not have a video.T)expectedz%Failed to extract brightcove video idZBrightcoveNew)Z	_match_idZ_download_webpager"   Z_parse_jsonr   getr   strZ_download_jsonjsondumps
isinstancedictlenr   BRIGHTCOVE_URL_TEMPLATEZ
url_result)	r   r   Z
article_idr   r   Zfusion_metadataZvideo_metadataZcustom_video_idZbc_video_idr    r    r!   _real_extract[   s<    

 
   
zNZHeraldIE._real_extractN)	__name__
__module____qualname__ZIE_NAMEr   Z_TESTSr0   r"   r1   r    r    r    r!   r      s   	
Gr   )	r+   Z
brightcover   commonr   utilsr   r   r   r    r    r    r!   <module>   s   