U
    i<                     @   sJ   d dl Z d dlZd dlZd dlmZ d dlmZ e  G dd deZdS )    N)Spider)disable_warningsc                   @   sT   e Zd ZdZdd Zd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   zhttps://www.baoshi3.ccc                 C   s   dS )Nu   宝石电影 )selfr   r   ,/storage/emulated/0/lz/py/sy/baoshi_final.pygetName   s    zSpider.getName c                 C   s   d S )Nr   )r   extendr   r   r   init   s    zSpider.initc                 C   s$   dddddddddg}d|iS )	N1u   电影)type_id	type_name2u	   连续剧4u   动漫classr   )r   filterclassesr   r   r   homeContent   s
    zSpider.homeContentc                 C   s   | j  d| d| d}| |}|j}td||}|rPtdd |D nt|}	g }
td|tj}|D ]P\}}}|	drd	| }n|	d
r|	ds| j | }|

|||dd qpt||	t|
|	d |
dS )Nz/type/-.htmlz/type/{}-(\d+)\.htmlc                 S   s   g | ]}t |qS r   )int).0xr   r   r   
<listcomp>    s     z*Spider.categoryContent.<locals>.<listcomp>Yclass="team-con"\s+href="/detail/(\d+)\.html"\s+title="([^"]+)".*?data-original="([^"]+)"//https:/r   vod_idvod_namevod_picvod_remarks   )page	pagecountlimittotallist)hostfetchtextrefindallformatmaxr   S
startswithappendlen)r   tidpgr   r	   urlreshtmlZ
pg_matchesZ
page_countvod_listmatchesmidnamepicr   r   r   categoryContent   s0    




zSpider.categoryContentc                 C   s   |d }| j  d| d}tj|ddddid}|j}td	|}|sRtd
|}td|}td|tj}td|}	dd |	D }
||r|d	 nd|r|dnddd
|
|rtdd|d	 ndd}d|giS )Nr   z/detail/r   F
   
User-AgentMozilla/5.0verifytimeoutheadersz<h1[^>]*>([^<]+)</h1>zclass="title2">([^<]+)</h2>z6class="detail-img"[^>]+(?:src|data-original)="([^"]+)"z&class="detail-sketch"[^>]*>(.*?)</div>z+href="(/play/\d+-\d+-\d+.html)">([^<]+)</a>c                 S   s   g | ]\}}| d | qS )$r   )r   Zp_urlZp_namer   r   r   r   I   s     z(Spider.detailContent.<locals>.<listcomp>   u   未知影片r   u   宝石云播#z<[^>]+>u   暂无简介)r   r    r!   vod_play_fromvod_play_urlvod_contentr(   )r)   requestsgetr+   r,   searchr0   r-   groupstripjoinsub)r   idsr;   r6   r7   r8   Z
name_matchZ	pic_matchZcontent_matchZplay_list_matches	play_urlsvodr   r   r   detailContent;   s&    zSpider.detailContentr   c                 C   s   | j  d| }z tj|ddddid}|j}W n   dg i Y S X td|tj}g }|D ]P\}	}
}|d	r|d
| }n|dr|d	s| j | }||	|
|dd q^d|iS )Nz/search/-------------.html?wd=Fr?   r@   rA   rB   r(   r   r   r   r   r   r   )	r)   rL   rM   r+   r,   r-   r0   r1   r2   )r   keyquickr5   r6   r7   r8   r:   r9   r;   r<   r=   r   r   r   searchContentU   s(    

 
 
  
zSpider.searchContentc                 C   s   d| j | ddidS NrG   r@   rA   )parser6   headerr)   r   flagidvipFlagsr   r   r   playerContentg   s    zSpider.playerContentc                 C   s   d| j | ddidS rZ   r]   r^   r   r   r   rb   j   s    N)r   )r   )__name__
__module____qualname__r)   r   r
   r   r>   rV   rY   rb   r   r   r   r   r      s   
"
r   )sysr,   rL   base.spiderr   urllib3r   r   r   r   r   <module>   s   