U
    g                     @   s\   d dl Z d dlZddlmZ ddlmZmZmZmZm	Z	 G dd deZ
G dd	 d	eZdS )
    N   )InfoExtractor   )determine_extfloat_or_noneint_or_noneparse_iso8601strip_or_nonec                   @   s   e Zd ZdZdZddddddd	d
ddi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ddg
ZdZdZdd ZdS )ToggleIEZtogglezc(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:en|zh)/(?:[^/]+/){2,}|toggle:)(?P<id>[0-9]+)zOhttp://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115Z343115mp4zLion Moms Premierez$md5:aea1149404bff4d7f7b6da11fafd8e6bZ20150910iU)idexttitledescriptionupload_date	timestampskip_downloadm3u8 downloadurlZ	info_dictparamsz<http://www.mewatch.sg/en/movies/dug-s-special-mission/341413Tr   Zonly_matchingzWhttp://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861zqhttp://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331zphttp://www.mewatch.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331z>http://www.mewatch.sg/zh/series/zero-calling-s2-hd/ep13/336367z`http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302z1http://www.mewatch.sg/en/movies/seven-days/321936z\https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456z4http://www.mewatch.sg/en/channels/eleven-plus/401585Z
tvpapi_147Z11111c                    s  |  |}ddddddddd| j| jd|dd}| jd|dt| d	  d
 }g } dg D ] }|d|d }}|rh|dksh|sqht|}	|	dd}|	dkr | j
||d|d| dd| ddd}
|
D ]}d|d krq|| qqh|	dkr8|| j|||d| dd| ddd qh|	dkrp|| j|||d| dd| ddd qh|	dkrh||	||d qh|s d pg D ]<}| d!s|d"d#kr|d$d%kr| | qg } d&g D ]~}t|tsq|d}|sqd|i}|d'd}td(|}|rb|t|d)t|d*d+ || q fd,d-}||t d.t d/t d0pd t d1|d2|d3||d4
S )5N r   )ZLocaleLanguageZLocaleCountryZLocaleDeviceZLocaleUserState0)ZLocalePlatformZSiteGuidZDomainIDZUDIDZApiUserZApiPass)ZinitObjZMediaIDZ	mediaTypezHhttp://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfozDownloading video info json)dataZ	MediaNameZFilesURLZFormatZNA Zm3u8r   zDownloading z m3u8 informationzFailed to download F)r   Zm3u8_idnoteerrnotefatalz/fpshls/r   Zmpdz MPD manifest)Zmpd_idr   r   r    Zismz ISM manifest)Zism_idr   r   r    )r   r   Z	format_idZMetasZallow_unplayable_formatsZKeyZ
EncryptionValue1ZPicturesZPicSizez!(?P<width>\d+)[xX](?P<height>\d+)widthheight)r#   r$   c                    s$   t  | d p  |  d S )NCounter_counter)r   getlower)prefixinfo ;/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/toggle.pycounter   s    z'ToggleIE._real_extract.<locals>.counterDescriptionZDurationZCreationDateZRatingZViewZLike)
r   r   r   durationr   Zaverage_ratingZ
view_countZ
like_count
thumbnailsformats)	_match_id	_API_USER	_API_PASS_download_jsonjsondumpsencoder'   r   replaceZ_extract_m3u8_formatsappendextendZ_extract_mpd_formatsZ_extract_ism_formats	get_paramZ
report_drm
isinstancedictresearchupdateintgroupr	   r   r   r   )selfr   Zvideo_idr   r   r2   Z
video_fileZ	video_urlZ
vid_formatr   Zm3u8_formatsfmetar1   ZpictureZpic_urlZ	thumbnailZpic_sizemr.   r,   r*   r-   _real_extract>   s    
  
   


  



  




 zToggleIE._real_extractN)	__name__
__module____qualname__IE_NAME
_VALID_URL_TESTSr4   r5   rI   r,   r,   r,   r-   r
      sZ   	 *r
   c                   @   sT   e Zd ZdZdZddddddd	d
ddiddddddddddgZdd ZdS )	MeWatchIEZmewatchzEhttps?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)z5https://www.mewatch.sg/watch/Recipe-Of-Life-E1-179371Z1008625r   u   Recipe Of Life 味之道i_z$md5:6e88cde8af2068444fc8e1bc3ebf257cZ20201021)r   r   r   r   r   r   r   r   r   ub   https://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-搜密。打卡。小红点-S2-E1-176232Tr   zhttps://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-%E6%90%9C%E5%AF%86%E3%80%82%E6%89%93%E5%8D%A1%E3%80%82%E5%B0%8F%E7%BA%A2%E7%82%B9-S2-E1-176232z7https://live.mewatch.sg/watch/Recipe-Of-Life-E41-189759c                 C   s<   |  |}| jd| |ddidd }| d| t |S )Nz!https://cdn.mewatch.sg/api/items/segmentsall)queryZcustomIdztoggle:)r3   r6   Z
url_resultr
   Zie_key)rE   r   Zitem_idZ	custom_idr,   r,   r-   rI      s    
   zMeWatchIE._real_extractN)rJ   rK   rL   rM   rN   rO   rI   r,   r,   r,   r-   rP      s2   	 rP   )r7   r@   commonr   utilsr   r   r   r   r	   r
   rP   r,   r,   r,   r-   <module>   s   	 