U
    Mfz                     @   s|   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	G dd	 d	eZ
G d
d de
ZG dd de
ZdS )   )InfoExtractor   )
clean_htmlformat_fieldint_or_nonestr_or_nonestrip_or_nonec                   @   s   e Zd ZdZdddZdS )MindsBaseIEzhttps?://(?:www\.)?minds\.com/Nc                 C   sD   d| }|  |d}| j||d| dd|r6|jndd|dS )	Nzhttps://www.minds.com/api/z
XSRF-TOKENzDownloading z JSON metadatazhttps://www.minds.com/ )ZRefererzX-XSRF-TOKEN)headersquery)Z_get_cookiesgetZ_download_jsonvalue)selfpathvideo_idresourcer   Zapi_urltoken r   :/tmp/pip-unpacked-wheel-zk9bgjdq/yt_dlp/extractor/minds.py	_call_api   s      
zMindsBaseIE._call_api)N)__name__
__module____qualname___VALID_URL_BASEr   r   r   r   r   r	      s   r	   c                   @   sz   e Zd ZdZejd Zddddddd	d
ddeeedgeddddddddddddddddddddgZdd Z	dS )MindsIEZmindsz.(?:media|newsfeed|archive/view)/(?P<id>[0-9]+)z.https://www.minds.com/media/100000000000086822Z 215a658184a419764852239d4970b045Z100000000000086822Zmp4zMinds intro sequencezre:https?://.+\.pngottmanZ20130524iuQBill OttmanZ	animationzattribution-cc)idexttitle	thumbnailuploader_idupload_date	timestampuploader
view_count
like_countdislike_counttagscomment_countlicense)urlmd5	info_dictz1https://www.minds.com/newsfeed/798025111988506624Z b2733a74af78d7fd3f541c4cbbaa5950Z798022190320226304ZColinFlahertyZ20180111iVZ)r   r   r    r%   r#   r$   r"   z5https://www.minds.com/archive/view/715172106794442752T)r,   Zonly_matchingz2https://www.minds.com/newsfeed/1197131838022602752c                 C   s  |  |}| d| |dd }|ddkrV|ddkrF|d }qj| |d S n|d	 dksft|}| d
| |d}g }|dpg D ]6}|d}|sq||dt|d|d q|dp|}|dpi }	|	d}
|d}|rt|tr|g}d }|dp&|d}|rJ| j	||dd}|rJ|j
}||dpZ||t|dpnd t|dt|dt|	d|
t|
d dt|dt|dt|d|t|d |d!S )"Nzv1/entities/entity/entitytypeZactivityZcustom_typevideoZentity_guidZ	perma_urlsubtypezv2/media/video/sourcessrclabelsize)Z	format_idheightr,   ZownerObjusernamer)   posterZthumbnail_srcF)fatalr    descriptionr+   Ztime_creatednamezhttps://www.minds.com/%sz
play:countzthumbs:up:countzthumbs:down:countzcomments:count)r   r    formatsr;   r+   r$   r%   r"   Zuploader_urlr&   r'   r(   r)   r*   r!   )	_match_idr   r   
url_resultAssertionErrorappendr   
isinstancestrZ_request_webpager,   r   r   r   r   )r   r,   Z	entity_idr/   r   r1   r=   sourcer4   ownerr"   r)   r!   r9   Zurlhr   r   r   _real_extractD   sr    
  
  




zMindsIE._real_extractN)
r   r   r   IE_NAMEr	   r   
_VALID_URLintZ_TESTSrF   r   r   r   r   r      sN   
)r   c                   @   s    e Zd ZdZdd Zdd ZdS )MindsFeedBaseIE   c                 c   s   | j dd}d}| d| d|d| |}|dp:g }|D ],}|d}|sTq@| d| t |V  q@|d	 |d
< |d
 rt|| j ksq|d7 }qd S )Nr   )limitsynczv2/feeds/container/z/videoszpage entitiesguidzhttps://www.minds.com/newsfeed/z	load-nextZfrom_timestamp)
_PAGE_SIZEr   r   r?   r   Zie_keylen)r   feed_idr   idatarN   r/   rO   r   r   r   _entries   s,    
  
 zMindsFeedBaseIE._entriesc                 C   sX   |  |}| d| j d| || j| j }| | |d |t|d|dS )Nzv1//rO   r<   Zbriefdescription)r>   r   
_FEED_PATH
_FEED_TYPEZplaylist_resultrU   r   r   )r   r,   rR   feedr   r   r   rF      s    
  zMindsFeedBaseIE._real_extractN)r   r   r   rP   rU   rF   r   r   r   r   rJ      s   rJ   c                   @   s:   e Zd ZdZde Zejd ZdZdddddd	d
Z	dS )MindsChannelIEZchannelminds:z:(?!(?:newsfeed|media|api|archive|groups)/)(?P<id>[^/?&#]+)zhttps://www.minds.com/ottmanr   r   zCo-creator & CEO @minds)r   r    r;   6   r,   r.   Zplaylist_mincountN
r   r   r   rX   rG   r	   r   rH   rW   Z_TESTr   r   r   r   rZ      s   
rZ   c                   @   s8   e Zd ZdZde Zejd ZdZddddd	d
Z	dS )MindsGroupIEgroupr[   zgroups/profile/(?P<id>[0-9]+)zgroups/groupzChttps://www.minds.com/groups/profile/785582576369672204/feed/videosZ785582576369672204zCooking Videos)r   r    r   r]   Nr^   r   r   r   r   r_      s   
r_   N)commonr   utilsr   r   r   r   r   r	   r   rJ   rZ   r_   r   r   r   r   <module>   s   	i#