U
    g                     @   sD   d dl Z ddlmZ ddlmZmZmZmZmZ G dd deZ	dS )    N   )InfoExtractor   )float_or_noneint_or_nonetry_getunified_timestampurl_or_nonec                
   @   sd   e Zd ZdZdddddddd	d
ddgZdZdZeedZdd Zdd Z	e
dd Zdd ZdS )BannedVideoIEz<https?://(?:www\.)?banned\.video/watch\?id=(?P<id>[0-f]{24})z6https://banned.video/watch?id=5e7a859644e02200c6ef5f11Z 14b6e81d41beaaee2215cd75c6ed56e4Z5e7a859644e02200c6ef5f11mp4zBChina Discovers Origin of Corona Virus: Issues Emergency Statementz8re:^https?://(?:www\.)?assets\.infowarsmedia.com/images/z$md5:560d96f02abbebe6c6b78b47465f6b28Z20200324iz^)idexttitle	thumbnaildescriptionZupload_date	timestamp)urlmd5Z	info_dictaQ  
query GetVideoAndComments($id: String!) {
    getVideo(id: $id) {
        streamUrl
        directUrl
        unlisted
        live
        tags {
            name
        }
        title
        summary
        playCount
        largeImage
        videoDuration
        channel {
            _id
            title
        }
        createdAt
    }
    getVideoComments(id: $id, limit: 999999, offset: 0) {
        _id
        content
        user {
            _id
            username
        }
        voteCount {
            positive
        }
        createdAt
        replyCount
    }
}a  
query GetCommentReplies($id: String!) {
    getCommentReplies(id: $id, limit: 999999, offset: 0) {
        _id
        content
        user {
            _id
            username
        }
        voteCount {
            positive
        }
        createdAt
        replyCount
    }
})GetVideoAndCommentsGetCommentRepliesc                 C   s<   | j d||dditd|i|| j| ddddS )	Nz%https://api.infowarsmedia.com/graphqlzContent-Typezapplication/json; charset=utf-8r   )	variablesZoperationNamequeryutf8)noteheadersdatar   )Z_download_jsonjsondumps_GRAPHQL_QUERIESencodeget)selfvideo_idZid_varZ	operationr    r#   @/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/bannedvideo.py	_call_apiW   s"       zBannedVideoIE._call_apic                 c   sh   |E d H  |  D ]P}|d}|ddkr| ||dd| }|dD ]}| ||V  qNqd S )N_idZ
replyCountr   r   z Downloading replies for comment ZgetCommentReplies)copyr    r%   _parse_comment)r!   r"   commentscomment_datacommentZ
comment_idZ
reply_jsonZreplyr#   r#   r$   _get_commentsb   s    

  zBannedVideoIE._get_commentsc              
   C   sH   |  d|  dt| dd t| dd t|  d|t| dd dS )	Nr&   contentc                 S   s   | d d S )Nuserusernamer#   xr#   r#   r$   <lambda>r       z.BannedVideoIE._parse_comment.<locals>.<lambda>c                 S   s   | d d S )Nr.   r&   r#   r0   r#   r#   r$   r2   s   r3   	createdAtc                 S   s   | d d S )NZ	voteCountZpositiver#   r0   r#   r#   r$   r2   v   r3   )r   textauthorZ	author_idr   parentZ
like_count)r    r   r   )r*   r7   r#   r#   r$   r(   m   s    zBannedVideoIE._parse_commentc                    s:    |} ||dd}|d }|d} fdd|dD }t|drhd	d
|dddgng }|dr| j|d|ddddd ||dd d |||dt|dd t|dd t|dt|dt|dt	|ddd |dD  j
|dd| |||dd S )!Nr   zDownloading video metadataZgetVideolivec                    s   g | ]}  |d qS )root)r(   ).0r+   r!   r#   r$   
<listcomp>~   s     z/BannedVideoIE._real_extract.<locals>.<listcomp>ZgetVideoCommentsZ	directUrldirectr   r   )Z	format_idZqualityr   r   Z	streamUrlZm3u8_nativeZhlsT)Zentry_protocolZm3u8_idr8   r   summaryc                 S   s   | d d S )Nchannelr   r#   r0   r#   r#   r$   r2      r3   z-BannedVideoIE._real_extract.<locals>.<lambda>c                 S   s   | d d S )Nr@   r&   r#   r0   r#   r#   r$   r2      r3   Z	playCountZ
largeImageZvideoDurationr4   c                 S   s   g | ]}| d qS )name)r    )r:   tagr#   r#   r$   r<      s     tagsZunlisted)Zis_unlisted)r   r   formatsis_liver   r@   Z
channel_idZ
view_countr   durationr   rC   Zavailabilityr)   Z__post_extractor)Z	_match_idr%   r    r	   extendZ_extract_m3u8_formatsr   r   r   r   Z_availabilityZextract_comments)r!   r   r"   Z
video_jsonZ
video_inforE   r)   rD   r#   r;   r$   _real_extracty   sN    


    zBannedVideoIE._real_extractN)__name__
__module____qualname__Z
_VALID_URLZ_TESTSZ_GRAPHQL_GETMETADATA_QUERYZ!_GRAPHQL_GETCOMMENTSREPLIES_QUERYr   r%   r,   staticmethodr(   rH   r#   r#   r#   r$   r
      s,   $
r
   )
r   commonr   utilsr   r   r   r   r	   r
   r#   r#   r#   r$   <module>   s   	