o
    i5                     @   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 )VideoKenBaseIEictscncf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idapikey)_download_json)selforgvideo_iddetails r   M/home/ubuntu/.local/lib/python3.10/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|r(t||dtj|j dS |S )Nzembed/sign-inzhttps://slideslive.com/embed/slideslive-zhttps://)embed_parent_urlembed_container_origin)r	   r   r   urllibparseurlparsehostname)r   	video_urlr   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
}|s+qtj|jdkr=t}| |||}| |||V  qd S )N))videosresults.
youtube_idvideoidtypesourceyoutubeYoutube	embed_urlembeddableurl)expected_typezslideslive.com)	r
   r   r%   r&   r'   r(   r   r+   
url_result)r   r,   urlvideor   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                   @   sx  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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)d*d+d,ed-ed.d/d0d1gg d2d3d4d5ddidgdd6i dd7dddd8dd9dd:dd;dd<d d:d!d=d"d>d$d?d(d@d*d+dAd/dBdCdDd0d,eeedEgg d2dFdGdHddidIdJd0dKdLd0dKdMd0dKgZdNdO ZdPS )Q
VideoKenIEz4(?:(?:topic|category)/[^/#?]+/)?video/(?P<id>[\w-]+)z3https://videos.neurips.cc/video/slideslive-3892281538922815mp4zVEfficient Processing of Deep Neural Network: from Algorithms to Hardware Architecturesi(6a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)r8   	info_dictparamsexpected_warningszLhttps://videos.neurips.cc/topic/machine%20learning/video/slideslive-38923348r   2Xa_dt78rJErL   
display_id38923348rM   zMachine EducationdescriptionzDWatch full version of this video at https://slideslive.com/38923348.channelzSlidesLive Videos - G2
channel_idUCOExahQQ588Da8Nft_Ltb9wchannel_urlz8https://www.youtube.com/channel/UCOExahQQ588Da8Nft_Ltb9wuploaderuploader_iduploader_urlz7http://www.youtube.com/channel/UCOExahQQ588Da8Nft_Ltb9wdurationi	  rN   i~`rO   20200131	age_limitr   channel_follower_count
view_countunlistednot_liveTzPeople & Blogszre:^https?://.*\.(?:jpg|webp)zcount:78zcount:77)availabilitylive_statusplayable_in_embed
categoriestagsrP   rQ   rR   zDhttps://videos.icts.res.in/topic/random%20variable/video/zysIsojYdvc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-nc8mABUJIQ	ICTStalksz%http://www.youtube.com/user/ICTStalksi,  20191004rl   rk   publicrm   zScience & Technologyzcount:42zcount:20)
like_countrh   rn   ro   rP   rQ   rR   r8   rV   rW   z5https://videos.cncf.io/category/478/video/IL4nxbmUIX8)r8   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
}|r4t| d|gi|S |drE| | 	d ||t
|S td|rR| |d|S td)Nhostr   z4https://analytics.videoken.com/api/videoinfo_private)r/   org_idr   r   zDownloading VideoKen API JSONrU   F)queryr   r   errnotefatalr,   r"   z^[\w-]{11}$r3   z/Unable to extract without VideoKen API response)_match_valid_urlgroupr!   r?   r   nextr;   
startswithr7   r+   r   rB   matchr   )r   r8   r(   r   rx   _r   r   r   r    _real_extract   s&   
zVideoKenIE._real_extractN)	r<   r=   r>   r   rD   
_VALID_URLint_TESTSr   r   r   r   r    rF   F   s    
	
$	
!^rF   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-3896843438968434rH   z-Deep Learning with Label Differential Privacyi|a20220128rJ   zcount:30zcount:29rK   rS   rT   ru   c                 C   s"   |  |}| | d ||t|S )N)	_match_idr7   r+   r   )r   r8   r   r   r   r    r      s   
zVideoKenPlayerIE._real_extractN)r<   r=   r>   r   r   r   r   r   r   r    r      s     r   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   381zCosmology - The Next Decader   rM   r8   playlist_mincountrV   c                 C   sl   |  |dd\}}| | j| |\}}| jd| d| d|ddidd	}| | ||||d
S )Nrw   r   z#https://analytics.videoken.com/api/z/playlistitems//r   r   zDownloading API JSON)r   r   rM   )r|   r}   r!   r?   r   playlist_resultr;   get)r   r8   r(   playlist_idrx   r   r,   r   r   r    r      s   
z VideoKenPlaylistIE._real_extractN)r<   r=   r>   r   rD   r   r   r   r   r   r   r    r      s    
	r   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/  1822Programsr   r   z'https://videos.neurips.cc/category/350/"   350zNeurIPS 2018z$https://videos.cncf.io/category/479/iH  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_idpage_numberlengthr   r   )r{   r   ry   r   r   rE   )r   r   rx   pager   r   r   r    _get_category_page  s   z%VideoKenCategoryIE._get_category_pagec                 c   s*    |  |||d }| ||E d H  d S Nr   )r   r;   )r   r   rx   r8   r   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 )Nrw   r   zDownloading category infor   category_namerecordsTotal)r|   r}   r!   r?   r   mathceilr   rE   r   r   	functoolspartialr   )	r   r8   r(   r   rx   r   category_infocategorytotal_pagesr   r   r    r     s   z VideoKenCategoryIE._real_extractr   N)
r<   r=   r>   r   rD   r   r   r   r   r   r   r   r   r    r      s0    


r   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/r   machine_learningzmachine learningr   r   z7https://videos.icts.res.in/topic/gravitational%20waves/M   gravitational_waveszgravitational wavesz(https://videos.cncf.io/topic/prometheus/   
prometheusr   Nc                 C   sD   | j d|d|| j||dd|dd|d
dd	i|r|nd
| dp!i S )Nz,https://es.videoken.com/api/v1.0/get_resultsFupload_descalltrue )
orgidsizery   r   sortfiltertokenis_topicr   searchidr   r   zDownloading topic page )r{   ry   r   r   r   )r   topicrx   	search_idapi_keyr   r   r   r   r    _get_topic_page3  s$   zVideoKenTopicIE._get_topic_pagec                 c   s.    |  |||||d }| ||E d H  d S r   )r   r;   )r   r   rx   r   r   r8   r   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 )
Nrw   r    r   :z
:transientzDownloading topic infor   total_no_of_pages)r|   r}   r%   r&   unquotereplacer!   r?   base64	b64encoder   timeencodedecoder   r   r   r   r   r   r   rE   )	r   r8   r(   topic_idr   rx   r   r   r   r   r   r    r   G  s    (
zVideoKenTopicIE._real_extractr   )
r<   r=   r>   r   rD   r   r   r   r   r   r   r   r   r    r     s0    

r   )r   r   r   rB   r   urllib.parser%   commonr   
slidesliver   utilsr   r   r   r	   r
   r   r   r   rF   r   r   r   r   r   r   r   r    <module>   s    $1u2