U
    g                     @   s<   d dl Z ddlmZ ddlmZmZmZ G dd deZdS )    N   )InfoExtractor   )ExtractorErrorlowercase_escapeurl_or_nonec                   @   sL   e Zd ZdZdddddddd	did
dddddddgZdZdd ZdS )ChaturbateIEzNhttps?://(?:[^/]+\.)?chaturbate\.com/(?: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Room is currently offlinec                    s  |  |}| jd| d||  d g }| j| jd dddd|td	d
}|rlt|d}|rl|| |st	
d D ]}|t|d q||st	
d D ]}||d qg }|D ]6}||dd }	}
|	|
fD ]}||kr|| qq|s`| jddg ddd d}|sFt fdd| jddfD rF| j}|rXt|ddtdg }|D ]\}dD ] }d| |krp|} qqpd }|| j||d|dkrd nd |d	dd! qh||d"| d#|  d|d$S )%Nzhttps://chaturbate.com//)headersz9initialRoomDossier\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1dataz{}value)defaultgroupF)Ztransform_sourcefatalZ
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>[^<]+)<error)r   r   c                 3   s   | ]}| kV  qd S )N ).0pZwebpager   ?/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/chaturbate.py	<genexpr>N   s     z-ChaturbateIE._real_extract.<locals>.<genexpr>Zoffline_tippingZtip_offlineT)expectedzUnable to find stream URL)fastZslow_r	   r#   i)r   Z
preferencem3u8_idr   Zlivez+https://roomimg.stream.highwebmedia.com/ri/z.jpg)r   r   Z	thumbnailr   r   formats)Z	_match_idZ_download_webpageZgeo_verification_headersZ_parse_jsonZ_search_regexr   r   getappendrefinditerr   replaceany_ROOM_OFFLINEr   extendZ_extract_m3u8_formatsZ_rta_search)selfr   Zvideo_idZfound_m3u8_urlsr   Zm3u8_urlmZ	m3u8_urlsZfound_m3u8_urlZm3u8_fast_urlZm3u8_no_fast_urlr   r&   Zknown_idr%   r   r   r    _real_extract$   s    

      
       
    
zChaturbateIE._real_extractN)__name__
__module____qualname__Z
_VALID_URLZ_TESTSr-   r1   r   r   r   r    r      s,    r   )r)   commonr   utilsr   r   r   r   r   r   r   r    <module>   s   