
    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                   r     e Zd ZdZddedz  dedz  f fdZddededefd	Zdd
edee	z  dz  de
fdZ xZS )YoutubeLiveStreamzN
    A class for fetching and processing Youtube live stream information.
    N
proxy_addrcookiesc                 P    t         |   ||       | j                         | _        y N)super__init___get_pc_headers
pc_headers)selfr   r   	__class__s      X/home/uftp/myenv/lib/python3.12/site-packages/streamget/platforms/youtube/live_stream.pyr   zYoutubeLiveStream.__init__   s"    W-..0    urlprocess_datareturnc                   K   t        || j                  | j                         d{   }t        j                  d|      j                  d      }t        j                  |      }|s|S ddd}d|vrt        d	      |d   d
   |d<   |d   j                  d      }|rJ|d   d   }|d   d   }	| j                  |	| j                  | j                         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   headersNzFvar ytInitialPlayerResponse = (.*?);var meta = document\.createElement    F)anchor_nameis_livevideoDetailsz`Error: Please log in to YouTube on your device's webpage and configure cookies in the config.iniauthorr   isLivetitlestreamingDatahlsManifestUrl)proxyr   T)r   r#   m3u8_urlplay_url_list)r   r   r   researchgroupjsonloads	Exceptiongetget_play_url_list)r   r   r   html_strjson_str	json_dataresultlive_status
live_titler'   r(   s              r   fetch_web_stream_dataz'YoutubeLiveStream.fetch_web_stream_data   s     #34??DOO\\99fhpqwwJJx(	!#6*rt t ). 9( C}/33H=">27;J 12BCH"&"8"8bfbqbq"8"rrM$dqrrF# ] ss"   &C0C,B2C0C.C0.C0r3   video_qualityc                 ^   K   | j                  ||dd       d{   }t        |      S 7 w)z_
        Fetches the stream URL for a live room and wraps it into a StreamData object.
        TYoutube)specplatformN)get_stream_urlr   )r   r3   r8   datas       r   fetch_stream_urlz"YoutubeLiveStream.fetch_stream_url/   s6      ((MW`(aa4   bs   -+-)NN)Tr   )__name__
__module____qualname____doc__strr   booldictr7   intr   r?   __classcell__)r   s   @r   r
   r
   	   sc    13: 1sTz 1s $ RV <! !S3YQUEU !ak !r   r
   )
r,   r)   r>   r   r   requests.async_httpr   baser   r
    r   r   <module>rL      s      	 + , !+! +!r   