U
    Mf4                     @   sX   d dl Z ddlmZ ddlmZmZmZmZmZm	Z	 G dd deZ
G dd	 d	eZdS )
    N   )InfoExtractor   )
clean_htmlint_or_noneparse_codecsparse_duration
str_to_intunified_timestampc                   @   s2   e Zd ZdZdddddddd	d
gZdd ZdS )GabTVIEz;https?://tv\.gab\.com/channel/[^/]+/view/(?P<id>[a-z0-9-]+)zbhttps://tv.gab.com/channel/wurzelroot/view/why-was-america-in-afghanistan-61217eacea5665de450d0488Z61217eacea5665de450d0488mp4zIWHY WAS AMERICA IN AFGHANISTAN - AMERICA FIRST AGAINST AMERICAN OLIGARCHYZ
WurzelrootZ608fb0a85738fd1974984f7dz1https://tv.gab.com/image/61217eacea5665de450d0488)idexttitleuploaderuploader_id	thumbnail)url	info_dictc                 C   s"  |  |dd }| ||}| d|d}| d|d}| d|d}| d	|d
}t| j| d|dddpvd }td| d|}	g }
|	D ]r}d| d| d| |dddd}d|krt	|
dd|d< d|d< d|d< nt	|
dd|d< |
| q|||
|||d| d S )!N-z(data-channel-id=\"(?P<channel_id>[^\"]+)
channel_idz*data-channel-name=\"(?P<channel_id>[^\"]+)channel_namez+data-episode-title=\"(?P<channel_id>[^\"]+)r   z&data-view-key=\"(?P<channel_id>[^\"]+)view_keydescriptioncontent)groupz<a\ data-episode-id=\"z,\"\ data-resolution=\"(?P<resolution>[^\"]+)zhttps://tv.gab.com/media/z	?viewKey=z&r=Zh264Zaacr   )r   Z	format_idZvcodecacodecr   zaudio- Zabr   heightiZqualitypzhttps://tv.gab.com/image/)r   r   formatsr   r   r   r   )	_match_idsplitZ_download_webpageZ_search_regexr   Z_html_search_regexZ_meta_regexrefindallr	   replaceappend)selfr   Zvideo_idZwebpager   r   r   r   r   Zavailable_resolutionsr"   
resolutionZfrmt r+   8/tmp/pip-unpacked-wheel-zk9bgjdq/yt_dlp/extractor/gab.py_real_extract   sJ    
 
zGabTVIE._real_extractN__name__
__module____qualname__Z
_VALID_URLZ_TESTSr-   r+   r+   r+   r,   r      s   r   c                   @   sR   e Zd ZdZddd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 )GabIEz3https?://(?:www\.)?gab\.com/[^/]+/posts/(?P<id>\d+)z7https://gab.com/SomeBitchIKnow/posts/107163961867310434Z 8ca34fb00f1e1033b5c5988d79ec531dz107163961867310434-0r   zL on GabZ946600ZSomeBitchIKnowz$md5:204055fafd5e1a519f5d6db953567ca3iwaZ20211025)r   r   r   r   r   r   	timestampupload_date)r   md5r   z7https://gab.com/TheLonelyProud/posts/107045884469287653Z f9cefcfdff6418e392611a828d47839dz107045884469287653-0zJody Sadowski on GabZ1390705i[aZ20211004ZTheLonelyProud)r   r   r   r   r3   r4   r   c           
         s  |  |}| d| |}g }t|d D ]0\}}|ddkrFq,|d }t|ddt|dpnd	d
d |dd  fdd|d|dpi f|d|dpi ffD }|dpi }	|| d| |d d  dt|d|t	|d|dp&t
|d|d|d|d|	d|	d |	dd! q,t|d"krz| ||S |d S )#Nz https://gab.com/api/v1/statuses/Zmedia_attachmentstype)videoZgifvmetaZaudio_encoder   Zaudio_bitrater    r   fps)r   Zasrr:   c              	      s@   g | ]8\}}|r|| d | dt| dddd qS )widthr    Zbitratei  )Zscale)r   r;   r    Ztbr)getr   ).0r   fZformat_metadatar+   r,   
<listcomp>p   s   z'GabIE._real_extract.<locals>.<listcomp>r   originalZ
source_mp4Zplayableaccountr   Zdisplay_namez on GabZ
created_atr   durationlengthZfavourites_countZreplies_countZreblogs_countusernamer   )r   r   r3   r"   r   rC   Z
like_countZcomment_countZrepost_countr   r   Zuploader_urlr   )r#   Z_download_json	enumerater<   r   r   r$   r(   r
   r   r   lenZplaylist_result)
r)   r   Zpost_idZ	json_dataentriesidxZmediametadatar"   authorr+   r?   r,   r-   a   sD    

	
zGabIE._real_extractNr.   r+   r+   r+   r,   r2   D   s4   r2   )r%   commonr   utilsr   r   r   r   r	   r
   r   r2   r+   r+   r+   r,   <module>   s    
6