新增功能微信通知自动辅种

This commit is contained in:
iyuu.cn
2019-12-27 19:47:43 +08:00
parent 54a2a501b6
commit 3c880ea5ee
4 changed files with 98 additions and 29 deletions

View File

@@ -11,6 +11,7 @@ if ( iyuuAutoReseed::$move != null ) {
exit; exit;
} }
iyuuAutoReseed::call($hashArray); iyuuAutoReseed::call($hashArray);
iyuuAutoReseed::wechatMessage();
/** /**
* iyuu自动辅种类 * iyuu自动辅种类
*/ */
@@ -55,6 +56,19 @@ class iyuuAutoReseed
*/ */
public static $move = null; public static $move = null;
/** /**
* 微信消息体
*/
public static $wechatMsg = array(
'hashCount' => 0, // 提交给服务器的hash总数
'sitesCount' => 0, // 可辅种站点总数
'reseedCount' => 0, // 返回的总数据
'reseedSuccess' => 0, // 成功:辅种成功(会加入缓存,哪怕种子在校验中,下次也会过滤)
'reseedError' => 0, // 错误:辅种失败(可以重试)
'reseedRepeat' => 0, // 重复:客户端已做种
'reseedSkip' => 0, // 跳过因未设置passkey而跳过
'reseedPass' => 0, // 忽略:因上次成功添加、存在缓存,而跳过
);
/**
* 初始化 * 初始化
*/ */
public static function init(){ public static function init(){
@@ -67,10 +81,10 @@ class iyuuAutoReseed
// 建立目录 // 建立目录
IFile::mkdir(self::$cacheDir); IFile::mkdir(self::$cacheDir);
IFile::mkdir(self::$cacheHash); IFile::mkdir(self::$cacheHash);
// 连接全局客户端
self::links(); self::links();
// 合作站点自动注册鉴权 // 合作站点自动注册鉴权
Oauth::login(self::$apiUrl . self::$endpoints['login']); Oauth::login(self::$apiUrl . self::$endpoints['login']);
#exit;
} }
/** /**
* 连接远端RPC服务器 * 连接远端RPC服务器
@@ -154,6 +168,8 @@ class iyuuAutoReseed
$info_hash = array_column($res, 'hashString'); $info_hash = array_column($res, 'hashString');
// 升序排序 // 升序排序
sort($info_hash); sort($info_hash);
// 微信模板消息 统计
self::$wechatMsg['hashCount'] += count($info_hash);
$json = json_encode($info_hash, JSON_UNESCAPED_UNICODE); $json = json_encode($info_hash, JSON_UNESCAPED_UNICODE);
// 去重 应该从文件读入,防止重复提交 // 去重 应该从文件读入,防止重复提交
$sha1 = sha1( $json ); $sha1 = sha1( $json );
@@ -181,6 +197,8 @@ class iyuuAutoReseed
$info_hash = array_column($res, 'hash'); $info_hash = array_column($res, 'hash');
// 升序排序 // 升序排序
sort($info_hash); sort($info_hash);
// 微信模板消息 统计
self::$wechatMsg['hashCount'] += count($info_hash);
$json = json_encode($info_hash, JSON_UNESCAPED_UNICODE); $json = json_encode($info_hash, JSON_UNESCAPED_UNICODE);
// 去重 应该从文件读入,防止重复提交 // 去重 应该从文件读入,防止重复提交
$sha1 = sha1( $json ); $sha1 = sha1( $json );
@@ -261,7 +279,27 @@ class iyuuAutoReseed
echo '[ERROR] ' . $e->getMessage() . PHP_EOL; echo '[ERROR] ' . $e->getMessage() . PHP_EOL;
} }
return false; return false;
} }
/**
* 正常做种的种子在各下载器的互相转移
*/
public static function move($torrent=array(), $type = 'qBittorrent'){
switch($type){
case 'transmission':
break;
case 'qBittorrent':
foreach ($torrent as $k => $v) {
// 路径转换
#$v['save_path'] = '/volume3' . $v['save_path']; // docker路径转换
self::add(self::$move[0], $v['magnet_uri'], $v['save_path'] );
}
break;
default:
echo '[ERROR] '.$type;
break;
}
}
/** /**
* @brief 提交种子hash给远端API用来获取辅种数据 * @brief 提交种子hash给远端API用来获取辅种数据
* @param array $hashArray 种子hash数组 * @param array $hashArray 种子hash数组
@@ -309,30 +347,35 @@ class iyuuAutoReseed
} }
// 可辅种站点信息列表 // 可辅种站点信息列表
$sites = $resArray['sites']; $sites = $resArray['sites'];
self::$wechatMsg['sitesCount'] = count($sites);
#p($sites); #p($sites);
// 按客户端循环辅种 // 按客户端循环辅种 开始
foreach (self::$links as $k => $v) { foreach (self::$links as $k => $v) {
$reseed = $infohash_Dir = array(); $reseed = $infohash_Dir = array();
// info_hash 对应的下载目录
$infohash_Dir = self::$links[$k]['hash'];
if (empty($resArray['clients_'.$k])) { if (empty($resArray['clients_'.$k])) {
echo "clients_".$k."没有查询到可辅种数据 \n\n"; echo "clients_".$k."没有查询到可辅种数据 \n\n";
continue; continue;
} }
// 当前客户端辅种数据 // 当前客户端辅种数据
$reseed = $resArray['clients_'.$k]; $reseed = $resArray['clients_'.$k];
// info_hash 对应的下载目录
$infohash_Dir = self::$links[$k]['hash'];
foreach ($reseed as $info_hash => $vv) { foreach ($reseed as $info_hash => $vv) {
// 当前种子哈希对应的目录 // 当前种子哈希对应的目录
$downloadDir = $infohash_Dir[$info_hash]; $downloadDir = $infohash_Dir[$info_hash];
foreach ($vv['torrent'] as $id => $value) { foreach ($vv['torrent'] as $id => $value) {
// 匹配的辅种数据累加
self::$wechatMsg['reseedCount']++;
$sitesID = $value['sid']; $sitesID = $value['sid'];
$url = $_url = ''; $url = $_url = '';
$download_page = ''; $download_page = '';
// 页面规则 // 页面规则
$download_page = str_replace('{}', $value['torrent_id'], $sites[$sitesID]['download_page']); $download_page = str_replace('{}', $value['torrent_id'], $sites[$sitesID]['download_page']);
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$download_page; $_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$download_page;
if (empty($configALL[$sites[$sitesID]['site']]['passkey'])) { if ( empty($configALL[$sites[$sitesID]['site']]['passkey']) ) {
echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置passkey已跳过' . "\n\n"; echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置passkey已跳过' . "\n\n";
self::$wechatMsg['reseedSkip']++;
continue; continue;
} }
// 种子URL组合方式区分 // 种子URL组合方式区分
@@ -353,19 +396,25 @@ class iyuuAutoReseed
$url = $_url."&passkey=". $configALL[$sites[$sitesID]['site']]['passkey']; $url = $_url."&passkey=". $configALL[$sites[$sitesID]['site']]['passkey'];
break; break;
} }
// 检查不辅种的站点 /**
// 判断是否VIP或特殊权限 * 检查站点是否可以辅种
*/
// 判断是否具有VIP或特殊权限
$is_vip = isset($configALL[$sites[$sitesID]['site']]['is_vip']) && $configALL[$sites[$sitesID]['site']]['is_vip'] ? 1 : 0; $is_vip = isset($configALL[$sites[$sitesID]['site']]['is_vip']) && $configALL[$sites[$sitesID]['site']]['is_vip'] ? 1 : 0;
if ( (in_array($sites[$sitesID]['site'], self::$noReseed)==false) || $is_vip ) { if ( (in_array($sites[$sitesID]['site'], self::$noReseed)==false) || $is_vip ) {
// 可以辅种 /**
* 可以辅种
*/
if ( isset($infohash_Dir[$value['info_hash']]) ) { if ( isset($infohash_Dir[$value['info_hash']]) ) {
// 与客户端现有种子重复 // 与客户端现有种子重复
echo '-------与客户端现有种子重复:'.$_url."\n\n"; echo '-------与客户端现有种子重复:'.$_url."\n\n";
self::$wechatMsg['reseedRepeat']++;
continue; continue;
}else{ }else{
// 判断上次是否成功添加? // 判断上次是否成功添加?
if ( is_file(self::$cacheHash . $value['info_hash'].'.txt') ) { if ( is_file(self::$cacheHash . $value['info_hash'].'.txt') ) {
echo '-------当前种子上次辅种已成功添加,已跳过!'.$_url."\n\n"; echo '-------当前种子上次辅种已成功添加,已跳过!'.$_url."\n\n";
self::$wechatMsg['reseedPass']++;
continue; continue;
} }
// 把拼接的种子URL推送给下载器 // 把拼接的种子URL推送给下载器
@@ -374,15 +423,24 @@ class iyuuAutoReseed
$ret = self::add($k, $url, $downloadDir); $ret = self::add($k, $url, $downloadDir);
// 添加成功的种子以infohash为文件名写入缓存 // 添加成功的种子以infohash为文件名写入缓存
if ($ret) { if ($ret) {
// 成功的种子
// 文件句柄 // 文件句柄
$resource = fopen(self::$cacheHash . $value['info_hash'].'.txt', "wb"); $resource = fopen(self::$cacheHash . $value['info_hash'].'.txt', "wb");
// 成功返回写入字节数失败返回false // 成功返回写入字节数失败返回false
$worldsnum = fwrite($resource, $url); $worldsnum = fwrite($resource, $url);
fclose($resource); fclose($resource);
self::$wechatMsg['reseedSuccess']++;
continue;
}else{
// 失败的种子
self::$wechatMsg['reseedError']++;
continue;
} }
} }
}else{ }else{
// 不辅种 /**
* 不辅种
*/
echo '-------已跳过不辅种的站点:'.$_url."\n\n"; echo '-------已跳过不辅种的站点:'.$_url."\n\n";
// 写入日志文件,供用户手动辅种 // 写入日志文件,供用户手动辅种
if ( !isset($infohash_Dir[$value['info_hash']]) ) { if ( !isset($infohash_Dir[$value['info_hash']]) ) {
@@ -396,31 +454,36 @@ class iyuuAutoReseed
} }
} }
} }
// 按客户端循环辅种 结束
} }
/** /**
* 正常做种的种子在各下载器的互相转移 *
*/ */
public static function move($torrent=array(), $type = 'qBittorrent'){ public static function wechatMessage(){
switch($type){ $br = "\r\n";
case 'transmission': $text = 'IYUU自动辅种-统计报表';
break; $desp = '总做种:'.self::$wechatMsg['hashCount'] . ' [客户端正在做种的hash总数]' .$br;
case 'qBittorrent': $desp .= '返回数据:'.self::$wechatMsg['reseedCount']. ' [服务器返回的可辅种数据]' .$br;
foreach ($torrent as $k => $v) { $desp .= '支持站点:'.self::$wechatMsg['sitesCount']. ' [当前支持自动辅种的站点数量]' .$br;
#$v['save_path'] = '/volume3' . $v['save_path']; // docker路径转换 $desp .= '成功:'.self::$wechatMsg['reseedSuccess']. ' [辅种成功会把hash加入缓存]' .$br;
self::add(self::$move[0], $v['magnet_uri'], $v['save_path'] ); $desp .= '失败:'.self::$wechatMsg['reseedError']. ' [下载器下载种子失败或网络超时引起,可以重试]' .$br;
} $desp .= '重复:'.self::$wechatMsg['reseedRepeat']. ' [客户端已做种]' .$br;
break; $desp .= '跳过:'.self::$wechatMsg['reseedSkip']. ' [未设置passkey]' .$br;
default: $desp .= '忽略:'.self::$wechatMsg['reseedPass']. ' [成功添加存在缓存]' .$br;
echo '[ERROR] '.$type; return ff($text, $desp);
break;
}
} }
} }
// transmission过滤函数只保留正常做种
/**
* transmission过滤函数只保留正常做种
*/
function filterStatus( $v ){ function filterStatus( $v ){
return isset($v['status']) && $v['status']===6; return isset($v['status']) && $v['status']===6;
} }
// qBittorrent过滤函数只保留正常做种
/**
* qBittorrent过滤函数只保留正常做种
*/
function qbfilterStatus( $v ){ function qbfilterStatus( $v ){
if( ($v['state']=='uploading') || ($v['state'] == 'stalledUP') ){ if( ($v['state']=='uploading') || ($v['state'] == 'stalledUP') ){
return true; return true;

View File

@@ -58,6 +58,7 @@ IYUU自动辅种工具英文名iyuuAutoReseed是一款PHP语言编
| 风少 | ¥20元 | 2019年12月24日23:30 | | 风少 | ¥20元 | 2019年12月24日23:30 |
| 小夏 | ¥1元 | 2019年12月25日11:38 | | 小夏 | ¥1元 | 2019年12月25日11:38 |
| 优つ伤 | ¥50元 | 2019年12月25日19:21 | | 优つ伤 | ¥50元 | 2019年12月25日19:21 |
| Nice | ¥20元 | 2019年12月27日12:54 |
补充说明: 补充说明:

View File

@@ -8,7 +8,7 @@
| 未配置客户端智能过滤 | 已完成 | 2019年12月25日 | 2019年12月25日 | | 未配置客户端智能过滤 | 已完成 | 2019年12月25日 | 2019年12月25日 |
| 脚本docker容器化 | 暂未开始 | | | | 脚本docker容器化 | 暂未开始 | | |
| 浏览器插件 | 暂未开始 | | | | 浏览器插件 | 暂未开始 | | |
| 自动辅种结束微信通知 | 正在开发 | 2019年12月25日 | | | 自动辅种结束微信通知 | 已完成 | 2019年12月25日 | 2019年12月27日 |
| 合集自动拆包辅种 | 暂未开始 | 2019年12月26日 | | | 合集自动拆包辅种 | 暂未开始 | 2019年12月26日 | |
| 兼容Reseed辅种 | 暂未开始 | | | | 兼容Reseed辅种 | 暂未开始 | | |
| 做种客户端间转移 | 正在开发 | 2019年12月25日 | | | 做种客户端间转移 | 正在开发 | 2019年12月25日 | |

View File

@@ -1,4 +1,9 @@
### 2019年12月27日
新增功能:自动辅种结束,微信通知统计信息
### 2019年12月25日 ### 2019年12月25日
1.新增支持upxinHDU、oshen 1.新增支持upxinHDU、oshen
------ ------