mirror of
https://gitee.com/ledc/IYUUAutoReseed
synced 2025-07-06 15:41:53 +00:00
优化瓷器cookie有效性检查
This commit is contained in:
@ -134,12 +134,10 @@ class AutoReseed
|
|||||||
echo($table->render());
|
echo($table->render());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 连接远端RPC服务器
|
* 连接远端RPC下载器
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public static function links()
|
public static function links()
|
||||||
{
|
{
|
||||||
if (empty(self::$links)) {
|
|
||||||
foreach (self::$clients as $k => $v) {
|
foreach (self::$clients as $k => $v) {
|
||||||
// 跳过未配置的客户端
|
// 跳过未配置的客户端
|
||||||
if (empty($v['username']) || empty($v['password'])) {
|
if (empty($v['username']) || empty($v['password'])) {
|
||||||
@ -159,13 +157,10 @@ class AutoReseed
|
|||||||
self::$move = array($k,$v['move']);
|
self::$move = array($k,$v['move']);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
echo '[Links ERROR] ' . $e->getMessage() . PHP_EOL;
|
die('[Links ERROR] ' . $e->getMessage() . PHP_EOL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 添加下载任务
|
* @brief 添加下载任务
|
||||||
@ -216,8 +211,8 @@ class AutoReseed
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'qBittorrent':
|
case 'qBittorrent':
|
||||||
$extra_options['paused'] = 'true';
|
|
||||||
$extra_options['autoTMM'] = 'false'; //关闭自动种子管理
|
$extra_options['autoTMM'] = 'false'; //关闭自动种子管理
|
||||||
|
$extra_options['paused'] = 'true';
|
||||||
if ($is_url) {
|
if ($is_url) {
|
||||||
$result = self::$links[$rpcKey]['rpc']->add($torrent, $save_path, $extra_options); // 种子URL添加下载任务
|
$result = self::$links[$rpcKey]['rpc']->add($torrent, $save_path, $extra_options); // 种子URL添加下载任务
|
||||||
} else {
|
} else {
|
||||||
@ -246,8 +241,7 @@ class AutoReseed
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief 提交种子hash给远端API,用来获取辅种数据
|
* 提交种子hash给远端API,用来获取辅种数据
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static function call()
|
public static function call()
|
||||||
{
|
{
|
||||||
@ -257,7 +251,6 @@ class AutoReseed
|
|||||||
self::reseed();
|
self::reseed();
|
||||||
self::wechatMessage();
|
self::wechatMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IYUUAutoReseed辅种
|
* IYUUAutoReseed辅种
|
||||||
*/
|
*/
|
||||||
@ -274,7 +267,7 @@ class AutoReseed
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 过滤无需辅种的客户端
|
// 过滤无需辅种的客户端
|
||||||
if (self::$move!==null && self::$move[1]==2) {
|
if (self::$move!==null && self::$move[0]!=$k && self::$move[1]==2) {
|
||||||
echo "clients_".$k." 根据设置无需辅种,已跳过!";
|
echo "clients_".$k." 根据设置无需辅种,已跳过!";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -285,7 +278,6 @@ class AutoReseed
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
$infohash_Dir = $hashArray['hashString'];
|
$infohash_Dir = $hashArray['hashString'];
|
||||||
#p($infohash_Dir);
|
|
||||||
unset($hashArray['hashString']);
|
unset($hashArray['hashString']);
|
||||||
// 签名
|
// 签名
|
||||||
$hashArray['sign'] = Oauth::getSign();
|
$hashArray['sign'] = Oauth::getSign();
|
||||||
@ -369,17 +361,19 @@ class AutoReseed
|
|||||||
self::$wechatMsg['reseedPass']++;
|
self::$wechatMsg['reseedPass']++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// 检查站点是否可以辅种
|
||||||
|
if (in_array($siteName, self::$noReseed)) {
|
||||||
|
echo '-------已跳过不辅种的站点:'.$_url.PHP_EOL.PHP_EOL;
|
||||||
|
self::$wechatMsg['reseedPass']++;
|
||||||
|
// 写入日志文件,供用户手动辅种
|
||||||
|
wlog('clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL.$_url.PHP_EOL.PHP_EOL, $siteName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 种子URL组合方式区分
|
* 种子URL组合方式区分
|
||||||
*/
|
*/
|
||||||
$url = self::getTorrentUrl($siteName, $_url);
|
$url = self::getTorrentUrl($siteName, $_url);
|
||||||
/**
|
$reseedPass = false;
|
||||||
* 检查站点是否可以辅种
|
|
||||||
*/
|
|
||||||
if ((in_array($siteName, self::$noReseed)==false)) {
|
|
||||||
/**
|
|
||||||
* 可以辅种
|
|
||||||
*/
|
|
||||||
// 特殊站点:推送给下载器种子元数据
|
// 特殊站点:推送给下载器种子元数据
|
||||||
switch ($siteName) {
|
switch ($siteName) {
|
||||||
case 'hdchina':
|
case 'hdchina':
|
||||||
@ -388,17 +382,38 @@ class AutoReseed
|
|||||||
// 拼接URL
|
// 拼接URL
|
||||||
$details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1');
|
$details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1');
|
||||||
$details_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$details_page;
|
$details_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$details_page;
|
||||||
|
print "种子详情页:".$details_url.PHP_EOL;
|
||||||
$details_html = download($details_url, $cookie, $userAgent);
|
$details_html = download($details_url, $cookie, $userAgent);
|
||||||
|
if (empty($details_html)) {
|
||||||
|
echo 'cookie已过期,请更新后重新辅种!已加入排除列表'.PHP_EOL;
|
||||||
|
$t = 30;
|
||||||
|
do {
|
||||||
|
echo microtime(true)." cookie已过期,请更新后重新辅种!已加入排除列表!,{$t}秒后继续...".PHP_EOL;
|
||||||
|
sleep(1);
|
||||||
|
} while (--$t > 0);
|
||||||
|
$configALL[$siteName]['cookie'] = '';
|
||||||
|
// 标志:跳过辅种
|
||||||
|
$reseedPass = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (strpos($details_html, '没有该ID的种子') != false) {
|
if (strpos($details_html, '没有该ID的种子') != false) {
|
||||||
# code... 错误通知
|
# code... 错误通知
|
||||||
|
// 标志:跳过辅种
|
||||||
|
$reseedPass = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
print "种子详情页:".$details_url.PHP_EOL;
|
|
||||||
// 提取种子下载地址
|
// 提取种子下载地址
|
||||||
$download_page = str_replace('{}', '', $sites[$sitesID]['download_page']);
|
$download_page = str_replace('{}', '', $sites[$sitesID]['download_page']);
|
||||||
$offset = strpos($details_html, $download_page);
|
$offset = strpos($details_html, $download_page);
|
||||||
$urlTemp = substr($details_html, $offset, 50);
|
$urlTemp = substr($details_html, $offset, 50);
|
||||||
// 种子地址
|
// 种子地址
|
||||||
$_url = substr($urlTemp, 0, strpos($urlTemp, '">'));
|
$_url = substr($urlTemp, 0, strpos($urlTemp, '">'));
|
||||||
|
if (empty($_url)) {
|
||||||
|
echo '未知错误,未提取到种子URL,请联系脚本作者!'.PHP_EOL;
|
||||||
|
// 标志:跳过辅种
|
||||||
|
$reseedPass = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' . $_url;
|
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' . $_url;
|
||||||
print "种子下载页:".$_url.PHP_EOL;
|
print "种子下载页:".$_url.PHP_EOL;
|
||||||
$url = download($_url, $cookie, $userAgent);
|
$url = download($_url, $cookie, $userAgent);
|
||||||
@ -412,12 +427,16 @@ class AutoReseed
|
|||||||
} while (--$t > 0);
|
} while (--$t > 0);
|
||||||
ff($siteName. '站点,辅种时触发第一次下载提示!');
|
ff($siteName. '站点,辅种时触发第一次下载提示!');
|
||||||
self::$noReseed[] = 'hdchina';
|
self::$noReseed[] = 'hdchina';
|
||||||
|
// 标志:跳过辅种
|
||||||
|
$reseedPass = true;
|
||||||
}
|
}
|
||||||
if (strpos($url, '系统检测到过多的种子下载请求') != false) {
|
if (strpos($url, '系统检测到过多的种子下载请求') != false) {
|
||||||
echo "当前站点触发人机验证,已加入排除列表".PHP_EOL;
|
echo "当前站点触发人机验证,已加入排除列表".PHP_EOL;
|
||||||
ff($siteName. '站点,辅种时触发人机验证!');
|
ff($siteName. '站点,辅种时触发人机验证!');
|
||||||
$configALL[$siteName]['limit'] = 1;
|
$configALL[$siteName]['limit'] = 1;
|
||||||
self::$noReseed[] = 'hdchina';
|
self::$noReseed[] = 'hdchina';
|
||||||
|
// 标志:跳过辅种
|
||||||
|
$reseedPass = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'hdcity':
|
case 'hdcity':
|
||||||
@ -444,6 +463,10 @@ class AutoReseed
|
|||||||
// 默认站点:推送给下载器种子URL链接
|
// 默认站点:推送给下载器种子URL链接
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// 检查switch内是否异常
|
||||||
|
if ($reseedPass) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// 把拼接的种子URL,推送给下载器
|
// 把拼接的种子URL,推送给下载器
|
||||||
$ret = false;
|
$ret = false;
|
||||||
// 成功返回:true
|
// 成功返回:true
|
||||||
@ -467,32 +490,11 @@ class AutoReseed
|
|||||||
wlog($url.PHP_EOL, 'reseedSuccess');
|
wlog($url.PHP_EOL, 'reseedSuccess');
|
||||||
// 成功累加
|
// 成功累加
|
||||||
self::$wechatMsg['reseedSuccess']++;
|
self::$wechatMsg['reseedSuccess']++;
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
// 失败的种子
|
// 失败的种子
|
||||||
wlog($url.PHP_EOL, 'reseedError');
|
wlog($url.PHP_EOL, 'reseedError');
|
||||||
// 失败累加
|
// 失败累加
|
||||||
self::$wechatMsg['reseedError']++;
|
self::$wechatMsg['reseedError']++;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/**
|
|
||||||
* 不辅种
|
|
||||||
*/
|
|
||||||
echo '-------已跳过不辅种的站点:'.$_url.PHP_EOL.PHP_EOL;
|
|
||||||
// 按站点规范日志内容
|
|
||||||
switch ($siteName) {
|
|
||||||
case 'hdchina':
|
|
||||||
$url = $details_url;
|
|
||||||
break;
|
|
||||||
case 'hdcity':
|
|
||||||
$url = $_url;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// 写入日志文件,供用户手动辅种
|
|
||||||
wlog('clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL.$url.PHP_EOL.$details_url.PHP_EOL.PHP_EOL, $siteName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -513,7 +515,6 @@ class AutoReseed
|
|||||||
}
|
}
|
||||||
echo "正在从下载器 clients_".$k." 获取种子哈希……".PHP_EOL;
|
echo "正在从下载器 clients_".$k." 获取种子哈希……".PHP_EOL;
|
||||||
$hashArray = self::$links[$k]['rpc']->getList($move);
|
$hashArray = self::$links[$k]['rpc']->getList($move);
|
||||||
#p($move);exit;
|
|
||||||
if (empty($hashArray)) {
|
if (empty($hashArray)) {
|
||||||
// 失败
|
// 失败
|
||||||
continue;
|
continue;
|
||||||
@ -522,14 +523,13 @@ class AutoReseed
|
|||||||
// 写日志
|
// 写日志
|
||||||
wlog($hashArray, 'move'.$k);
|
wlog($hashArray, 'move'.$k);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 前置过滤:移除转移成功的hash
|
// 前置过滤:移除转移成功的hash
|
||||||
$rs = self::hashFilter($infohash_Dir);
|
$rs = self::hashFilter($infohash_Dir);
|
||||||
if ($rs) {
|
if ($rs) {
|
||||||
echo "clients_".$k." 全部转移成功,本次无需转移!".PHP_EOL.PHP_EOL;
|
echo "clients_".$k." 全部转移成功,本次无需转移!".PHP_EOL.PHP_EOL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// 循环转移做种客户端
|
||||||
foreach ($infohash_Dir as $info_hash => $downloadDir) {
|
foreach ($infohash_Dir as $info_hash => $downloadDir) {
|
||||||
// 做种实际路径与相对路径之间互转
|
// 做种实际路径与相对路径之间互转
|
||||||
echo '转换前:'.$downloadDir.PHP_EOL;
|
echo '转换前:'.$downloadDir.PHP_EOL;
|
||||||
@ -538,20 +538,17 @@ class AutoReseed
|
|||||||
if (is_null($downloadDir)) {
|
if (is_null($downloadDir)) {
|
||||||
die("全局配置的move数组内,路径转换参数配置错误,请重新配置!!!".PHP_EOL);
|
die("全局配置的move数组内,路径转换参数配置错误,请重新配置!!!".PHP_EOL);
|
||||||
}
|
}
|
||||||
|
// 种子目录:脚本要能够读取到
|
||||||
// 种子扩展参数
|
|
||||||
$extra_options = array();
|
|
||||||
$path = self::$links[$k]['BT_backup'];
|
$path = self::$links[$k]['BT_backup'];
|
||||||
// 待删除种子
|
// 待删除种子
|
||||||
$torrentDelete = '';
|
$torrentDelete = '';
|
||||||
|
|
||||||
// 获取种子原文件的实际路径
|
// 获取种子原文件的实际路径
|
||||||
|
|
||||||
switch ($v['type']) {
|
switch ($v['type']) {
|
||||||
case 'transmission':
|
case 'transmission':
|
||||||
|
// 优先使用API提供的种子路径
|
||||||
$torrentPath = $move[$info_hash]['torrentFile'];
|
$torrentPath = $move[$info_hash]['torrentFile'];
|
||||||
$torrentDelete = $move[$info_hash]['id'];
|
$torrentDelete = $move[$info_hash]['id'];
|
||||||
// 脚本与tr不在一起的兼容性处理
|
// API提供的种子路径不存在时,使用配置内指定的BT_backup路径
|
||||||
if (!is_file($torrentPath)) {
|
if (!is_file($torrentPath)) {
|
||||||
$torrentPath = str_replace("\\", "/", $torrentPath);
|
$torrentPath = str_replace("\\", "/", $torrentPath);
|
||||||
$torrentPath = $path . strrchr($torrentPath, '/');
|
$torrentPath = $path . strrchr($torrentPath, '/');
|
||||||
@ -563,14 +560,11 @@ class AutoReseed
|
|||||||
}
|
}
|
||||||
$torrentPath = $path .DS. $info_hash . '.torrent';
|
$torrentPath = $path .DS. $info_hash . '.torrent';
|
||||||
$torrentDelete = $info_hash;
|
$torrentDelete = $info_hash;
|
||||||
$extra_options['skip_checking'] = 'true'; //跳校验
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
# code...
|
# code...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断种子原文件是否存在
|
|
||||||
if (!is_file($torrentPath)) {
|
if (!is_file($torrentPath)) {
|
||||||
die("clients_".$k." 的种子文件{$torrentPath}不存在,无法完成转移!");
|
die("clients_".$k." 的种子文件{$torrentPath}不存在,无法完成转移!");
|
||||||
}
|
}
|
||||||
@ -579,9 +573,16 @@ class AutoReseed
|
|||||||
// 正式开始转移
|
// 正式开始转移
|
||||||
echo "种子已推送给下载器,正在转移做种...".PHP_EOL;
|
echo "种子已推送给下载器,正在转移做种...".PHP_EOL;
|
||||||
$ret = false;
|
$ret = false;
|
||||||
|
// 目标下载器类型
|
||||||
|
$rpcKey = self::$move[0];
|
||||||
|
$type = self::$links[$rpcKey]['type'];
|
||||||
|
if ($type == 'qBittorrent') {
|
||||||
|
$extra_options['skip_checking'] = "true"; //转移时,跳校验
|
||||||
|
} else {
|
||||||
|
$extra_options = array();
|
||||||
|
}
|
||||||
// 成功返回:true
|
// 成功返回:true
|
||||||
$ret = self::add(self::$move[0], $torrent, $downloadDir, $extra_options);
|
$ret = self::add(self::$move[0], $torrent, $downloadDir, $extra_options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转移成功的种子写日志
|
* 转移成功的种子写日志
|
||||||
*/
|
*/
|
||||||
|
@ -157,7 +157,6 @@ class qBittorrent extends AbstractClient
|
|||||||
#$extra_options['skip_checking'] = 'true'; //跳校验
|
#$extra_options['skip_checking'] = 'true'; //跳校验
|
||||||
// 关键 上传文件流 multipart/form-data【严格按照api文档编写】
|
// 关键 上传文件流 multipart/form-data【严格按照api文档编写】
|
||||||
$post_data = $this->buildData($extra_options);
|
$post_data = $this->buildData($extra_options);
|
||||||
#p($post_data);
|
|
||||||
// 设置请求头
|
// 设置请求头
|
||||||
$this->curl->setHeader('Content-Type', 'multipart/form-data; boundary='.$this->delimiter);
|
$this->curl->setHeader('Content-Type', 'multipart/form-data; boundary='.$this->delimiter);
|
||||||
$this->curl->setHeader('Content-Length', strlen($post_data));
|
$this->curl->setHeader('Content-Length', strlen($post_data));
|
||||||
|
Reference in New Issue
Block a user