U
    g5                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZddlmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZ G dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZdS )    N   )InfoExtractor)SlidesLiveIE   )ExtractorErrorInAdvancePagedListint_or_noneremove_starttraverse_objupdate_url_queryurl_or_nonec                   @   sN   e Zd ZddddZddeeje dZdZ	d	d
 Z
dd Zdd ZdS )VideoKenBaseIEZictsZcncfZneurips)zvideos.icts.res.inzvideos.cncf.iozvideos.neurips.cczhttps?://(?P<host>|z)/   c                 C   s.   | j d| d|dddid}|d |d fS )	N-https://analytics.videoken.com/api/videolake/z/detailsz'Downloading organization ID and API keyAcceptapplication/json)noteheadersidZapikey)_download_json)selforgvideo_iddetails r   =/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/videoken.py_get_org_id_and_api_key   s    
  z&VideoKenBaseIE._get_org_id_and_api_keyc                 C   sT   |s|sd S |rd|kr(dt |d }t|rPt||dtj|j dS |S )Nzembed/sign-inzhttps://slideslive.com/embed/slideslive-zhttps://)Zembed_parent_urlZembed_container_origin)r	   r   r   urllibparseurlparsehostname)r   	video_urlr   Zrefererr   r   r   _create_slideslive_url'   s    z%VideoKenBaseIE._create_slideslive_urlc                 c   s   t |dD ]}t |dd}|s q
d }t |dddkr>|}d}n<t |dd	td
}|sVq
n$tj|jdkrzt}| |||}| |||V  q
d S )N))videosresults.Z
youtube_idvideoidtypesourceZyoutubeYoutubeZ	embed_urlZembeddableurl)Zexpected_typezslideslive.com)	r
   r   r   r    r!   r"   r   r$   
url_result)r   r%   urlvideor   Zie_keyr#   r   r   r   _extract_videos3   s    zVideoKenBaseIE._extract_videosN)__name__
__module____qualname___ORGANIZATIONSjoinmapreescape_BASE_URL_RE
_PAGE_SIZEr   r$   r.   r   r   r   r   r      s   r   c                   @   s   e Zd Zejd Zdddddddd	d
dddidgdddddddddddddddddeedddd gg d!d"d#d$ddidgdd%d&dd'd(d)d*d+d)d,d-d.d/ddd0deeed1gg d!d2d3d4ddid5d6dd7d8dd7d9dd7gZd:d; Zd<S )=
VideoKenIEz4(?:(?:topic|category)/[^/#?]+/)?video/(?P<id>[\w-]+)z3https://videos.neurips.cc/video/slideslive-38922815Z38922815mp4zVEfficient Processing of Deep Neural Network: from Algorithms to Hardware Architecturesi(6aZ20210906re:^https?://.*\.(?:jpg|png)z	count:330z	count:329r   exttitle	timestampupload_date	thumbnail
thumbnailschaptersskip_downloadm3u8$Failed to download VideoKen API JSON)r,   	info_dictparamsZexpected_warningszLhttps://videos.neurips.cc/topic/machine%20learning/video/slideslive-38923348Z2Xa_dt78rJEZ38923348zMachine EducationzDWatch full version of this video at https://slideslive.com/38923348.zSlidesLive Videos - G2ZUCOExahQQ588Da8Nft_Ltb9wz8https://www.youtube.com/channel/UCOExahQQ588Da8Nft_Ltb9wz7http://www.youtube.com/channel/UCOExahQQ588Da8Nft_Ltb9wi	  i~`Z20200131r   ZunlistedZnot_liveTzPeople & Blogszre:^https?://.*\.(?:jpg|webp)zcount:78zcount:77)r   r=   Z
display_idr>   descriptionchannel
channel_idchannel_urluploaderuploader_iduploader_urldurationr?   r@   	age_limitchannel_follower_count
view_countavailabilitylive_statusplayable_in_embed
categoriestagsrA   rB   rC   zDhttps://videos.icts.res.in/topic/random%20variable/video/zysIsojYdvcZzysIsojYdvczVSmall-worlds, complex networks and random graphs (Lecture 3)  by Remco van der Hofstadz$md5:87433069d79719eeadc1962cc2ace00bz-International Centre for Theoretical ScienceszUCO3xnVTHzB7l-nc8mABUJIQz8https://www.youtube.com/channel/UCO3xnVTHzB7l-nc8mABUJIQZ	ICTStalksz%http://www.youtube.com/user/ICTStalksi,  Z20191004publiczScience & Technologyzcount:42zcount:20)r   r=   r>   rI   rJ   rK   rL   rM   rN   rO   rP   r@   rQ   rU   rT   rV   rR   Z
like_countrS   rW   rX   rA   rB   rC   r,   rG   rH   z5https://videos.cncf.io/category/478/video/IL4nxbmUIX8)r,   Zonly_matchingz9https://videos.cncf.io/topic/kubernetes/video/YAM2d7yTrrIz,https://videos.icts.res.in/video/d7HuP_abpKUc              	   C   s   |  |dd\}}| | j| |\}}| jd|||dddiddd	d
}|rht| d|gi|S |dr| | 	d ||t
|S td|r| |d|S tdd S )Nhostr   z4https://analytics.videoken.com/api/videoinfo_private)r'   org_idr   r   zDownloading VideoKen API JSONrF   F)queryr   r   Zerrnotefatalr%   r   z^[\w-]{11}$r*   z/Unable to extract without VideoKen API response)_match_valid_urlgroupr   r2   r   nextr.   
startswithr+   r$   r   r5   matchr   )r   r,   r"   r   r\   _r   r   r   r   _real_extract   s0       
  zVideoKenIE._real_extractN)	r/   r0   r1   r   r7   
_VALID_URLint_TESTSre   r   r   r   r   r9   F   s   
  $ !^r9   c                
   @   s<   e Zd ZdZdddddddd	d
dddidgZdd ZdS )VideoKenPlayerIEz;https?://player\.videoken\.com/embed/slideslive-(?P<id>\d+)z5https://player.videoken.com/embed/slideslive-38968434Z38968434r:   z-Deep Learning with Label Differential Privacyi|aZ20220128r;   zcount:30zcount:29r<   rD   rE   rZ   c                 C   s"   |  |}| | d ||t|S )N)Z	_match_idr+   r$   r   )r   r,   r   r   r   r   re      s    
  zVideoKenPlayerIE._real_extractN)r/   r0   r1   rf   rh   re   r   r   r   r   ri      s     ri   c                   @   s2   e Zd Zejd ZddddddgZdd	 Zd
S )VideoKenPlaylistIEz&(?:category/\d+/)?playlist/(?P<id>\d+)z5https://videos.icts.res.in/category/1822/playlist/381u   Z381zCosmology - The Next Decader   r>   r,   Zplaylist_mincountrG   c                 C   sl   |  |dd\}}| | j| |\}}| jd| d| d|ddidd	}| | ||||d
S )Nr[   r   z#https://analytics.videoken.com/api/z/playlistitems//r   r   zDownloading API JSON)r   r   r>   )r_   r`   r   r2   r   playlist_resultr.   get)r   r,   r"   Zplaylist_idr\   rd   r%   r   r   r   re      s      z VideoKenPlaylistIE._real_extractN)r/   r0   r1   r   r7   rf   rh   re   r   r   r   r   rj      s   
	rj   c                   @   sd   e Zd Zejd Zdddddddd	d
dddddddddgZdddZdd Zdd Z	dS )VideoKenCategoryIEz category/(?P<id>\d+)/?(?:$|[?#])z)https://videos.icts.res.in/category/1822/  Z1822ZProgramsrl   rm   z'https://videos.neurips.cc/category/350/"   Z350zNeurIPS 2018z$https://videos.cncf.io/category/479/iH  Z479z"KubeCon + CloudNativeCon Europe'19r   Nc              	   C   s>   | j d| d|d|r|nd| ||| jdddidp<i S )	Nr   z/category_videosFzDownloading category page )category_idZpage_numberlengthr   r   )r^   r   r]   r   r   r8   )r   rt   r\   pager   r   r   r   _get_category_page  s    
  z%VideoKenCategoryIE._get_category_pagec                 c   s(   |  |||d }| ||E d H  d S Nr   )rx   r.   )r   rt   r\   r,   rw   r%   r   r   r   _entries  s    zVideoKenCategoryIE._entriesc           	   	   C   s   |  |dd\}}| | j| |\}}| j||dd}|d }tt|d | j }| 	t
t| j||||| j||S )Nr[   r   zDownloading category infor   Zcategory_nameZrecordsTotal)r_   r`   r   r2   rx   mathceilrg   r8   ro   r   	functoolspartialrz   )	r   r,   r"   rt   r\   rd   Zcategory_infocategorytotal_pagesr   r   r   re     s      z VideoKenCategoryIE._real_extract)r   N)
r/   r0   r1   r   r7   rf   rh   rx   rz   re   r   r   r   r   rq      s.   


rq   c                   @   sd   e Zd Zejd Zdddddddd	d
dddddddddgZdddZdd Zdd Z	dS )VideoKenTopicIEz!topic/(?P<id>[^/#?]+)/?(?:$|[?#])z3https://videos.neurips.cc/topic/machine%20learning/rr   Zmachine_learningzmachine learningrl   rm   z7https://videos.icts.res.in/topic/gravitational%20waves/M   Zgravitational_waveszgravitational wavesz(https://videos.cncf.io/topic/prometheus/   Z
prometheusr   Nc                 C   sD   | j d|d|| j||dd|dd|d
dd	i|r2|nd
| dpBi S )Nz,https://es.videoken.com/api/v1.0/get_resultsFZupload_descalltrue )
Zorgidsizer]   rw   sortfiltertokenZis_topicr   Zsearchidr   r   zDownloading topic page )r^   r]   r   r   rv   )r   topicr\   	search_idapi_keyrw   r   r   r   r   _get_topic_page3  s(      zVideoKenTopicIE._get_topic_pagec                 c   s,   |  |||||d }| ||E d H  d S ry   )r   r.   )r   r   r\   r   r   r,   rw   r%   r   r   r   rz   C  s    zVideoKenTopicIE._entriesc           	      C   s   |  |dd\}}tj|}|dd}| | j| |\}}t	d| dt
t  d  }t| j||||ddd	 }| tt| j||||||| j||S )
Nr[   r    rd   :z
:transientzDownloading topic infor{   Ztotal_no_of_pages)r_   r`   r   r    unquotereplacer   r2   base64	b64encoderg   timeencodedecoder   r   ro   r   r~   r   rz   r8   )	r   r,   r"   Ztopic_idr   r\   r   r   r   r   r   r   re   G  s,    (      zVideoKenTopicIE._real_extract)r   N)
r/   r0   r1   r   r7   rf   rh   r   rz   re   r   r   r   r   r     s.   

r   )r   r~   r|   r5   r   urllib.parser   commonr   Z
slidesliver   utilsr   r   r   r	   r
   r   r   r   r9   ri   rj   rq   r   r   r   r   r   <module>   s   $1u2