U
    gT                     @   sP   d dl mZ ddlmZmZmZmZmZmZm	Z	m
Z
mZmZ G dd deZdS )   )InfoExtractor   )
ExtractorError
clean_htmlint_or_nonemerge_dictsparse_countstr_or_nonetry_getunified_strdateurlencode_postdataurljoinc                   @   s   e Zd ZdZdZdZdgZdZdddd	d
ddddddddddd	ddddi dddgZdddddddd d!d"	Z	d#d$d%Z
d&Zd'd( Zd)S )*HKETVIEZhketvuX   香港教育局教育電視 (HKETV) Educational Television, Hong Kong Educational BureauFZHKz<https?://(?:www\.)?hkedcity\.net/etv/resource/(?P<id>[0-9]+)z0https://www.hkedcity.net/etv/resource/2932360618Z f193712f5f7abb208ddef3c5ea6ed0b7Z
2932360618Zmp4u>   喜閱一生(共享閱讀樂) (中、英文字幕可供選擇)z$md5:d5286d05219ef50e0613311cbe96e560Z20181024i  zcount:2)idexttitledescriptionupload_dateduration	subtitleszGeo restricted to HK)urlmd5Z	info_dictskipz/https://www.hkedcity.net/etv/resource/972641418Z 1ed494c1c6cf7866a8290edad9b07dc9Z	972641418u!   衣冠楚楚 (天使系列之一)z$md5:10bb3d659421e74f58e5db5691627b0fZ20070109i  zzh-Hantzzh-Hansenr   hinetlthur)	u   中文（繁體中文）u   中文（简体中文）ZEnglishzBahasa Indonesiau   हिन्दीu   नेपालीZTagalogu	   ไทยu   اردوih  i  )ZSDZHDzhttps://apps.hkedcity.netc                 C   s  |  |}| ||}| jd|d dpT| jd|dd ddpT| jd|dd dpT| |}| d|d	}| d
|d}d|||d}| j| jd |t|t	ddi| 
 d}|d }	|dr|dst|d}
d|
kr| j|
| jd nt|
ddg }t|	d}t|	d}|	d d }|d D ]v}t| j|d}|sNq.|d }| j|}|r|r|r|| | nd }|||d!|||d" q.i }t|d#d$ tpg }|D ]}t|tsؐqt|d%}|rt|tsq| d&krqt| j|d}|s*q|d }|| j||g | |d'd( q| jd)|td*d+|d,ddid-d.pi }tt|d/d$ }||| jd0|d-d1t| jd2|d-d1d-d3t|	d4||t| j|	d5t|	d6|d7
S )8N)Zed_titlezsearch.ed_title)defaultz=data-favorite_title_(?:eng|chi)=(["\'])(?P<id>(?:(?!\1).)+)\1r   r   )r   groupz<h1>([^<]+)</h1>z-post_var\[["\']file_id["\']\s*\]\s*=\s*(.+?);zfile IDz0post_var\[["\']curr_url["\']\s*\]\s*=\s*"(.+?)";zcurr URLget_info)actioncurr_urlfile_idZ	video_urlz/media/play/handler.phpzContent-Typez!application/x-www-form-urlencoded)dataheadersresultsuccessaccessZaccess_err_msgz0Video streaming is not available in your country)msgZ	countriesT)expectedwidthheightZplaylist    sourcesfilelabeltype)Z	format_idr   r   r,   r-   c                 S   s   | d S )Ntracks xr4   r4   :/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/hketv.py<lambda>       z'HKETVIE._real_extract.<locals>.<lambda>kind)Zcaptionsr   Zsrt)r   r   z+https://emocounter.hkedcity.net/handler.phpZget_emotionZetv)r"   zdata[bucket_id]zdata[identifier]F)r%   r&   fatalc                 S   s   | d d d d S )Nr%   Zemotion_datar.   countr4   r5   r4   r4   r7   r8      r9   r   )r;   Zed_date)Z	day_firstlengthimage
view_count)
r   r   r   r   r   formatsr   Z	thumbnailr?   
like_count) Z	_match_idZ_download_webpageZ_html_search_metaZ_search_regexZ_html_search_regexZ_og_search_titleZ_download_json_APPS_BASE_URLr   r   Zgeo_verification_headersgetr   Zraise_geo_restricted_GEO_COUNTRIESr   r   r   _FORMAT_HEIGHTSappendr
   list
isinstancedictr	   strlower
setdefault	_CC_LANGSZ_proto_relative_urlr   r   )selfr   Zvideo_idZwebpager   r$   r#   r%   responser'   errorr@   r,   r-   Z	playlist0fmtZfile_urlr1   hwr   r3   trackZ
track_kindZ	track_urlZtrack_labelZemotionrA   r4   r4   r7   _real_extractC   s   
             
"

  	     zHKETVIE._real_extractN)__name__
__module____qualname__ZIE_NAMEZIE_DESCZ_GEO_BYPASSrD   Z
_VALID_URLZ_TESTSrM   rE   rB   rU   r4   r4   r4   r7   r      sZ   		r   N)commonr   utilsr   r   r   r   r   r	   r
   r   r   r   r   r4   r4   r4   r7   <module>   s   0