U
    g{                     @   sH   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
dS )    N   )InfoExtractor   )ExtractorErrorfloat_or_noneformat_fieldint_or_nonestr_or_nonetraverse_objc                   @   s   e Zd ZdZdddddddd	d
ddeeedddddddddddddddeeedddddddd dd!d"d#d$d%d&eeed'ddd(d)d*d+d)d*gZd,d- Zd.S )/	MedalTVIEzBhttps?://(?:www\.)?medal\.tv/games/[^/?#&]+/clips/(?P<id>[^/?#&]+)z3https://medal.tv/games/valorant/clips/jTBFnLKdLy15KZ 03e4911fdcf7fce563090705c2e79267ZjTBFnLKdLy15KZmp4zMornu's clutch ZAcieliqbZ20220504Z19335460zhttps://medal.tv/users/19335460   )idexttitledescriptionuploader	timestampupload_dateuploader_iduploader_urlcomment_count
view_count
like_countduration)urlmd5Z	info_dictz7https://medal.tv/games/cod-cold-war/clips/2mA60jWAGQCBHZ fc7a3e4552ae8993c1c4006db46be447Z2mA60jWAGQCBHz	Quad ColdzMedal,https://medal.tv/desktop/ZMowgliSBiR\_Z20201020Z10619174zRhttps://cdn.medal.tv/10619174/thumbnail-34934644-720p.jpg?t=1080p&c=202042&missingzhttps://medal.tv/users/10619174   )r   r   r   r   r   r   r   r   	thumbnailr   r   r   r   r   z7https://medal.tv/games/cod-cold-war/clips/2um24TWdty0NAZ b6dc76b78195fff0b4f8bf4a33ec2148Z2um24TWdty0NAzu tk me i tk u biggerZMimicci8_Z20201117Z5156321zQhttps://cdn.medal.tv/5156321/thumbnail-36787208-360p.jpg?t=1080p&c=202046&missingzhttps://medal.tv/users/5156321	   z3https://medal.tv/games/valorant/clips/37rMeFpryCC-9T)r   Zonly_matchingz3https://medal.tv/games/valorant/clips/2WRj40tpY_EU9c                    s  |  |}| j||ddid}| jd|d|ddd}t|d	dd
}|sRtd|d|d }t|d}t|d}|r|r|| nd d/ fdd	}	g }
g }| D ]\}}|rt|t	sqt
d|}|sq|d}t|d}|dkr|	|
||p||rd ndd q|dkr|	|||d q|d}|
sv|rv|dkr`| jdd|d  n| jd!| d"|d t|d#dd
pi }t|d$}t|d d%}|||
||d&|d't|d(d)||t|d*t|d+t|d,t|d-d.S )0NZmobilebypasstrue)queryz%<script[^>]*>[^<]*\bhydrationData\s*=z	next dataz	</script>F)Zend_patternfatal)Zclips.)get_allz!Could not find video information.)video_idZcontentTitleZsourceWidthZsourceHeightgqq?	format_idc              
      sF   |p
d| }||krd S t t | }| d|||d|d|i d S )Nz%dpr   widthheight)introundappend)	containerZitem_urlr'   Zid_keyitem_idr&   Zaspect_ratio </tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/medaltv.pyadd_iteme   s        z)MedalTVIE._real_extract.<locals>.add_itemz"(contentUrl|thumbnail)(?:(\d+)p)?$r   r   Z
contentUrlsource)r,   r   r   errori  zThat clip does not exist.T)expectedr$   zAn unknown error occurred (z).)Zprofiles.ZuserIdzhttps://medal.tv/users/%sZcontentDescriptionZdisplayNamecreatedi  ZvideoLengthSecondsZviewsZlikescomments)r   r   formats
thumbnailsr   r   r   r   r   r   r   r   r   )r%   N)Z	_match_idZ_download_webpageZ_search_jsonr
   r   r   getitems
isinstancestrrematchgroupZraise_no_formatsr	   r   r   )selfr   r$   ZwebpageZhydration_dataZclipr   Zsource_widthZsource_heightr0   r6   r7   kvZmobjprefixr'   r2   authorZ	author_idZ
author_urlr.   r-   r/   _real_extractP   s    
     

  

 
zMedalTVIE._real_extractN)__name__
__module____qualname__Z
_VALID_URLr(   Z_TESTSrD   r.   r.   r.   r/   r      s|   @r   )r<   commonr   utilsr   r   r   r   r	   r
   r   r.   r.   r.   r/   <module>   s    
