Skip to content

Commit

Permalink
add bttool
Browse files Browse the repository at this point in the history
  • Loading branch information
lxbccc committed Jul 11, 2019
1 parent 11f2b98 commit 2d93aff
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 298 deletions.
191 changes: 4 additions & 187 deletions app/Console/Commands/Bttool.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ function create_magnet($dn, $xl = false, $btih = '', $sha1 = '', $ed2k = '', $tr
// $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');
// $encoder = new \PHP\BitTorrent\Encoder();
// $decoder = new \PHP\BitTorrent\Decoder($encoder);
//
// $decodedFile = $decoder->decodeFile('resources/t2.torrent');

// $decodedFile->
// $decodedFile = json_decode(json_encode($decodedFile));
Expand All @@ -193,186 +193,3 @@ function create_magnet($dn, $xl = false, $btih = '', $sha1 = '', $ed2k = '', $tr
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;
}
}
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"php": "^7.1.3",
"bhutanio/torrent-bencode": "dev-master",
"catfan/medoo": "^1.6",
"christeredvartsen/php-bittorrent": "^1.1",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"jaeger/querylist": "^4.1",
Expand All @@ -20,7 +19,6 @@
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"mavinoo/laravel-batch": "dev-master",
"sandfoxme/bencode": "^1.3",
"theseer/directoryscanner": "^1.3"
},
"require-dev": {
Expand Down
110 changes: 1 addition & 109 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

AVBook 是基于Laravel开发的Web应用程序,通过Artisan 控制台实现 avmoo 、javbus 的爬虫采集数据入库mysql,前端页面模仿javbus,并添加一些类似javlibrary的功能。该系统相当于以上三个网站的结合体,能够使你更加方便地管理你的影片

## 预览

<a target="_blank" href ="https://raw.githubusercontent.com/guyueyingmu/avbook/master/public/avbook/scrshot_index.png" >首页截图</a>

<a target="_blank" href ="https://raw.githubusercontent.com/guyueyingmu/avbook/master/public/avbook/scrshot_movie.png" >详情页截图</a>
Expand Down

0 comments on commit 2d93aff

Please sign in to comment.