search
Homephp教程PHP源码磁力链接打包下载

磁力链接打包下载

May 23, 2016 pm 04:38 PM


keyWord=$keyWord;
		$this->saveFile=$saveFile;
		$this->minSize=$minSize;
		$this->page=$pageRange[0];
		$this->maxPage=$pageRange[1];
	}
	
	public function run(){
	    
		while($this->flag && $this->maxPage>$this->page){
		    $this->timestamp=$this->microtimeFloat();
			$this->_execute();
			$this->page++;
			$this->_notice();
			
		}
	}
	/**
	 * 执行
	 */
	protected function _execute(){
	    
		$this->_getUrl();
		$this->_getHtmlPage();
		$this->_parseHtml();
		if($this->_currentMagnetCount){//当有磁力链接时保存
			$this->_save();
		}
		
	}
	
	public function microtimeFloat(){
        list($usec, $sec) = explode(" ", microtime());
        return sprintf('%01.2f',(float)$usec + (float)$sec);
    }
    /**
     * 通知
     */
	protected function _notice(){
	    
	    $currentTime = $this->microtimeFloat();
	    $useTime =sprintf('%01.2f', $currentTime-$this->timestamp);
	    $this->timestamp = $currentTime;
	    echo '第'.$this->page.'页存储了'.$this->_currentMagnetCount.'个磁力链接,耗时'.$useTime."秒\r\n";
		if(!($this->flag && $this->maxPage>$this->page)){
			echo '总共存储了'.$this->_magnetCount.'个磁力链接'."\r\n";
		}
	}
    /**
     * 设置url
     */
	protected function _getUrl(){
	    
		$this->_url = $this->host.'search?q='.rawurlencode($this->keyWord).'&p='.$this->page;	
	}
	/**
	 * 获得html文件内容
	 */
	protected function _getHtmlPage(){
	    
		$ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT,$this->timeout);
        curl_setopt($ch, CURLOPT_URL, $this->_url);
        curl_setopt($ch, CURLOPT_SSLVERSION,3); 
        $result = curl_exec($ch);
        if($result === false){
            //echo 'Curl error: '. curl_errno($ch) .' : '. curl_error($ch);
            $opts = array(
                'https'=>array(
                    'method'=>"GET",
                    'timeout'=>$this->timeout,//单位秒
                )
            );
            $context = stream_context_create($opts);
            $this->_html =  @file_get_contents($this->_url,false,$context);
        }else{
            $this->_html = $result;
        }
        curl_close($ch);
	}
    /**
     * 抓取磁力链接
     */
	protected function _parseHtml(){
	    
		preg_match_all('/href="(magnet\:\?xt=urn\:btih\:.+?)"/',$this->_html,$magnet);
		preg_match_all('/attr_val">(\d+?\.?\d*? [G|M|K]B)/',$this->_html,$size);
		if(empty($size[1])){
			$this->flag=false;//当获取磁力链接时不到时,停止翻页
		}
		foreach($size[1] as $key=>$val){
			if($this->_compareSize($val)){
				$this->_magnet[]=$magnet[1][$key];
			}		
		}
		$this->_currentMagnetCount = count($this->_magnet);
		$this->_magnetCount += count($this->_magnet);
	}
    /**
     * 比较磁力链接文件的大小
     */
	protected function _compareSize($size){
	    
		$number = substr($size,0,strpos($size,' '));
		$unit = substr($size,strpos($size,' ')+6);

		$n='';
		switch($unit){
			case 'GB':
					$n=1;
					break;
			case 'MB':
					$n=1024;
					break;
			case 'KB':
					$n=1048576;
					break;
			default :
					$n=false;
		}
		if($n===false){
		    try {
		        throw new Exception("文件大小单位识别失败\n");
		    } catch (Exception $e) {
		        echo $e->getMessage();
		        return false;
		    }
			
		}
		return ( $this->minSize < ($number/$n) );
	}
    /**
     * 把磁力链接保存到文件中
     */
	protected function _save(){
	    
	    $data = &#39;&#39;;
		foreach($this->_magnet as $val){
		    $data .= $val."\n";
		    $this->magnetNum++;
		    if(0==$this->magnetNum%15)
		      $data.="\n\n";
		}
		file_put_contents($this->saveFile,$data,FILE_APPEND);
		$this->_magnet=array();
	}
	
}
//示例
$s = new Magnet(&#39;LOL&#39;,&#39;magnet.log&#39;,2,array(0,10));
$s->run();

                   

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software