o
    i                     @   s@   d dl Z ddlmZ ddlmZmZmZmZ G dd deZdS )    N   )InfoExtractor   )ExtractorErrorlowercase_escapeurl_or_noneurlencode_postdatac                   @   s   e Zd ZdZdddddddd	did
ddddddddddddddddgZddddddZdd Zdd Zdd ZdS )ChaturbateIEzahttps?://(?:[^/]+\.)?chaturbate\.(?P<tld>com|eu|global)/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)z$https://www.chaturbate.com/siswet19/siswet19mp4z:re:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$   T)idexttitle	age_limitis_liveskip_downloadzRoom is offline)url	info_dictparamsskipz*https://chaturbate.com/fullvideo/?b=caylin)r   only_matchingz#https://en.chaturbate.com/siswet19/zhttps://chaturbate.eu/siswet19/z)https://chaturbate.eu/fullvideo/?b=caylinz#https://chaturbate.global/siswet19/zRoom is currently offlinez#Room is currently in a private showzPerformer is currently awayzRoom is password protectedzHidden session in progress)offlineprivateawayzpassword protectedhiddenc                 C   s   | j d| d|td|ii |  dddddd	pi }|d
}|sK|d}| j| }r8t|dd|dkr@|   | d| d d S ||d| ddd| j||ddddS )Nhttps://chaturbate.z/get_edge_hls_url_ajax/	room_slugXMLHttpRequestzapplication/json)zX-Requested-WithAcceptFT)dataheadersfatalimpersonater   room_statusexpectedpubliczGot status "z." from API; falling back to webpage extraction+https://roomimg.stream.highwebmedia.com/ri/.jpgr   r   )r   live)r   r   	thumbnailr   r   formats)	_download_jsonr   geo_verification_headersget
_ERROR_MAPr   raise_geo_restrictedreport_warning_extract_m3u8_formats)selfvideo_idtldresponsem3u8_urlstatuserror r;   O/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/chaturbate.py_extract_from_api4   s:   

	

zChaturbateIE._extract_from_apic                    s  | j d| d| d||  dd g }| j| jd dddd	|td
d}|r5t|d}|r5|| |sJt	d D ]}|t|
d q=|s]t	d D ]
}||
d qRg }|D ]}||dd}	}
|	|
fD ]}||vr{|| qpqa|s| jddg ddd d}|st fdd| jd ddfD r| jd }|rt|ddtdg }|D ])}dD ]}d| |v r|} nqd }|| j||d|d krd!nd |d
dd" q||d#| d$|  d|d%S )&Nr   /T)r!   r#   z9initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1r    z{}value)defaultgroupF)transform_sourcer"   
hls_sourcez'(\\u002[27])(?P<url>http.+?\.m3u8.*?)\1r   z"(["\'])(?P<url>http.+?\.m3u8.*?)\1_fast z?<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>zA<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<r:   )rA   r@   c                 3   s    | ]}| v V  qd S )Nr;   ).0pwebpager;   r<   	<genexpr>y   s    z2ChaturbateIE._extract_from_html.<locals>.<genexpr>r   offline_tippingtip_offliner%   zUnable to find stream URL)fastslow_r   rM   i)r   
preferencem3u8_idr"   r*   r(   r)   )r   r   r+   r   r   r,   )_download_webpager.   _parse_json_search_regexr   r   r/   appendrefinditerrA   replaceanyr0   r   extendr3   _rta_search)r4   r5   r6   found_m3u8_urlsr    r8   m	m3u8_urlsfound_m3u8_urlm3u8_fast_urlm3u8_no_fast_urlr:   r,   known_idrQ   r;   rH   r<   _extract_from_htmlQ   s   





zChaturbateIE._extract_from_htmlc                 C   s.   |  |dd\}}| ||p| ||S )Nr   r6   )_match_valid_urlrA   r=   rc   )r4   r   r5   r6   r;   r;   r<   _real_extract   s   zChaturbateIE._real_extractN)	__name__
__module____qualname__
_VALID_URL_TESTSr0   r=   rc   re   r;   r;   r;   r<   r	      sL    Fr	   )	rV   commonr   utilsr   r   r   r   r	   r;   r;   r;   r<   <module>   s    