
    OJniv                     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 )ZhihuLiveStreamzL
    A class for fetching and processing Zhihu live stream information.
    N
proxy_addrcookiesc                 P    t         |   ||       | j                         | _        y N)super__init___get_mobile_headersmobile_headers)selfr   r   	__class__s      V/home/uftp/myenv/lib/python3.12/site-packages/streamget/platforms/zhihu/live_stream.pyr   zZhihuLiveStream.__init__   s#    W-"668    returnc                 .    dddd| j                   xs ddS )Nzosee2unifiedRelease/21914 osee2unifiedReleaseVersion/10.39.0 Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148z!application/json, text/plain, */*z;zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2z.https://live.ybw1666.com/800005143?promoters=0 )z
user-agentacceptzaccept-languagereferercookie)r   )r   s    r   r   z#ZhihuLiveStream._get_mobile_headers   s'    q9\Gll(b
 	
r   urlprocess_datac                   K   ddd}d|v rm|j                  d      d   }d| d}t        || j                  | j                         d	{   }t	        j
                  |      }|d
   |d<   |d   d   d   }n|}|j                  d      d   j                  dd      d   }	t        || j                  | j                         d	{   }
t        j                  d|
      }|s|S t	        j
                  |j                  d            }|s|S |d   d   d   |	   }|d   d
   }||d<   |d   d   }|dk(  r!|d   }|d   d   }|d||d   |d   |d   dz  }|S 7 7 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   F)anchor_nameis_livezpeople/   zhttps://api.zhihu.com/people/z/profile?profile_new_version=)r   headersNnamer    dramaliving_theatertheater_url?r   /)maxsplitz;<script id="js-initialData" type="text/json">(.*?)</script>initialStatetheatertheatersactorstatusthemeplayInfoThlsUrlplayUrl)r!   titlem3u8_urlflv_url
record_url)
splitr   r   r   jsonloadsrsplitresearchgroup)r   r   r   resultuser_idapijson_str	json_datalive_page_urlweb_idhtml_str	json_str2
json_data2	live_datar    live_status
live_titleplay_urls                     r   fetch_web_stream_dataz%ZhihuLiveStream.fetch_web_stream_data   s     "$6ii	*1-G1':WXC&stPTPcPcddH

8,I$-f$5F=!%g./?@OMM$$S)!,33C!3DRH"=T__VZViVijjII[]ef	MZZ	 23
~.y9*EfM	(0 +}(2!"7+J )*5H#$X.#I.&x0 F ; e ks&   A	EEA<EE	BEErD   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   )rD   rO   s     r   fetch_stream_urlz ZhihuLiveStream.fetch_stream_urlJ   s"     
 	j.11	9%%s   )NN)Tr   )__name__
__module____qualname____doc__strr   dictr   boolrN   staticmethodintr   rR   __classcell__)r   s   @r   r
   r
   	   s~    93: 9sTz 9
T 
-s -$ -RV -^ &$ &sSy4?O &[e & &r   r
   )
r:   r=   datar   r   requests.async_httpr   baser   r
    r   r   <module>ra      s"     	 + , !G&n G&r   