diff --git a/app/Console/Commands/Bttool.php b/app/Console/Commands/Bttool.php new file mode 100644 index 0000000..3e442ff --- /dev/null +++ b/app/Console/Commands/Bttool.php @@ -0,0 +1,378 @@ +decodeFile('resources/t2.torrent'); + $torrent = \PHP\BitTorrent\Torrent::createFromTorrentFile('resources/t2.torrent'); + var_dump($torrent->getFileList()); +die;*/ +// $data = Bencode::load('resources/t2.torrent'); +// var_dump(json_encode($data,true)); + + $bcoder = new \Bhutanio\BEncode\BEncode; +// $bcoder->set([ +// 'announce'=>'http://www.private-tracker.com', +// 'comment'=>'Downloaded from Private Tracker', +// 'created_by'=>'PrivateTracker v1.0' +// ]); + + // decode Torrent file +// var_dump(file_get_contents('resources/t2.torrent')[0]);die; + $torrent = $bcoder->bdecode( file_get_contents('resources/t2.torrent')); +// var_dump(array_keys($torrent['info'])); +// die; +// print_r($torrent['info']['files']); + $Files = $torrent['info']['files']; + function create_ed2k($fname, $fsize, $fhash){ + $ed2k_out = 'ed2k://|file|' . $fname . '|' . $fsize . '|' . $fhash . '|/'; + return $ed2k_out; + } + function create_magnet($dn, $xl = false, $btih = '', $sha1 = '', $ed2k = '', $tree_tiger = '', $md5 = '') + { + $magnet = 'magnet:?'; + if ($dn){ + $magnet .= 'dn=' . $dn; // download name + } + if ($xl){ + $magnet .= '&xl=' . $xl; // size + } + if ($btih){ + $magnet .= '&xt=urn:btih:' . $btih; // bittorrent info_hash (Base32) + } + if ($sha1){ + $magnet .= '&xt=urn:sha1:' . $sha1; // gnutella sha1 (base32) + } + if ($ed2k){ + $magnet .= '&xt=urn:ed2k:' . $ed2k; // emule hash (Hex) + } + if ($tree_tiger){ + $magnet .= '&xt=urn:tree:tiger:' . $tree_tiger; // tiger (Base32) + } + if ($sha1 && $tree_tiger) { + $magnet .= '&xt=urn:bitprint:' . $sha1 . '.' . $tree_tiger; // Gnutella 2 (Shareaza) bitprint (Base32) + } + if ($md5){ + $magnet .= '&xt=urn:md5:' . $md5; // md5 hash (Hex) + } + return $magnet; + } + + + + + //var_dump($Files);// + foreach($Files as $File) { + + if(isset( $File['ed2k'])){ + + +// $hex = bin2hex($File['ed2k'] );//二进制转成16进制 + $f = $File; + $f["filehash"] =isset($f["filehash"]) ? bin2hex($f["filehash"]) : ''; + $f["ed2k"] =bin2hex($f["ed2k"]); + var_dump($f); + $sha1 ='';//isset($f["filehash"]) ? strtoupper(base32_encode($f["filehash"])) : ''; //isset($f["sha1"]) ? strtoupper(base32_encode($f["sha1"])) : ''; + $ed2k = $f["ed2k"]; + $tiger = isset($f["tiger"]) ? strtoupper(base32_encode($f["tiger"])) : ''; + $md5 = isset($f["md5sum"]) ? bin2hex($f["md5sum"]) : ''; + //hashes is set? + $ext_hashes = (isset($f["ed2k"]) || isset($f["sha1"]) || isset($f["tiger"]) || isset($f["md5sum"])); + if ($ext_hashes && isset($f["length"])) + { + if (isset($f["ed2k"])) + { + echo create_ed2k(max($f['path']), $f["length"], $f["ed2k"] ) ."\n"; + } + else + { + + } + // echo @create_magnet(max($f['path']), $f["length"], '', $sha1, $ed2k, $tiger, $md5)."\n\n"; + + } +/* + $s = create_ed2k(max($f['path']), $f["length"], bin2hex($f["ed2k"])); + var_dump($s); + die; + + var_dump($hex);//die; + var_dump(chr(hexdec($hex))); + $string=''; + for ($i=0; $i < strlen($hex)-1; $i+=2){ + $string .= chr(hexdec($hex[$i].$hex[$i+1])); + } + // $string = iconv("GBK","utf-8", $string); + + var_dump($string);die; +// $s =iconv('UTF-8//TRANSLIT', 'utf-8//TRANSLIT', $File['ed2k']); + + +// $encode = mb_detect_encoding($File['ed2k']); + $encode = mb_detect_encoding($File['ed2k'],array("ASCII","GB2312","GBK",'BIG5','UTF-8')); +var_dump($encode); + +var_dump($File['ed2k']); + + $s =iconv( $encode,'UTF-8//IGNORE', $File['ed2k']);; +// $s = utf8_encode( $File['ed2k']) ; + var_dump($s); + die;*/ + } + + + } + + // show Torrent contents + $files = $bcoder->filelist( $torrent ); +// print_r($files); +die; + // +// +// $bcoder = new \Bhutanio\BEncode\BEncode(); +// $bcoder->set([ +// 'announce'=>'http://www.private-tracker.com', +// 'comment'=>'Downloaded from Private Tracker', +// 'created_by'=>'PrivateTracker v1.0' +// ]); +// +// // decode Torrent file +// $torrent = $bcoder->bdecode('resources/t2.torrent' ); +// print_r($torrent); +// + $encoder = new \PHP\BitTorrent\Encoder(); + $decoder = new \PHP\BitTorrent\Decoder($encoder); + + $decodedFile = $decoder->decodeFile('resources/t2.torrent'); + +// $decodedFile-> +// $decodedFile = json_decode(json_encode($decodedFile)); +// var_dump($decodedFile); +// foreach ($decodedFile as $item) { +// var_dump(json_encode($item)); +// } + die; + } +} + + +class xBEncoder { + + const READY = 0; + const READ_STR = 1; + const READ_DICT = 2; + const READ_LIST = 3; + const READ_INT = 4; + const READ_KEY = 5; + + public $y; + protected $z, $m, $n; + protected $stat; + protected $stack; + + + /** + * This method saves the status of current + * encode/decode work. + */ + protected function push($newY, $newStat) { + array_push($this->stack, array($this->y, $this->z, $this->m, $this->n, $this->stat)); + list($this->y, $this->z, $this->m, $this->n, $this->stat) = array($newY, 0, 0, 0, $newStat); + } + + + /** + * This method restore the saved status of current + * encode/decode work. + */ + protected function pop() { + $t = array_pop($this->stack); + if ($t) { + if ($t[4] == self::READ_DICT) { + $t[0]->{$t[1]} = $this->y; + $t[1] = 0; + } elseif ($t[4] == self::READ_LIST) + $t[0][] = $this->y; + list($this->y, $this->z, $this->m, $this->n, $this->stat) = $t; + } + } + + + /** + * This method initializes the status of work. + * YOU SHOULD CALL THIS METHOD BEFORE EVERYTHING. + */ + public function init() { + $this->stat = self::READY; + $this->stack = array(); + $this->z = $this->m = $this->n = 0; + } + + /** + * This method decode $s($l as length). + * You can get $obj->y as the result. + */ + public function decode($s, $l) { + $this->y = 0; + for ($i = 0; $i < $l; ++$i) { + switch ($this->stat) { + case self::READY: + if ($s[$i] == 'd') { + $this->y = new xBDict(); + $this->stat = self::READ_DICT; + } elseif ($s[$i] == 'l') { + $this->y = array(); + $this->stat = self::READ_LIST; + } + break; + case self::READ_INT: + if ($s[$i] == 'e') { + $this->y->val = substr($s, $this->m, $i - $this->m); + $this->pop(); + } + break; + case self::READ_STR: + if (xBInt::isNum($s[$i])) + continue; + if ($s[$i] = ':') { + $this->z = substr($s, $this->m, $i - $this->m); + $this->y = substr($s, $i + 1, $this->z + 0); + $i += $this->z; + $this->pop(); + } + break; + case self::READ_KEY: + if (xBInt::isNum($s[$i])) + continue; + if ($s[$i] = ':') { + $this->n = substr($s, $this->m, $i - $this->m); + $this->z = substr($s, $i + 1, $this->n + 0); + $i += $this->n; + $this->stat = self::READ_DICT; + } + break; + case self::READ_DICT: + if ($s[$i] == 'e') { + $this->pop(); + break; + } elseif (!$this->z) { + $this->m = $i; + $this->stat = self::READ_KEY; + break; + } + case self::READ_LIST: + switch ($s[$i]) { + case 'e': + $this->pop(); + break; + case 'd': + $this->push(new xBDict(), self::READ_DICT); + break; + case 'i': + $this->push(new xBInt(), self::READ_INT); + $this->m = $i + 1; + break; + case 'l': + $this->push(array(), self::READ_LIST); + break; + default: + if (xBInt::isNum($s[$i])) { + $this->push('', self::READ_STR); + $this->m = $i; + } + } + break; + } + } + $rtn = empty($this->stack); + $this->init(); + return $rtn; + } + + /** + * This method encode $obj->y into BEncode. + */ + public function encode() { + return $this->_encDo($this->y); + } + + protected function _encStr($str) { + return strlen($str).':'.$str; + } + + protected function _encDo($o) { + if (is_string($o)) + return $this->_encStr($o); + if ($o instanceof xBInt) + return 'i'.$o->val.'e'; + if ($o instanceof xBDict) { + $r = 'd'; + foreach ($o as $k => $c) + $r .= $this->_encStr($k).$this->_encDo($c); + return $r.'e'; + } + if (is_array($o)) { + $r = 'l'; + foreach ($o as $c) + $r .= $this->_encDo($c); + return $r.'e'; + } + } +} + + +class xBDict {} + +class xBInt { + public $val; + + public function __construct($val = 0) { + $this->val = $val; + } + + public static function isNum($chr) { + $chr = ord($chr); + if ($chr <= 57 && $chr >= 48) + return true; + return false; + } +} \ No newline at end of file diff --git a/app/Console/Commands/JavbusCrawler.php b/app/Console/Commands/JavbusCrawler.php index 70ed733..44c9cf1 100644 --- a/app/Console/Commands/JavbusCrawler.php +++ b/app/Console/Commands/JavbusCrawler.php @@ -228,6 +228,7 @@ public function handle() return; } + // if($this->option('movie')==1){ $movie404 = $this->option('movie404')*1; $moviemax = $this->option('moviemax')*1; @@ -263,7 +264,7 @@ public function update_ja_code_36($table_javbus ,$table_avmoo) ]); foreach ($d as $key => $val ) { $this->database->query( "update {$table_javbus} set avmoo_code_36 = '{$val['code_36']}' WHERE movie_pic_cover = '{$val['movie_pic_cover']}' " ); - echo "update avmoo_code_36 $key == {$val['code_36']} == {$val['movie_pic_cover']}\n "; + echo "update avmoo_code_36 :: $key == {$val['code_36']} == {$val['movie_pic_cover']}\n "; } $data = $this->database->query( " SELECT count(1) as avmoo_code_36_null_num from {$table_javbus} WHERE avmoo_code_36 ='' " )->fetchAll(\PDO::FETCH_ASSOC); echo "avmoo_code_36_null_num : {$data[0]['avmoo_code_36_null_num']} \n"; diff --git a/app/Console/Commands/JavlibraryCrawler.php b/app/Console/Commands/JavlibraryCrawler.php new file mode 100644 index 0000000..b12f182 --- /dev/null +++ b/app/Console/Commands/JavlibraryCrawler.php @@ -0,0 +1,432 @@ +option('genre')){ + $this->handle_genre(); + } + + if($this->option('movie')){ + $this->handle_movie(); + } +// if($this->option('page')*1 >0){ +// $this->handle_all_page($this->option('page')*1); +// } +// if($this->option('magpage')!== null){ +// $this->handle_all_magnet($this->option('magpage')*1); +// } + //php artisan avbook:javbus --movie=1 --page=10 --magpage=10 --movie404=1 + } + public $max_concurrency = 16; + public function handle_genre() + { + + $cf =\App\Tools\CrawlerUpdate::get_crawler_config(); + + $this->sphost = $cf['javlibhost']; + $this->hosturl = "http://{$this->sphost}/"; + + $start_type = "gern"; + $headers = [ + 'Accept'=>'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', + 'Accept-Encoding'=>'gzip, deflate', + 'Accept-Language'=>'zh-CN,zh;q=0.9,en;q=0.8', + 'Cache-Control'=>'max-age=0', + 'Connection'=>'keep-alive', + 'Cookie'=>'__cfduid=de58b540550437dded9edf806e15e97921558631740; timezone=-480; over18=18; __qca=P0-1061630505-1558631744517; Hm_lvt_bfc6c23974fbad0bbfed25f88a973fb0=1558632657; Hm_lpvt_bfc6c23974fbad0bbfed25f88a973fb0=1558632681', + 'Host'=>$this->sphost, + 'Upgrade-Insecure-Requests'=>'1', + 'User-Agent'=>'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36', +// 'User-Agent'=>'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)' + ]; + $this->crawler_client_init($this->hosturl,$start_type,$this->table_prefix,$headers); + + $client = new \GuzzleHttp\Client(['headers'=>$headers,'http_errors' => false ]); + +// $response=$client->get($this->hosturl.'cn/vl_genre.php?list&mode=2&page=1&g=aqja' ); +// $original_body = (string)$response->getBody(); +// $content = mb_convert_encoding($original_body, 'UTF-8', $this->spcharset); +// preg_match_all('#