U
    $Pf                     @   s   d dl mZ ddlmZ ddlmZ ddl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 )    )unicode_literals   )InfoExtractor   )
compat_str)
clean_html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   s@   d| }|  |d}| j||d| d|r2|jndd|dS )Nzhttps://www.minds.com/api/z
XSRF-TOKENzDownloading %s JSON metadata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-7zdooeg3/youtube_dl/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p0|d}|rV| j
||dd}|rV| }||dpf||t|dpzd t|dt|dt|	d|
|
rd|
 n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namer   z
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   Z_sort_formats
isinstancer   Z_request_webpagegeturlr   r	   r
   )r   r/   Z	entity_idr2   r   r4   r@   sourcer7   ownerr%   r,   r$   r<   Zurlhr   r   r   _real_extractG   st    
  
  




zMindsIE._real_extractN)
r   r   r   IE_NAMEr   r   
_VALID_URLintZ_TESTSrI   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p4g }|D ],}|d}|sNq:| d| t |V  q:|d |d	< |d	 rt|| j ksq|d7 }qd S )
Nr   )limitsynczv2/feeds/container/%s/videoszpage %sentitiesguidzhttps://www.minds.com/newsfeed/z	load-nextZfrom_timestamp)
_PAGE_SIZEr   r   rB   r   Zie_keylen)r   feed_idr   idatarQ   r2   rR   r   r   r   _entries   s,      
 zMindsFeedBaseIE._entriesc                 C   sT   |  |}| d| j|f || j| j }| | |d |t|d|dS )Nzv1/%s/%srR   r?   Zbriefdescription)rA   r   
_FEED_PATH
_FEED_TYPEZplaylist_resultrX   r
   r   )r   r/   rU   feedr   r   r   rI      s    
  zMindsFeedBaseIE._real_extractN)r   r   r   rS   rX   rI   r   r   r   r   rM      s   rM   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/   r1   Zplaylist_mincountN
r   r   r   rZ   rJ   r   r   rK   rY   Z_TESTr   r   r   r   r\      s   
r\   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   ra      s   
ra   N)
__future__r   commonr   compatr   utilsr   r   r	   r
   r   r   rM   r\   ra   r   r   r   r   <module>   s   j#