U
    h/                     @   sP   d dl Z d dlZd dlZd dlmZ e jd d dlmZ G dd deZdS )    N)MD5z..)Spiderc                   @   s   e Zd Zd)ddZdd Zdd Zdd	 Zd
d ZdZddiZ	dd Z
dd Zdd Zdd Zd*ddZdd Zdd Zdd Zd d! Zd+d#d$Zd%d& Zd'd( Zd"S ),r    c                 C   s   |   | _|  \| _| _d S N)getuiduidgetuserinfotokencode)selfextend r   ,   /storage/emulated/0/lz/py/sy/爱瓜影视.pyinit   s    
zSpider.initc                 C   s   d S r   r   r   r   r   r   getName   s    zSpider.getNamec                 C   s   d S r   r   )r   urlr   r   r   isVideoFormat   s    zSpider.isVideoFormatc                 C   s   d S r   r   r   r   r   r   manualVideoCheck   s    zSpider.manualVideoCheckc                 C   s   d S r   r   r   r   r   r   destroy   s    zSpider.destroyzhttps://tvapi211.magicetech.com
User-Agentzokhttp/3.11.0c           	   	   C   s   | j | jd}| j| j d| || jd }i }g }i }|d D ]~}||d t|d d g |t|d < |d D ]D}t	|d	 r~|t|d  |d
 |d dd |d	 D d q~qF||d< ||d< |S )Nr	   authcodez4/hr_1_1_0/apptvapi/web/index.php/video/filter-headerjsonheadersdataZchannel_name
channel_id)	type_nametype_idZ
search_boxlistfieldlabelc                 S   s*   g | ]"}|d  r|d t |d  dqS )valuedisplay)nv)str).0jr   r   r   
<listcomp>6   s      z&Spider.homeContent.<locals>.<listcomp>)keynamer#   classfilters)
r	   r
   posthostgetbodyr   r   appendr'   len)	r   filterbodyr   resultclassesr.   kir   r   r   homeContent$   s.    

zSpider.homeContentc                 C   sL   | j | jd}| j| j d| || jd }d| |d d d iS )Nr   z//hr_1_1_0/apptvapi/web/index.php/video/index-tvr   r    r   r   bannerr	   r
   r/   r0   r1   r   r   getlist)r   r5   r   r   r   r   homeVideoContent<   s
    
zSpider.homeVideoContentc                 C   s   | j | j||dd|dd|dd|dd|dd|dd	
}| j| j d
| || jd }i }| |d d |d< ||d< d|d< d|d< d|d< |S )Narea0yearsorttaghotstatus24)
r	   r   r   r?   rA   rB   rC   rE   page_num	page_sizez3/hr_1_1_0/apptvapi/web/index.php/video/filter-videor   r   r    pagei'  	pagecountZ   limiti?B total)	r	   r
   getr/   r0   r1   r   r   r=   )r   tidpgr4   r   r5   r   r6   r   r   r   categoryContentB   s$    
 
 

  
zSpider.categoryContentc                 C   s  |d  d}| j| j|d |d d}| j| j d| || jd }i }|d d D ]R}|d	 }|D ]@}|d
 |krg ||d
 < ||d
  |d  d|d   qlq\g g  }}	|	 D ]"\}
}|	|
 |d
| qd
|	d
|d}d|giS )Nr   @   )r	   r   r   video_idz-/hr_1_1_0/apptvapi/web/index.php/video/detailr   r   chaptersZ
sourcelistZsource_nametitle$
source_url#z$$$)vod_play_fromvod_play_urlr    )splitr	   r
   r/   r0   r1   r   r   r2   itemsjoin)r   idsr5   r   vdatar8   r9   r)   plistnamesr+   r#   vodr   r   r   detailContentP   s(    
 (

zSpider.detailContent1c                 C   sL   | j | j||d}| j| j d| || jd }d| |d d iS )N)r	   r   keywordrG   z5/hr_1_1_0/apptvapi/web/index.php/search/letter-resultr   r    r   r<   )r   r+   quickrP   r5   r   r   r   r   searchContente   s
    
zSpider.searchContentc                 C   s   d|ddddd}|S )Nr   zDDalvik/2.1.0 (Linux; U; Android 11; M2012K10C Build/RP1A.200720.011)zhttps://aigua.tvzhttps://aigua.tv/)r   OriginReferer)parser   headerr   )r   flagidvipFlagsr6   r   r   r   playerContentk   s    	zSpider.playerContentc                 C   s   d S r   r   )r   paramr   r   r   
localProxyy   s    zSpider.localProxyc                 C   s:   | j | j d|  | jd }|d }|d |d fS )Nz0/hr_1_1_0/apptvapi/web/index.php/user/auth-loginr   r   Z
user_tokenr   )r/   r0   r1   r   r   )r   r   r&   r   r   r   r   |   s
    
zSpider.getuserinfoc                 C   s*   |  d}|s&tt }| d| |S )Nr   )getCacher'   uuiduuid4setCache)r   r   r   r   r   r      s
    
zSpider.getuidNc                 C   s   |d kri }dddddddt tt d| jd
}|| tt| d	d
 d}ddd | D }| 	d| d
 }|d|i |S )N4z1.1.0re   3Ztv11zcom.gzsptv.gztvvideo)
productverdebugappIdZosTypeZmarketChannelZsysVertimeZpackageNameudidc                 S   s   | d S )Nr   r   )itemr   r   r   <lambda>       z Spider.getbody.<locals>.<lambda>)r+   &c                 s   s(   | ] \}}|d kr| d| V  qdS )r   =Nr   )r(   r8   r&   r   r   r   	<genexpr>   s      z!Spider.getbody.<locals>.<genexpr>ZjI7POOBbmiUZ0lmiZ D9ShYdN51ksWptpkTu11yenAJu7Zu3cRsign)r'   intr~   r   updatedictsortedr]   r^   md5upper)r   Z	json_dataparamsZsorted_jsontextZmd5_hashr   r   r   r1      s       
zSpider.getbodyc                 C   s    t  }||d | S )Nzutf-8)r   newr   encode	hexdigest)r   r   hr   r   r   r      s    z
Spider.md5c              
   C   sp   g }|D ]b}t |dtkr&|d }||d d|d |d|d|d|dd	 q|S )
Nvideor   rR   rT   Z
video_namecoverscorerm   )vod_idvod_namevod_picvod_yearvod_remarks)typerN   r   r2   )r   r   videosr9   r   r   r   r=      s     
zSpider.getlist)r   )re   )N)__name__
__module____qualname__r   r   r   r   r   r0   r   r:   r>   rQ   rd   rh   rp   rr   r   r   r1   r   r=   r   r   r   r   r      s&   


r   )	sysr~   rt   ZCrypto.Hashr   pathr2   base.spiderr   r   r   r   r   <module>   s   