海运的博客

pt torrent种子自动辅种相似度计算

发布时间:March 5, 2021 // 分类:PT // No Comments

torrent解析类使用https://github.com/Rhilip/Bencode,打补丁支持获取种子hash信息。

--- Bencode.php.1       2021-02-24 07:30:41.677067125 +0800
+++ Bencode.php 2021-03-05 17:52:23.803081067 +0800
@@ -26,6 +26,9 @@
  */
 class Bencode
 {
+    public function info_hash($data, $info_hash) {
+      return sha1(substr($data, $info_hash['pos'], $info_hash['length']));
+    }
     /**
      * Decode bencoded data from string
      *
@@ -46,7 +49,15 @@
             $return = [];
             while ($data[$pos] !== 'e') {
                 $key = self::decode($data, $pos);
+                if (!strcmp($key, "info")) {
+                //if ($key === "info") {
+                  $return['info_hash']['pos'] = $pos;
+                }
                 $value = self::decode($data, $pos);
+                if (!strcmp($key, "info")) {
+                //if ($key === "info") {
+                  $return['info_hash']['length'] = ($pos - $return['info_hash']['pos']);
+                }
                 if ($key === null || $value === null) {
                     break;
                 }
@@ -125,6 +136,9 @@
             $return = '';
             $check = -1;
             $list = true;
+            if (isset($data['info_hash'])) {
+              unset($data['info_hash']);
+            }
             foreach ($data as $key => $value) {
                 if ($key !== ++$check) {
                     $list = false;

解析种子torrent所包含的文件名称信息,将名称和文件大小组合排序并计算sha,sha相同则2个种子内容一样可自动辅种。

<?php
require_once './Bencode.php';
require_once './ParseErrorException.php';
$bencode = new Bencode(); 
$str = file_get_contents($filename);
$s = $bencode->decode($str);

if (isset($s['info']["files"])) {
  foreach ($s['info']["files"] as $v) {
    $length = $v["length"];
    $file = end($v["path"]);
    $save[] = $length.$file;
  }
} else {
  $length = $s['info']["length"];
  $file = $s['info']["name"];
  $save[] = $length.$file;
}
if (isset($s["encoding"])) {
  $coding = $s["encoding"];
} else {
  $coding = mb_detect_encoding(implode('', $save), ['UTF-8', 'GB18030', 'GBK', 'GB2312', 'ISO-8859-1']);
  echo 'detect encoding: '.$coding.PHP_EOL;
}
if (!$coding) {
  $coding = 'UTF-8';
}
if ($coding != "UTF-8") {
  foreach ($save as $k => $v) {
    $save[$k] = mb_convert_encoding($v, "UTF-8", $coding);
  }
}
sort($save);
$sha1 = sha1(implode('', $save));

N1用transmission刷PT自动挂载移动硬盘配置问题

发布时间:March 2, 2019 // 分类:PT,N1 // No Comments

挂载移动硬盘fstab配置文件,nofail当移动硬盘没插入时不提示错误,要不然提示错误进不去系统,noatime提升硬盘文件系统性能

/dev/sda1       /mnt            ext4            defaults,nofail,noatime,errors=remount-ro       0 2

配置transmission当移动硬盘挂载后才开始启动,且启动前检查下载目录是否存在,否则启动失败。

查看system生成的移动硬盘挂载服务,然后配置transmission在其挂载之后启动。

systemctl list-unit-files |grep -i mount|grep mnt
mnt.mount                                  generated      

transmission service配置:

[Unit]
Description=Transmission BitTorrent Daemon
After=network.target mnt.mount 

[Service]
LimitNOFILE=65535
User=debian-transmission
#Type=notify
Type=simple
ExecStartPre=/usr/bin/test -d /mnt/downloads
#RequiresMountsFor=/mnt
ExecStart=/usr/bin/transmission-daemon -f --log-error -g /var/lib/transmission-daemon/.config/transmission-daemon/
ExecStop=/bin/kill -s STOP $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID

[Install]
WantedBy=multi-user.target

参考:
https://unix.stackexchange.com/questions/246935/set-systemd-service-to-execute-after-fstab-mount

transmission rpc api php

发布时间:December 29, 2018 // 分类:PT // No Comments

<?php
class transmission {
  public $url;
  public $user;
  public $pass;
  public $session_id = '';
  public $header = array(
    //'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
    'Connection: keep-alive'
  );

  public function __construct($url, $user, $pass) {
    $this->url = $url;
    $this->user = $user;
    $this->pass = $pass;
    $this->request();
  }

  function request($post = "") {
    //echo $url.PHP_EOL;
    $url = $this->url;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    $header = $this->header;
    if ($this->session_id) {
      $header[] = 'X-Transmission-Session-Id: '.$this->session_id;
    }
    $header[] = "Authorization: Basic ".base64_encode($this->user.':'.$this->pass);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    if ($post) {
      echo $post.PHP_EOL;
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    }
    $data = curl_exec($curl);
    $code = curl_getinfo($curl)["http_code"];
    $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
    //var_dump(curl_getinfo($curl));
    curl_close($curl);
    $header = substr($data, 0, $header_size);
    $body = substr($data, $header_size);
    //var_dump($header);
    //var_dump($body);
    if ($code == 409 && preg_match('/<code>X-Transmission-Session-Id: (.*?)<\/code>/', $data, $mh)) {
      $this->session_id = $mh[1];
    } elseif ($code == 401) {
      die("Authorization error".PHP_EOL);
    } elseif ($code == 200) {
      return json_decode($body, 1);
    }
  }

  function build_request($method, $arguments) {
    $post_data = json_encode(array('method' => $method, 'arguments' => $arguments));
    return $this->request($post_data);
  }

  public function get($ids = null, $fields = null) {
    $fields = $fields ? $fields : array( "id", "name", "status", "doneDate", "haveValid", "totalSize", "trackers", "uploadLimited", "uploadLimit");
    $arguments = $ids ? array("fields" => $fields, "ids" => $ids) : array("fields" => $fields);
    return $this->build_request( "torrent-get", $arguments );
  }

  public function reannounce($ids = null) {
    $arguments = $ids ? array("ids" => $ids) : array();
    return $this->build_request( "torrent-reannounce", $arguments);
  }
}

/*
$rpc = new transmission("http://192.168.168.6:9091/transmission/rpc", "admin", "pass");
$data = $rpc->get(array(1), array('id'));
//$data = $rpc->get();
$data = $rpc->reannounce();
var_dump($data);
 */

更多参数:
https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt

ubuntu18.04编译使用transmission2.92/2.94/3.0跳过校验

发布时间:November 16, 2018 // 分类:PT // No Comments

安装编译环境及transmission依赖:

apt-get install ca-certificates libcurl4-openssl-dev libssl-dev pkg-config build-essential checkinstall libevent-dev intltool libtool zlib1g-dev

下载编译transmission:

wget http://archive.ubuntu.com/ubuntu/pool/main/t/transmission/transmission_2.92.orig.tar.gz
tar zxvf transmission_2.92.orig.tar.gz 
cd transmission-2.92
wget http://archive.ubuntu.com/ubuntu/pool/main/t/transmission/transmission_2.92-3ubuntu2.debian.tar.xz
tar Jxvf transmission_2.92-3ubuntu2.debian.tar.xz 
#打openssl补丁,不然编译失败
patch -p 1 < debian/patches/f91cf5ad8c677b61ceb0bf5877b87f9e93256dd7.patch 
#patch -p 1 < debian/patches/8c8386a7f3f482a9c917f51d28e0042e55f56b3e.patch 
#patch -p 1 < debian/patches/transmission-fix-dns-rebinding-vuln.patch 
#transmission跳过校验patch
wget https://github.com/superlukia/transmission-2.92_skiphashcheck/commit/56e327d1dacb5b3453954b76a6d0edd30edb7a34.patch
patch -p 1 < 56e327d1dacb5b3453954b76a6d0edd30edb7a34.patch
./configure 
make 
#替换已安装的transmission-daemon
mv /usr/bin/transmission-daemon /usr/bin/transmission-daemon.bak
cp daemon/transmission-daemon /usr/bin/transmission-daemon

2.94:

apt-get source transmission-daemon
#tar zxf transmission_2.94.orig.tar.gz transmission-2.94/
cd transmission-2.94/
wget https://github.com/blackyau/Transmission_SkipHashChek/commit/0a18e4dffc7002eb80abe39ae8c8c8aec1205967.patch
git apply 0a18e4dffc7002eb80abe39ae8c8c8aec1205967.patch
./autogen.sh
make

3.0:

apt install git ca-certificates libcurl4-openssl-dev libssl-dev pkg-config build-essential checkinstall libevent-dev intltool libtool zlib1g-dev libglib2.0-dev libsystemd-dev
git clone https://github.com/transmission/transmission
cd transmission/
git checkout 3.00
git submodule update --init
git clone https://github.com/TonyRL/docker-transmission-skip-hash-check.git
patch -p0 < docker-transmission-skip-hash-check/patches/001-skip-hash-checking.patch 
patch -p0 < docker-transmission-skip-hash-check/patches/002-fdlimit.patch 
patch -p0 < docker-transmission-skip-hash-check/patches/003-random-announce.patch 
./autogen.sh --prefix=/usr/local/transmission --with-systemd 
make && make install

如果编译时没安装libsystemd依赖,需修改下systemd服务,不然通过systemctl启动transmission会卡住。

cat /etc/systemd/system/multi-user.target.wants/transmission-daemon.service
[Unit]
Description=Transmission BitTorrent Daemon
After=network.target

[Service]
User=debian-transmission
#Type=notify
Type=simple
ExecStart=/usr/bin/transmission-daemon -f --log-error -g /var/lib/transmission-daemon/.config/transmission-daemon/
ExecStop=/bin/kill -s STOP $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID

[Install]
WantedBy=multi-user.target

在WEB界面添加种子后校验时右键点击种子Ask tracker for more peers即可跳过校验。
另类方法:
https://www.jianshu.com/p/ab2df4282e59
参考:
https://github.com/superlukia/transmission-2.92_skiphashcheck
https://blog.csdn.net/Sardkit/article/details/79911925

此内容被密码保护

发布时间:October 11, 2018 // 分类:PT // No Comments

请输入密码访问

分类
最新文章
最近回复
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...
  • jiangker: good, very helpful to me
  • fengfeng: N1 armbian 能有编译下内核吗。。我要开启can 不懂怎么操作