U
    $Pf
#                     @   sl   d dl mZ 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mZ G dd deZG d	d
 d
eZdS )    )unicode_literalsN   )InfoExtractor   )determine_extExtractorError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idd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#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url	info_dictparamszDRM-protected videoz<http://www.mewatch.sg/en/movies/dug-s-special-mission/341413Z341413ZwvmzDug's Special Missionz$md5:e86c6f4458214905c1772398fabc93e0Z20150827i{UzDRM-protected wvm download)noter   r   r   z6m3u8 links are geo-restricted, but Android/mp4 is okayzWhttp://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861Z332861z&28th SEA Games (5 Show) -  Episode  11z$md5:3cd4f5f56c7c3b1340c50a863f896faaZ20150605i+qUzm3u8 links are geo-restricted)r   r   r   r   skipzqhttp://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331Tr   Zonly_matchingzphttp://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
  d }g } dg D ]}|d|d }}|rj|dksj|sqjt|}	|	dd}|	dkr| j
||d|d| d| dd}
|
D ]}d|d krq|| qqj|	dkr(|| j|||d| d| dd qj|	dkrX|| j|||d| d| dd  qj|	dkrj||	||d! qj|sʈ d"pg D ]2}|d#d$kr|d%d&krtd'd(d)qtd*d(d)| | g } d+g D ]~}t|tsq|d}|sqd|i}|d,d}td-|}|rV|t|d.t|d/d0 || q fd1d2}||t d3t d4t d5pd t d6|d7|d8||d9
S ):N 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 jsonzutf-8)dataZ	MediaNameZFilesURLZFormatZNA Zm3u8r   zDownloading %s m3u8 informationz&Failed to download %s m3u8 informationF)r   Zm3u8_idr   errnotefatalz/fpshls/r   ZmpdzDownloading %s MPD manifestz"Failed to download %s MPD manifest)Zmpd_idr   r#   r$   ZismzDownloading %s ISM manifestz"Failed to download %s ISM manifest)Zism_idr   r#   r$   )r   r   Z	format_idZMetasZKeyZ
EncryptionValue1zThis video is DRM protected.T)expectedzNo downloadable videos foundZ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-7zdooeg3/youtube_dl/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_formatsr   Z_sort_formats
isinstancedictresearchupdateintgroupr   r	   r
   r   )selfr   Zvideo_idr   r   r7   Z
video_fileZ	video_urlZ
vid_formatr   Zm3u8_formatsfmetar6   ZpictureZpic_urlZ	thumbnailZpic_sizemr3   r1   r/   r2   _real_extractZ   s    
     
  

  

  


 zToggleIE._real_extractN)	__name__
__module____qualname__IE_NAME
_VALID_URL_TESTSr9   r:   rM   r1   r1   r1   r2   r      s   	 	 	 B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:)r8   r;   Z
url_resultr   Zie_key)rI   r   Zitem_idZ	custom_idr1   r1   r2   rM      s    
   zMeWatchIE._real_extractN)rN   rO   rP   rQ   rR   rS   rM   r1   r1   r1   r2   rT      s2   	 rT   )
__future__r   r<   rD   commonr   utilsr   r   r   r	   r
   r   r   rT   r1   r1   r1   r2   <module>   s    
 8