o
    i                     @   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 )ToggleIE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/343115343115mp4zLion Moms Premierez$md5:aea1149404bff4d7f7b6da11fafd8e6b20150910iU)idexttitledescriptionupload_date	timestampskip_downloadm3u8 downloadurl	info_dictparamsz<http://www.mewatch.sg/en/movies/dug-s-special-mission/341413Tr   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/401585
tvpapi_147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}}|rI|dksI|sJq4t|}	|	dd}|	dkr~| j
||d|d| dd| ddd}
|
D ]}d|d v rwqn|| qnq4|	dkr|| j|||d| dd| ddd q4|	dkr|| j|||d| dd| ddd q4|	dkr||	||d q4|s d pg D ]}| d!s|d"d#kr|d$d%kr| | qg } d&g D ]:}t|tsq|d}|sqd|i}|d'd}td(|}|r#|t|d)t|d*d+ || q fd,d-}||t d.t d/t d0pEd t d1|d2|d3||d4
S )5N r   )LocaleLanguageLocaleCountryLocaleDeviceLocaleUserState0)LocalePlatformSiteGuidDomainIDUDIDApiUserApiPass)initObjMediaID	mediaTypezHhttp://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfozDownloading video info json)data	MediaNameFilesURLFormatNA m3u8r   zDownloading z m3u8 informationzFailed to download F)r   m3u8_idnoteerrnotefatalz/fpshls/r   mpdz MPD manifest)mpd_idr8   r9   r:   ismz ISM manifest)ism_idr8   r9   r:   )r   r   	format_idMetasallow_unplayable_formatsKey
EncryptionValue1PicturesPicSizez!(?P<width>\d+)[xX](?P<height>\d+)widthheight)rH   rI   c                    s$   t  | d p |  d S )NCounter_counter)r   getlower)prefixinfo K/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/toggle.pycounter   s   z'ToggleIE._real_extract.<locals>.counterDescriptionDurationCreationDateRatingViewLike)
r   r   r   durationr   average_rating
view_count
like_count
thumbnailsformats)	_match_id	_API_USER	_API_PASS_download_jsonjsondumpsencoderL   r   replace_extract_m3u8_formatsappendextend_extract_mpd_formats_extract_ism_formats	get_param
report_drm
isinstancedictresearchupdateintgroupr	   r   r   r   )selfr   video_idr   r   r_   
video_file	video_url
vid_formatr   m3u8_formatsfmetar^   picturepic_url	thumbnailpic_sizemrS   rQ   rO   rR   _real_extract>   s   












zToggleIE._real_extractN)	__name__
__module____qualname__IE_NAME
_VALID_URL_TESTSra   rb   r   rQ   rQ   rQ   rR   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 )	MeWatchIEmewatchzEhttps?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)z5https://www.mewatch.sg/watch/Recipe-Of-Life-E1-1793711008625r   u   Recipe Of Life 味之道i_z$md5:6e88cde8af2068444fc8e1bc3ebf257c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)querycustomIdztoggle:)r`   rc   
url_resultr
   ie_key)rv   r   item_id	custom_idrQ   rQ   rR   r      s   
zMeWatchIE._real_extractN)r   r   r   r   r   r   r   rQ   rQ   rQ   rR   r      s2    	r   )rd   rq   commonr   utilsr   r   r   r   r	   r
   r   rQ   rQ   rQ   rR   <module>   s    	 