
    OJni                     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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 )JDLiveStreamzI
    A class for fetching and processing JD live stream information.
    N
proxy_addrcookiesc                 P    t         |   ||       | j                         | _        y N)super__init___get_mobile_headersmobile_headers)selfr   r   	__class__s      S/home/uftp/myenv/lib/python3.12/site-packages/streamget/platforms/jd/live_stream.pyr   zJDLiveStream.__init__   s#    W-"668    returnc                 .    dddd| j                   xs ddS )Nz;ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))zhttps://lives.jd.comzhttps://lives.jd.com/ )z
user-agentoriginrefererzx-referer-pagecookie)r   )r   s    r   r   z JDLiveStream._get_mobile_headers   s$    W,.5ll(b
 	
r   urlprocess_datac                   K   t        || j                  | j                  d       d{   }| j                  |d      }ddd}|s4t	        j
                  d|      }|s|S |j                  d	      }d
| |d<   nrddd|z   dz   d}d}t        ||| j                  | j                         d{   }	t        j                  |	      }
|
d   d   }||d<   d|
d   vr|S |
d   d   d   d   }d|z   dz   ddd}dt        j                  j                  |       }t        || j                  | j                         d{   }	t        j                  |	      }
|
d   d    }|d	k(  ry|r]d!dd|z   d"z   d}t        d#|| j                  | j                         d{   }t        j                  |      }|d   d$   d%   d&   |d&<   |
d   d'   }|
d   d(   }|d|||d)z  }|S 7 7 67 7 N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.
        T)r   headersredirect_urlNauthorIdr   F)anchor_nameis_livez#/(.*?)\?origin   jd_r#   talent_head_findTalentMsg	dr_detailz{"authorId":"z"","monitorSource":"1","userId":""})
functionIdappidbodyz.https://api.m.jd.com/talent_head_findTalentMsg)datar   r    result
talentNamelivingRoomJumpparamsidz{"liveId": "z"}getImmediatePlayToMzh5-live)r+   r)   r*   z#https://api.m.jd.com/client.action?)r   r    r,   statusjdTalentContentListzO","type":1,"userId":"","page":1,"offset":"-1","monitorSource":"1","pageSize":1}z(https://api.m.jd.com/jdTalentContentListcontentr   titlevideoUrl
h5VideoUrl)r$   m3u8_urlflv_url
record_url)r   r   r   
get_paramsresearchgroupjsonloadsurllibparse	urlencode)r   r   r   r!   	author_idr-   live_idr,   info_apijson_str	json_datar#   r0   apilive_status	json_str2
json_data2r:   r9   s                      r   fetch_web_stream_dataz"JDLiveStream.fetch_web_stream_data   sT     'stPTPcPcrvwwOOL*=	!#6ii 2LAGmmA&G&)'OF=! :$')36ZZD
 HH&xdt`d`s`sttH

8,I#H-l;K$/F=!y'::)*:;HEdKG"W,t3/
 4FLL4J4J64R3ST"34??DL_L_``JJx(	'1!"7(+i7 ;^ ^ #,,V]a7;PTPcPc#e e	!ZZ	2
",X"6y"A!"DW"Mw'
3G (6H$H`hiiFe x  u aesI   'G,G"BG,/G%0BG, G(AG,G*AG,%G,(G,*G,rI   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   )rI   rO   s     r   fetch_stream_urlzJDLiveStream.fetch_stream_urlZ   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=   urllib.parserB   r,   r   r   requests.async_httpr   baser   r
    r   r   <module>ra      s%     	  + , !V&> V&r   