a
    h5                     @   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   N/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/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|v 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)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@   rA   	age_limitchannel_follower_count
view_countavailabilitylive_statusplayable_in_embed
categoriestagsrB   rC   rD   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?   rJ   rK   rL   rM   rN   rO   rP   rQ   rA   rR   rV   rU   rW   rS   Z
like_countrT   rX   rY   rB   rC   rD   r-   rH   rI   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 JSONrG   F)queryr   r   Zerrnotefatalr%   r   z^[\w-]{11}$r*   z/Unable to extract without VideoKen API response)_match_valid_urlgroupr   r3   r   nextr/   
startswithr,   r$   r   r6   matchr   )r   r-   r"   r   r]   _r   r   r   r   _real_extract   s&    
zVideoKenIE._real_extractN)	r0   r1   r2   r   r8   
_VALID_URLint_TESTSrf   r   r   r   r   r:   F   s   
$!^r:   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=   rE   rF   r[   c                 C   s"   |  |}| | d ||t|S )N)Z	_match_idr,   r$   r   )r   r-   r   r   r   r   rf      s    
zVideoKenPlayerIE._real_extractN)r0   r1   r2   rg   ri   rf   r   r   r   r   rj      s   rj   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_mincountrH   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`   ra   r   r3   r   playlist_resultr/   get)r   r-   r"   Zplaylist_idr]   re   r%   r   r   r   rf      s    
z VideoKenPlaylistIE._real_extractN)r0   r1   r2   r   r8   rg   ri   rf   r   r   r   r   rk      s   
	rk   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Programsrm   rn   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   r9   )r   ru   r]   pager   r   r   r   _get_category_page  s    z%VideoKenCategoryIE._get_category_pagec                 c   s(   |  |||d }| ||E d H  d S Nr   )ry   r/   )r   ru   r]   r-   rx   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`   ra   r   r3   ry   mathceilrh   r9   rp   r   	functoolspartialr{   )	r   r-   r"   ru   r]   re   Zcategory_infocategorytotal_pagesr   r   r   rf     s    z VideoKenCategoryIE._real_extract)r   N)
r0   r1   r2   r   r8   rg   ri   ry   r{   rf   r   r   r   r   rr      s.   


rr   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/rs   Zmachine_learningzmachine learningrm   rn   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^   rx   sortfiltertokenZis_topicr   Zsearchidr   r   zDownloading topic page )r_   r^   r   r   rw   )r   topicr]   	search_idapi_keyrx   r   r   r   r   _get_topic_page3  s$    zVideoKenTopicIE._get_topic_pagec                 c   s,   |  |||||d }| ||E d H  d S rz   )r   r/   )r   r   r]   r   r   r-   rx   r%   r   r   r   r{   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    re   :z
:transientzDownloading topic infor|   Ztotal_no_of_pages)r`   ra   r   r    unquotereplacer   r3   base64	b64encoderh   timeencodedecoder   r   rp   r   r   r   r{   r9   )	r   r-   r"   Ztopic_idr   r]   r   r   r   r   r   r   rf   G  s     (
zVideoKenTopicIE._real_extract)r   N)
r0   r1   r2   r   r8   rg   ri   r   r{   rf   r   r   r   r   r     s.   

r   )r   r   r}   r6   r   urllib.parser   commonr   Z
slidesliver   utilsr   r   r   r	   r
   r   r   r   r:   rj   rk   rr   r   r   r   r   r   <module>   s   $1u2