
    V|h                     F    S SK r SSKJr  SSKJrJrJrJr   " S S\5      rg)    N   )InfoExtractor   )ExtractorErrorlowercase_escapeurl_or_noneurlencode_postdatac                       \ rS rSrSrSSSSSSS	.S
S0SS.SSS.SSS.SSS.SSS.SSS./rSSSSSS.rS rS rS r	Sr
g)ChaturbateIE   zahttps?://(?:[^/]+\.)?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                    U R                  SU S3U[        SU05      0 U R                  5       ESSS.ESSS	9=(       d    0 nUR                  S
5      nU(       di  UR                  S5      nU R                  R                  U5      =n(       a
  [        USS9eUS:X  a  U R                  5         U R                  SU S35        g UUSU S3SSU R                  XASSS9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errors          U/home/james-whalen/.local/lib/python3.13/site-packages/yt_dlp/extractor/chaturbate.py_extract_from_apiChaturbateIE._extract_from_api4   s   &&!#&=>#[($;<//1$4,  ' . 4 24 	 <<&\\-0F++F33u3$UT::!))+,vh6d ef FxjPTU11(%VZ1[
 	
    c                 ~  ^ U R                  SU SU S3UU R                  5       SS9m/ nU R                  U R                  STSSSS	9U[        S
S9nU(       a2  [        UR                  S5      5      nU(       a  UR                  U5        U(       dG  [        R                  " ST5       H,  nUR                  [	        UR                  S5      5      5        M.     U(       d>  [        R                  " ST5       H#  nUR                  UR                  S5      5        M%     / nU H7  nXR                  SS5      pX4 H  nXW;  d  M
  UR                  U5        M     M9     U(       dq  U R                  SS/TSSS S9nU(       d9  [        U4S jU R                  S   SS4 5       5      (       a  U R                  S   nU(       a
  [        USS9e[        S5      e/ nU HF  nS H  nSU 3U;   d  M  Un  O   S nUR                  U R!                  XQSUS:X  a  S OS US
SS!95        MH     UUS"U S#3U R#                  T5      SU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>   )rG   rF   c              3   ,   >#    U  H	  oT;   v   M     g 7f)N ).0pwebpages     r?   	<genexpr>2ChaturbateIE._extract_from_html.<locals>.<genexpr>y   s      W .VG| .Vs   r   offline_tippingtip_offliner)   zUnable to find stream URL)fastslow_r   rU   i)r   
preferencem3u8_idr&   r.   r,   r-   )r   r   r/   r   r   r0   )_download_webpager2   _parse_json_search_regexr   r   r3   appendrefinditerrG   replaceanyr4   r   extendr7   _rta_search)r8   r9   r:   found_m3u8_urlsr$   r<   m	m3u8_urlsfound_m3u8_urlm3u8_fast_urlm3u8_no_fast_urlr>   r0   known_idrY   rP   s                  @r?   _extract_from_htmlChaturbateIE._extract_from_htmlQ   s   ((!#az3X113 ) G LW  > '7u	   F
 "488L#9:H&&x0[[>I&&'7'GHI [[97D&&qwwu~6D 	-N.<>T>TU\^`>a+*=,$$X. > . &&SUW ' ?E  W	24E}.V W W W OOI6E$UT:: !<==!H,xj>X-&G -
 NN455")V"33u4	 6 9 : " FxjPTU))'2
 	
rB   c                     U R                  U5      R                  SS5      u  p#U R                  X#5      =(       d    U R                  X#5      $ )Nr   r:   )_match_valid_urlrG   r@   rk   )r8   r   r9   r:   s       r?   _real_extractChaturbateIE._real_extract   sC    --c288uE%%h4^8O8OPX8^^rB   rM   N)__name__
__module____qualname____firstlineno__
_VALID_URL_TESTSr4   r@   rk   ro   __static_attributes__rM   rB   r?   r   r      s    uJ5Q
 T
 " < 5 1 ; 53F> /8-:.J
:D
L_rB   r   )	r^   commonr   utilsr   r   r   r	   r   rM   rB   r?   <module>rz      s%    	 ! M_= M_rB   