
    OJni	                     J    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 )YiqiLiveStreamzO
    A class for fetching and processing YiqiLive live stream information.
    N
proxy_addrcookiesc                 P    t         |   ||       | j                         | _        y N)super__init___get_pc_headers
pc_headers)selfr   r   	__class__s      Y/home/uftp/myenv/lib/python3.12/site-packages/streamget/platforms/yiqilive/live_stream.pyr   zYiqiLiveStream.__init__   s"    W-..0    returnc                 ,    ddd| j                   xs ddS )Nzhttps://17.livezhttps://17.live/z;ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092)) )originrefererz
user-agentcookie)r   )r   s    r   r   zYiqiLiveStream._get_pc_headers   s!    ')Wll(b	
 	
r   urlprocess_datac                   K   |j                  d      d   j                  dd      d   }d| }t        || j                  | j                         d	{   }t        j                  |      }|d
   }|dd}d|i}d| d}t        ||| j                  | j                         d	{   }t        j                  |      }|j                  d      }	|	r|	dk(  r|d   d   d   d   }
|d|
|
dz  }|S 7 7 Lw)a)  
        Fetches web 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.
        ?r   /   )maxsplitz*https://wap-api.17app.co/api/v1/user/room/)r   headersNdisplayNameF)anchor_nameis_liveliveStreamIDz&https://wap-api.17app.co/api/v1/lives/z/viewers/alive)	json_datar   r%   statusr   pullURLsInfortmpURLsurlHighQualityT)r(   flv_url
record_url)splitrsplitr   r   r   jsonloadsget)r   r   r   room_idapi_1json_strr*   r'   resultlive_statusr/   s              r   fetch_web_stream_dataz$YiqiLiveStream.fetch_web_stream_data   s     ))C.#**3*;B?<WIF"5T__doo^^JJx(	.!,?G
	 9	P"5I$//cgcrcrssJJx(	mmH-;!+/
;A>?OPG$7'RRF _ ts&   AC8C4AC8)C6*AC86C8r*   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   17直播)r   )r*   r<   s     r   fetch_stream_urlzYiqiLiveStream.fetch_stream_url5   s"     
 	j*--	9%%s   )NN)Tr   )__name__
__module____qualname____doc__strr   dictr   boolr;   staticmethodintr   r?   __classcell__)r   s   @r   r
   r
      s}    13: 1sTz 1
 
s $ RV : &$ &sSy4?O &[e & &r   r
   )	r3   datar   r   requests.async_httpr   baser   r
    r   r   <module>rN      s     + , !3&^ 3&r   