
    OJni+                     R    d dl Z d dlZddlmZmZ ddlmZ ddlmZ  G d de      Z	y)	    N   )
StreamDatawrap_stream)	async_req   )BaseLiveStreamc                        e Zd ZdZddedz  dedz  f fdZdefdZdded	edefd
Z	e
ddedeez  dz  defd       Z xZS )RedNoteLiveStreamzN
    A class for fetching and processing RedNote live stream information.
    N
proxy_addrcookiesc                 P    t         |   ||       | j                         | _        y N)super__init___get_mobile_headersmobile_headers)selfr   r   	__class__s      X/home/uftp/myenv/lib/python3.12/site-packages/streamget/platforms/rednote/live_stream.pyr   zRedNoteLiveStream.__init__   s#    W-"668    returnc                     ddddS )Nz;ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))z/platform=iOS&sid=session.1722166379345546829388zhttps://app.xhs.cn/)z
user-agentzxy-common-paramsreferer )r   s    r   r   z%RedNoteLiveStream._get_mobile_headers   s    W Q,
 	
r   urlprocess_datac                 *  K   d|v r+t        || j                  | j                  d       d{   }| j                  |d      }t	        j
                  d|      }|r|j                  d      n|}dd	d
}t        || j                  | j                         d{   }t	        j
                  d|      }|r|j                  d      j                  dd      }t        j                  |      }	|s|	S |	j                  d      r|	d   }
|
j                  d      dk(  r|
d   d   }|j                  d      }|ryd|vru|d   }| j                  |d      }| j                  |d      }|j                  d      d   j                  d      d   }d| d}|j                  dd      }||d||||dz  }|S d | }t        || j                  | j                         d{   }t	        j
                  d!|      }|r|j                  d      |d"<   |S 7 7 u7 8w)#a)  
        Fetches app stream data for a live room.

        Args:
            url (str): The room URL.
            process_data (bool): Whether to process the data. Defaults to True.

        Returns:
            dict: A dictionary containing anchor name, live status, room URL, and title.
        zxhslink.comT)r   headersredirect_urlNhost_idz/user/profile/(.*?)(?=/|\?|$)    F)anchor_nameis_live)r   r   z/<script>window.__INITIAL_STATE__=(.*?)</script>	undefinednull
liveStream
liveStatussuccessroomDataroomInfo	roomTitleu   回放deeplinkhost_nicknameflvUrlzlive/.r   z(http://live-source-play.xhscdn.com/live/z.flvz.m3u8)r#   r$   titleflv_urlm3u8_url
record_urlz)https://www.xiaohongshu.com/user/profile/u%   <title>@(.*?) 的个人主页</title>r#   )r   r   r   
get_paramsresearchgroupreplacejsonloadsgetsplit)r   r   r   r    user_idresulthtml_str
match_datajson_str	json_datastream_data	room_infor1   	live_linkr#   r2   room_idr3   profile_urls                      r   fetch_app_stream_dataz'RedNoteLiveStream.fetch_app_stream_data   s     C!#$//4K^K^mqrrC//#y1))<cB&-'--"7!#6"34??DL_L_``YYPRZ[
!''*22;GH

8,I  }}\*'5??<0I= +J 7
 CI%MM+6E!6$-j$9	&*ooi&Q"&//)X"F")--"8";"A"A#"Fq"I$LWIUY"Z#*??67#C+6'+%*'.(0*1#   &A'K";4??TXTgTghhii GR$/$5$5a$8F=!W s a@ is5   +HHA+HHD>HH3HHHrC   video_qualityc                 .   K   | ddiz  } t        |       S w)z_
        Fetches the stream URL for a live room and wraps it into a StreamData object.
        platformu	   小红书)r   )rC   rJ   s     r   fetch_stream_urlz"RedNoteLiveStream.fetch_stream_urlQ   s"     
 	j+..	9%%s   )NN)Tr   )__name__
__module____qualname____doc__strr   dictr   boolrI   staticmethodintr   rM   __classcell__)r   s   @r   r
   r
   	   s~    93: 9sTz 9
T 
7s 7$ 7RV 7r &$ &sSy4?O &[e & &r   r
   )
r:   r6   datar   r   requests.async_httpr   baser   r
   r   r   r   <module>r[      s"     	 + , !N& N&r   