
    OJni                     b    d dl Z d dlZ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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 )KugouLiveStreamzL
    A class for fetching and processing Kugou live stream information.
    N
proxy_addrcookiesc                 P    t         |   ||       | j                         | _        y N)super__init___get_pc_headers
pc_headers)selfr   r   	__class__s      V/home/uftp/myenv/lib/python3.12/site-packages/streamget/platforms/kugou/live_stream.pyr   zKugouLiveStream.__init__   s"    W-..0    urlprocess_datareturnc                   K   d|v r&t        j                  d|      j                  d      }n(|j                  d      d   j	                  dd      d   }d| }t        || j                  | j                  	       d
{   }t        j                  |      }|d   d   d   }|dd}|st        d      |d   d   }	|	dk7  r|ddddddddt        t        t        j                         dz              d
}
dt        j                  j!                  |
       }t        || j                  | j                         d
{   }t        j                  |      }|d   d   }|r|d   d    d   d!   d   }|d"||d#z  }|S 7 7 A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.
        roomIdzroomId=(\d+)   ?r   /)maxsplitzPhttps://service2.fanxing.kugou.com/roomcen/room/web/cdn/getEnterRoomInfo?roomId=)r   r   headersNdatanormalRoomInfonickNameF)anchor_nameis_livezaMusic channel live rooms are not supported for recording, please switch to a different live room.liveType70z	1-2-4-5-8zfx-flashz1-5-6100011010i  )
std_ridstd_platstd_kid
streamTypeuatargetLiveTypesversionsupportEncryptModeappid_zEhttps://fx1.service.kugou.com/video/pc/live/pull/mutiline/streamaddr?)r   r    linesstreamProfileshttpsFlvT)r%   flv_url
record_url)researchgroupsplitrsplitr   r   r   jsonloadsRuntimeErrorstrinttimeurllibparse	urlencode)r   r   r   room_idapp_apijson_str	json_datar$   resultlive_statusparamsapi	json_str2
json_data2stream_datar:   s                   r   fetch_web_stream_dataz%KugouLiveStream.fetch_web_stream_data   s     s?ii5;;A>GiinQ'..sQ.?BGdeldmn"w4??TXTcTcddJJx(	'(89*E!,?s   '
3"") #*!&)TYY[4/01F ZZ`ZfZfZpZpqwZxYyzC'QUQ`Q`aaII.J$V,W5K%b/*:;A>zJ1MdwgVV; e. bs&   A=F?E> B>F>F ?A F FrM   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   )rM   rV   s     r   fetch_stream_urlz KugouLiveStream.fetch_stream_urlC   s"     
 	j.11	9%%s   )NN)Tr   )__name__
__module____qualname____doc__rD   r   booldictrU   staticmethodrE   r   rY   __classcell__)r   s   @r   r
   r
      sr    13: 1sTz 1.s .$ .RV .` &$ &sSy4?O &[e & &r   r
   )rA   r<   rF   urllib.parserG   r!   r   r   requests.async_httpr   baser   r
    r   r   <module>rf      s&     	   + , !>&n >&r   