a
    h                     @   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/Z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_liveZskip_downloadzRoom is offline)urlZ	info_dictparamsskipz*https://chaturbate.com/fullvideo/?b=caylin)r   Z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privateZawayzpassword protectedhiddenc                 C   s   | j d| d|td|ii |  dddddd	p:i }|d
}|s|d}| j| }rpt|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/Z	room_slugZXMLHttpRequestzapplication/json)zX-Requested-WithAcceptFT)dataheadersfatalimpersonater   Z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)	Z_download_jsonr   geo_verification_headersget
_ERROR_MAPr   Zraise_geo_restrictedZreport_warning_extract_m3u8_formats)selfvideo_idtldresponsem3u8_urlstatuserror r0   P/mnt/pikpak/tmp/myenv/lib/python3.9/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}|rjt|d}|rj|| |st	d D ]}|t|
d qz|st	d D ]}||
d qg }|D ]6}||dd }	}
|	|
fD ]}||vr|| qq|sf| jddg ddd d}|sLt fdd| jd ddfD rL| jd }|r^t|ddtdg }|D ]\}dD ] }d| |v rv|} qqvd }|| j||d|d krd!nd |d
dd" qn||d#| d$|  d|d%S )&Nr   /T)r   r   z9initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1r   z{}value)defaultgroupF)Ztransform_sourcer   Z
hls_sourcez'(\\u002[27])(?P<url>http.+?\.m3u8.*?)\1r   z"(["\'])(?P<url>http.+?\.m3u8.*?)\1Z_fast z?<span[^>]+class=(["\'])desc_span\1[^>]*>(?P<error>[^<]+)</span>zA<div[^>]+id=(["\'])defchat\1[^>]*>\s*<p><strong>(?P<error>[^<]+)<r/   )r6   r5   c                 3   s   | ]}| v V  qd S )Nr0   ).0pZwebpager0   r1   	<genexpr>y       z2ChaturbateIE._extract_from_html.<locals>.<genexpr>r   Zoffline_tippingZtip_offliner   zUnable to find stream URL)fastZslow_r
   r=   i)r   Z
preferencem3u8_idr   r"   r    r!   )r   r   r#   r   r   r$   )Z_download_webpager%   Z_parse_jsonZ_search_regexr   r   r&   appendrefinditerr6   replaceanyr'   r   extendr(   Z_rta_search)r)   r*   r+   Zfound_m3u8_urlsr   r-   mZ	m3u8_urlsZfound_m3u8_urlZm3u8_fast_urlZm3u8_no_fast_urlr/   r$   Zknown_idr?   r0   r:   r1   _extract_from_htmlQ   s    



zChaturbateIE._extract_from_htmlc                 C   s.   |  |dd\}}| ||p,| ||S )Nr   r+   )Z_match_valid_urlr6   r2   rG   )r)   r   r*   r+   r0   r0   r1   _real_extract   s    zChaturbateIE._real_extractN)	__name__
__module____qualname__Z
_VALID_URLZ_TESTSr'   r2   rG   rH   r0   r0   r0   r1   r	      sJ   Fr	   )	rA   commonr   utilsr   r   r   r   r	   r0   r0   r0   r1   <module>   s   