o
    i                     @   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=5e7a859644e02200c6ef5f11 14b6e81d41beaaee2215cd75c6ed56e45e7a859644e02200c6ef5f11mp4zBChina Discovers Origin of Corona Virus: Issues Emergency Statementz8re:^https?://(?:www\.)?assets\.infowarsmedia.com/images/z$md5:560d96f02abbebe6c6b78b47465f6b2820200324iz^)idexttitle	thumbnaildescriptionupload_date	timestamp)urlmd5	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   )	variablesoperationNamequeryutf8)noteheadersdatar!   )_download_jsonjsondumps_GRAPHQL_QUERIESencodeget)selfvideo_idid_var	operationr    r,   P/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/bannedvideo.py	_call_apiW   s   zBannedVideoIE._call_apic                 c   sj    |E d H  |  D ](}|d}|ddkr2| ||dd| }|dD ]	}| ||V  q(q
d S )N_id
replyCountr   r   z Downloading replies for comment getCommentReplies)copyr'   r.   _parse_comment)r(   r)   commentscomment_datacomment
comment_id
reply_json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      | d d S )Nuserusernamer,   xr,   r,   r-   <lambda>r       z.BannedVideoIE._parse_comment.<locals>.<lambda>c                 S   r<   )Nr=   r/   r,   r?   r,   r,   r-   rA   s   rB   	createdAtc                 S   r<   )N	voteCountpositiver,   r?   r,   r,   r-   rA   v   rB   )r   textauthor	author_idr   parent
like_count)r'   r   r   )r5   rI   r,   r,   r-   r3   m   s   zBannedVideoIE._parse_commentc                    s:    |} ||dd}|d }|d} fdd|dD }t|dr4d	d
|dddgng }|drL| 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 metadatagetVideolivec                    s   g | ]}  |d qS )root)r3   ).0r6   r(   r,   r-   
<listcomp>~   s    z/BannedVideoIE._real_extract.<locals>.<listcomp>getVideoComments	directUrldirectr   r   )	format_idqualityr   r   	streamUrlm3u8_nativehlsT)entry_protocolm3u8_idrL   r   summaryc                 S   r<   )Nchannelr   r,   r?   r,   r,   r-   rA      rB   z-BannedVideoIE._real_extract.<locals>.<lambda>c                 S   r<   )Nr]   r/   r,   r?   r,   r,   r-   rA      rB   	playCount
largeImagevideoDurationrC   c                 S   s   g | ]}| d qS )name)r'   )rN   tagr,   r,   r-   rP      s    tagsunlisted)is_unlisted)r   r   formatsis_liver   r]   
channel_id
view_countr   durationr   rc   availabilityr4   __post_extractor)	_match_idr.   r'   r	   extend_extract_m3u8_formatsr   r   r   r   _availabilityextract_comments)r(   r   r)   
video_json
video_inforg   r4   rf   r,   rO   r-   _real_extracty   sF   


zBannedVideoIE._real_extractN)__name__
__module____qualname__
_VALID_URL_TESTS_GRAPHQL_GETMETADATA_QUERY!_GRAPHQL_GETCOMMENTSREPLIES_QUERYr%   r.   r:   staticmethodr3   rt   r,   r,   r,   r-   r
      s.    $
r
   )
r#   commonr   utilsr   r   r   r   r	   r
   r,   r,   r,   r-   <module>   s    	