mirror of
https://gitee.com/ledc/IYUUAutoReseed
synced 2025-05-19 16:05:21 +00:00
fix
This commit is contained in:
parent
289df1e126
commit
419b6eb8cd
@ -13,7 +13,7 @@ use IYUU\Library\Table;
|
||||
class AutoReseed
|
||||
{
|
||||
// 版本号
|
||||
const VER = '1.10.2';
|
||||
const VER = '1.10.3';
|
||||
// RPC连接
|
||||
private static $links = [];
|
||||
// 客户端配置
|
||||
@ -276,7 +276,6 @@ class AutoReseed
|
||||
global $configALL;
|
||||
// 支持站点数量
|
||||
self::$wechatMsg['sitesCount'] = count(self::$sites);
|
||||
$sites = self::$sites;
|
||||
// 遍历客户端 开始
|
||||
foreach (self::$links as $k => $v) {
|
||||
if (empty($v)) {
|
||||
@ -311,14 +310,14 @@ class AutoReseed
|
||||
self::$curl->setOpt(CURLOPT_CONNECTTIMEOUT, $connecttimeout);
|
||||
self::$curl->setOpt(CURLOPT_TIMEOUT, $timeout);
|
||||
}
|
||||
// P($infohash_Dir); // 调试:打印目录对应表
|
||||
// p($infohash_Dir); // 调试:打印目录对应表
|
||||
echo "正在向服务器提交 clients_".$k." 种子哈希……".PHP_EOL;
|
||||
$res = self::$curl->post(self::$apiUrl . self::$endpoints['infohash'], $hashArray);
|
||||
$res = json_decode($res->response, true);
|
||||
// 写返回日志
|
||||
wlog($res, 'reseed'.$k);
|
||||
$reseed = isset($res['data']) && $res['data'] ? $res['data'] : array();
|
||||
if (empty($reseed)) {
|
||||
$data = isset($res['data']) && $res['data'] ? $res['data'] : array();
|
||||
if (empty($data)) {
|
||||
echo "clients_".$k." 没有查询到可辅种数据".PHP_EOL.PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
@ -332,282 +331,184 @@ class AutoReseed
|
||||
continue;
|
||||
}
|
||||
// 遍历当前客户端可辅种数据
|
||||
foreach ($reseed as $info_hash => $vv) {
|
||||
// 当前种子哈希对应的目录
|
||||
foreach ($data as $info_hash => $reseed) {
|
||||
// 可辅种信息用哈希对应目录
|
||||
$downloadDir = $infohash_Dir[$info_hash];
|
||||
foreach ($vv['torrent'] as $id => $value) {
|
||||
foreach ($reseed['torrent'] as $id => $value) {
|
||||
// 匹配的辅种数据累加
|
||||
self::$wechatMsg['reseedCount']++;
|
||||
// 站点id
|
||||
$sid = $value['sid'];
|
||||
// 种子id
|
||||
$torrent_id = $value['torrent_id'];
|
||||
// 站点名
|
||||
if (empty($sites[$sid]['site'])) {
|
||||
// 检查禁用站点
|
||||
if (empty(self::$sites[$sid])) {
|
||||
echo '-----当前站点不受支持,已跳过。' .PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
continue;
|
||||
}
|
||||
$siteName = $sites[$sid]['site'];
|
||||
// 站名
|
||||
$siteName = self::$sites[$sid]['site'];
|
||||
// 错误通知
|
||||
self::setNotify($siteName, $sid, $torrent_id);
|
||||
// 页面规则
|
||||
$download_page = str_replace('{}', $torrent_id, $sites[$sid]['download_page']);
|
||||
// 种子页规则
|
||||
$download_page = str_replace('{}', $torrent_id, self::$sites[$sid]['download_page']);
|
||||
// 协议
|
||||
$protocol = $sites[$sid]['is_https'] == 0 ? 'http://' : 'https://';
|
||||
$_url = $protocol . $sites[$sid]['base_url']. '/' .$download_page;
|
||||
$protocol = self::$sites[$sid]['is_https'] == 0 ? 'http://' : 'https://';
|
||||
|
||||
// 临时种子连接(会写入辅种日志)
|
||||
$_url = $protocol . self::$sites[$sid]['base_url']. '/' .$download_page;
|
||||
/**
|
||||
* 前置检测
|
||||
* 辅种前置检查
|
||||
*/
|
||||
// 配置与passkey检测
|
||||
if (empty($configALL[$siteName]) || empty($configALL[$siteName]['passkey'])) {
|
||||
//echo '-------因当前' .$siteName. "站点未设置passkey,已跳过!!".PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
if (!self::reseedCheck($k, $value, $infohash_Dir, $downloadDir, $_url)) {
|
||||
continue;
|
||||
} else {
|
||||
echo "clients_".$k."正在辅种... {$siteName}".PHP_EOL;
|
||||
}
|
||||
// cookie检测
|
||||
if (in_array($siteName, self::$cookieCheck) && empty($configALL[$siteName]['cookie'])) {
|
||||
echo '-------因当前' .$siteName. '站点未设置cookie,已跳过!!' .PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
continue;
|
||||
}
|
||||
// 流控检测
|
||||
if (isset($configALL[$siteName]['limit'])) {
|
||||
echo "-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL;
|
||||
// 流控日志
|
||||
if ($siteName == 'hdchina') {
|
||||
$details_page = str_replace('{}', $torrent_id, 'details.php?id={}&hit=1');
|
||||
$_url = 'https://' .$sites[$sid]['base_url']. '/' .$details_page;
|
||||
}
|
||||
wlog('clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL."-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL, 'reseedLimit');
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
continue;
|
||||
}
|
||||
// 重复做种检测
|
||||
if (isset($value['info_hash']) && isset($infohash_Dir[$value['info_hash']])) {
|
||||
echo '-------与客户端现有种子重复:'.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedRepeat']++;
|
||||
continue;
|
||||
}
|
||||
// 历史添加检测
|
||||
if (is_file(self::$cacheHash . $value['info_hash'].'.txt')) {
|
||||
echo '-------当前种子上次辅种已成功添加,已跳过! '.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedPass']++;
|
||||
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;
|
||||
}
|
||||
// 操作站点流控的配置
|
||||
if (isset($configALL[$siteName]['limitRule']) && $configALL[$siteName]['limitRule']) {
|
||||
$limitRule = $configALL[$siteName]['limitRule'];
|
||||
if (isset($limitRule['count']) && isset($limitRule['sleep'])) {
|
||||
if ($limitRule['count'] <= 0) {
|
||||
echo '-------当前站点辅种数量已满足规则,保障账号安全已跳过:'.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedPass']++;
|
||||
continue;
|
||||
} else {
|
||||
// 异步间隔流控算法:各站独立、执行时间最优
|
||||
$lastTime = isset($limitRule['time']) ? $limitRule['time'] : 0; // 最近一次辅种成功的时间
|
||||
if ($lastTime) {
|
||||
$interval = time() - $lastTime; // 间隔时间
|
||||
if ($interval < $limitRule['sleep']) {
|
||||
$t = $limitRule['sleep'] - $interval + mt_rand(1, 5);
|
||||
do {
|
||||
echo microtime(true)." 为账号安全,辅种进程休眠 {$t} 秒后继续...".PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo '-------当前站点流控规则错误,缺少count或sleep参数!请重新配置!'.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedPass']++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 种子URL组合方式区分
|
||||
* 种子推送方式区分
|
||||
*/
|
||||
$url = self::getTorrentUrl($siteName, $_url);
|
||||
$reseedPass = false; // 标志:跳过辅种
|
||||
// 特殊站点:种子元数据推送给下载器
|
||||
switch ($siteName) {
|
||||
case 'hdchina':
|
||||
$cookie = $configALL[$siteName]['cookie'];
|
||||
$userAgent = $configALL['default']['userAgent'];
|
||||
// 拼接详情页URL
|
||||
$details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1');
|
||||
$details_url = $protocol .$sites[$sid]['base_url']. '/' .$details_page;
|
||||
print "种子详情页:".$details_url.PHP_EOL;
|
||||
$details_html = download($details_url, $cookie, $userAgent);
|
||||
// 删种检查
|
||||
if (strpos($details_html, '没有该ID的种子') != false) {
|
||||
echo '种子已被删除!'.PHP_EOL;
|
||||
self::sendNotify('404');
|
||||
$reseedPass = true;
|
||||
break;
|
||||
}
|
||||
// 提取种子下载地址
|
||||
$offset = strpos($details_html, str_replace('{hash}', '', $sites[$sid]['download_page']));
|
||||
if ($offset === false) {
|
||||
ff($siteName. '站点,cookie已过期,请更新后重新辅种!');
|
||||
echo 'cookie已过期,请更新后重新辅种!已加入排除列表'.PHP_EOL;
|
||||
$t = 15;
|
||||
do {
|
||||
echo microtime(true)." cookie已过期,请更新后重新辅种!已加入排除列表!,{$t}秒后继续...".PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
$configALL[$siteName]['cookie'] = '';
|
||||
$reseedPass = true;
|
||||
break;
|
||||
}
|
||||
// 种子地址
|
||||
$regex = "/download.php\?hash\=(.*?)[\"|\']/i"; // 提取种子hash的正则表达式
|
||||
preg_match($regex, $details_html, $matchs);
|
||||
$download_page = str_replace('{hash}', $matchs[1], $sites[$sid]['download_page']);
|
||||
$_url = $protocol . $sites[$sid]['base_url']. '/' . $download_page;
|
||||
print "种子下载页:".$_url.PHP_EOL;
|
||||
$url = download($_url, $cookie, $userAgent);
|
||||
if (strpos($url, '第一次下载提示') != false) {
|
||||
echo "当前站点触发第一次下载提示,已加入排除列表".PHP_EOL;
|
||||
echo "请进入瓷器详情页,点右上角蓝色框:下载种子,成功后更新cookie!".PHP_EOL;
|
||||
$t = 30;
|
||||
do {
|
||||
echo microtime(true)." 请进入瓷器详情页,点右上角蓝色框:下载种子,成功后更新cookie!,{$t}秒后继续...".PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
ff($siteName. '站点,辅种时触发第一次下载提示!');
|
||||
self::$noReseed[] = $siteName;
|
||||
$reseedPass = true;
|
||||
}
|
||||
if (strpos($url, '系统检测到过多的种子下载请求') != false) {
|
||||
echo "当前站点触发人机验证,已加入排除列表".PHP_EOL;
|
||||
ff($siteName. '站点,辅种时触发人机验证!');
|
||||
$configALL[$siteName]['limit'] = 1;
|
||||
self::$noReseed[] = $siteName;
|
||||
$reseedPass = true;
|
||||
}
|
||||
break;
|
||||
case 'hdcity':
|
||||
$cookie = $configALL[$siteName]['cookie'];
|
||||
$userAgent = $configALL['default']['userAgent'];
|
||||
print "种子:".$_url.PHP_EOL;
|
||||
if (isset($configALL[$siteName]['cuhash'])) {
|
||||
// 已获取cuhash
|
||||
# code...
|
||||
} else {
|
||||
// 获取cuhash
|
||||
$html = download($protocol .$sites[$sid]['base_url']. '/pt', $cookie, $userAgent);
|
||||
// 提取种子下载地址
|
||||
$offset = strpos($html, 'cuhash=');
|
||||
if ($offset === false) {
|
||||
ff($siteName. '站点,cookie已过期,请更新后重新辅种!');
|
||||
echo 'cookie已过期,请更新后重新辅种!'.PHP_EOL;
|
||||
$configALL[$siteName]['cookie'] = '';
|
||||
if (in_array($siteName, self::$cookieCheck)) {
|
||||
// 特殊站点:种子元数据推送给下载器
|
||||
$reseedPass = false; // 标志:跳过辅种
|
||||
$cookie = $configALL[$siteName]['cookie'];
|
||||
$userAgent = $configALL['default']['userAgent'];
|
||||
switch ($siteName) {
|
||||
case 'hdchina':
|
||||
// 请求详情页
|
||||
$details_html = self::getNexusPHPdetailsPage($protocol, $value, $cookie, $userAgent);
|
||||
if (is_null($details_html)) {
|
||||
$reseedPass = true;
|
||||
break;
|
||||
}
|
||||
$regex = "/cuhash\=(.*?)[\"|\']/i"; // 提取种子cuhash的正则表达式
|
||||
preg_match($regex, $html, $matchs);
|
||||
$configALL[$siteName]['cuhash'] = $matchs[1];
|
||||
}
|
||||
$url = str_replace('{cuhash}', $configALL[$siteName]['cuhash'], $_url);
|
||||
// 城市下载种子时会302转向
|
||||
$url = download($url, $cookie, $userAgent);
|
||||
if (strpos($url, 'Non-exist torrent id!') != false) {
|
||||
echo '种子已被删除!'.PHP_EOL;
|
||||
self::sendNotify('404');
|
||||
// 标志:跳过辅种
|
||||
$reseedPass = true;
|
||||
}
|
||||
break;
|
||||
case 'hdsky':
|
||||
$cookie = $configALL[$siteName]['cookie'];
|
||||
$userAgent = $configALL['default']['userAgent'];
|
||||
// 拼接详情页URL
|
||||
$details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1');
|
||||
$details_url = $protocol .$sites[$sid]['base_url']. '/' .$details_page;
|
||||
print "种子详情页:".$details_url.PHP_EOL;
|
||||
$details_html = download($details_url, $cookie, $userAgent);
|
||||
// 删种检查
|
||||
if (strpos($details_html, '没有该ID的种子') != false) {
|
||||
echo '种子已被删除!'.PHP_EOL;
|
||||
self::sendNotify('404');
|
||||
$reseedPass = true;
|
||||
// 搜索种子地址
|
||||
$remove = '{hash}';
|
||||
$offset = strpos($details_html, str_replace($remove, '', self::$sites[$sid]['download_page']));
|
||||
if ($offset === false) {
|
||||
$reseedPass = true;
|
||||
self::cookieExpired($siteName); // cookie失效
|
||||
break;
|
||||
}
|
||||
// 提取种子地址
|
||||
$regex = "/download.php\?hash\=(.*?)[\"|\']/i"; // 提取种子hash的正则表达式
|
||||
if (preg_match($regex, $details_html, $matchs)) {
|
||||
// 拼接种子地址
|
||||
$_url = str_replace($remove, $matchs[1], $_url);
|
||||
echo "下载种子:".$_url.PHP_EOL;
|
||||
$url = download($_url, $cookie, $userAgent);
|
||||
if (strpos($url, '第一次下载提示') != false) {
|
||||
self::$noReseed[] = $siteName;
|
||||
$reseedPass = true;
|
||||
|
||||
echo "当前站点触发第一次下载提示,已加入排除列表".PHP_EOL;
|
||||
sleepIYUU(30, '请进入瓷器详情页,点右上角蓝色框:下载种子,成功后更新cookie!');
|
||||
ff($siteName. '站点,辅种时触发第一次下载提示!');
|
||||
break;
|
||||
}
|
||||
if (strpos($url, '系统检测到过多的种子下载请求') != false) {
|
||||
$configALL[$siteName]['limit'] = 1;
|
||||
$reseedPass = true;
|
||||
|
||||
echo "当前站点触发人机验证,已加入流控列表".PHP_EOL;
|
||||
ff($siteName. '站点,辅种时触发人机验证!');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$reseedPass = true;
|
||||
sleepIYUU(15, $siteName.'正则表达式未匹配到种子地址,可能站点已更新,请联系IYUU作者!');
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 提取种子下载地址
|
||||
$remove = 'id={}&passkey={passkey}';
|
||||
$offset = strpos($details_html, str_replace($remove, '', $sites[$sid]['download_page']));
|
||||
if ($offset === false) {
|
||||
ff($siteName. '站点,cookie已过期,请更新后重新辅种!');
|
||||
echo 'cookie已过期,请更新后重新辅种!已加入排除列表'.PHP_EOL;
|
||||
$t = 15;
|
||||
do {
|
||||
echo microtime(true)." cookie已过期,请更新后重新辅种!已加入排除列表!,{$t}秒后继续...".PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
$configALL[$siteName]['cookie'] = '';
|
||||
$reseedPass = true;
|
||||
case 'hdcity':
|
||||
$details_url = $protocol . self::$sites[$sid]['base_url'] . '/t-' .$torrent_id;
|
||||
print "种子详情页:".$details_url.PHP_EOL;
|
||||
if (empty($configALL[$siteName]['cuhash'])) {
|
||||
// 请求包含cuhash的列表页
|
||||
$html = download($protocol .self::$sites[$sid]['base_url']. '/pt', $cookie, $userAgent);
|
||||
// 搜索cuhash
|
||||
$offset = strpos($html, 'cuhash=');
|
||||
if ($offset === false) {
|
||||
self::cookieExpired($siteName); // cookie失效
|
||||
$reseedPass = true;
|
||||
break;
|
||||
}
|
||||
// 提取cuhash
|
||||
$regex = "/cuhash\=(.*?)[\"|\']/i"; // 提取种子cuhash的正则表达式
|
||||
if (preg_match($regex, $html, $matchs)) {
|
||||
$configALL[$siteName]['cuhash'] = $matchs[1];
|
||||
} else {
|
||||
$reseedPass = true;
|
||||
sleepIYUU(15, $siteName.'正则表达式未匹配到cuhash,可能站点已更新,请联系IYUU作者!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 拼接种子地址
|
||||
$remove = '{cuhash}';
|
||||
$_url = str_replace($remove, $configALL[$siteName]['cuhash'], $_url);
|
||||
// 城市下载种子会302转向
|
||||
echo "下载种子:".$_url.PHP_EOL;
|
||||
$url = download($_url, $cookie, $userAgent);
|
||||
if (strpos($url, 'Non-exist torrent id!') != false) {
|
||||
echo '种子已被删除!'.PHP_EOL;
|
||||
self::sendNotify('404');
|
||||
// 标志:跳过辅种
|
||||
$reseedPass = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 种子地址
|
||||
$regex = '/download.php\?(.*?)["|\']/i';
|
||||
if (preg_match($regex, $details_html, $matchs)) {
|
||||
$download_page = str_replace($remove, '', $sites[$sid]['download_page']).str_replace('&', '&', $matchs[1]);
|
||||
}
|
||||
$_url = $protocol . $sites[$sid]['base_url']. '/' . $download_page;
|
||||
print "种子下载页:".$_url.PHP_EOL;
|
||||
$url = download($_url, $cookie, $userAgent);
|
||||
if (strpos($url, '第一次下载提示') != false) {
|
||||
echo "当前站点触发第一次下载提示,已加入排除列表".PHP_EOL;
|
||||
echo "请进入种子详情页,下载种子,成功后更新cookie!".PHP_EOL;
|
||||
$t = 30;
|
||||
do {
|
||||
echo microtime(true)." 请进入种子详情页,下载种子,成功后更新cookie!,{$t}秒后继续...".PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
ff($siteName. '站点,辅种时触发第一次下载提示!');
|
||||
self::$noReseed[] = $siteName;
|
||||
$reseedPass = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 默认站点:推送给下载器种子URL链接
|
||||
break;
|
||||
case 'hdsky':
|
||||
// 请求详情页
|
||||
$details_html = self::getNexusPHPdetailsPage($protocol, $value, $cookie, $userAgent);
|
||||
if (is_null($details_html)) {
|
||||
$reseedPass = true;
|
||||
break;
|
||||
}
|
||||
// 搜索种子地址
|
||||
$remove = 'id={}&passkey={passkey}';
|
||||
$offset = strpos($details_html, str_replace($remove, '', self::$sites[$sid]['download_page']));
|
||||
if ($offset === false) {
|
||||
self::cookieExpired($siteName); // cookie失效
|
||||
$reseedPass = true;
|
||||
break;
|
||||
}
|
||||
// 提取种子地址
|
||||
$regex = '/download.php\?(.*?)["|\']/i';
|
||||
if (preg_match($regex, $details_html, $matchs)) {
|
||||
// 拼接种子地址
|
||||
$download_page = str_replace($remove, '', self::$sites[$sid]['download_page']).str_replace('&', '&', $matchs[1]);
|
||||
$_url = $protocol . self::$sites[$sid]['base_url']. '/' . $download_page;
|
||||
print "下载种子:".$_url.PHP_EOL;
|
||||
$url = download($_url, $cookie, $userAgent);
|
||||
if (strpos($url, '第一次下载提示') != false) {
|
||||
self::$noReseed[] = $siteName;
|
||||
$reseedPass = true;
|
||||
|
||||
echo "当前站点触发第一次下载提示,已加入排除列表".PHP_EOL;
|
||||
echo "请进入种子详情页,下载种子,成功后更新cookie!".PHP_EOL;
|
||||
sleepIYUU(30, '请进入种子详情页,下载种子,成功后更新cookie!');
|
||||
ff($siteName. '站点,辅种时触发第一次下载提示!');
|
||||
}
|
||||
} else {
|
||||
$reseedPass = true;
|
||||
sleepIYUU(15, $siteName.'正则表达式未匹配到种子地址,可能站点已更新,请联系IYUU作者!');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 默认站点:推送给下载器种子URL链接
|
||||
break;
|
||||
}
|
||||
// 检查switch内是否异常
|
||||
if ($reseedPass) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$url = self::getTorrentUrl($siteName, $_url);
|
||||
}
|
||||
// 检查switch内是否异常
|
||||
if ($reseedPass) {
|
||||
continue;
|
||||
}
|
||||
// 把拼接的种子URL,推送给下载器
|
||||
|
||||
// 把种子URL,推送给下载器
|
||||
echo '推送种子:' . $_url . PHP_EOL;
|
||||
$ret = false;
|
||||
// 成功返回:true
|
||||
// 成功true | 失败false
|
||||
$ret = self::add($k, $url, $downloadDir);
|
||||
|
||||
// 按站点规范日志内容
|
||||
switch ($siteName) {
|
||||
case 'hdchina':
|
||||
case 'hdsky':
|
||||
$url = $details_url;
|
||||
break;
|
||||
case 'hdcity':
|
||||
$url = $_url;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$log = 'clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL.$url.PHP_EOL.PHP_EOL;
|
||||
// 规范日志内容
|
||||
$log = 'clients_'. $k . PHP_EOL . $downloadDir . PHP_EOL . $_url . PHP_EOL.PHP_EOL;
|
||||
if ($ret) {
|
||||
// 成功的种子
|
||||
// 操作流控参数
|
||||
@ -635,6 +536,44 @@ class AutoReseed
|
||||
}
|
||||
// 按客户端循环辅种 结束
|
||||
}
|
||||
/**
|
||||
* 请求NexusPHP详情页
|
||||
* @param $protocol string 协议
|
||||
* @param $torrent array 种子
|
||||
* @param $cookie string Cookie
|
||||
* @param $userAgent string UA
|
||||
* @return mixed|null
|
||||
*/
|
||||
private static function getNexusPHPdetailsPage($protocol, $torrent, $cookie, $userAgent)
|
||||
{
|
||||
$sid = $torrent['sid'];
|
||||
$torrent_id = $torrent['torrent_id'];
|
||||
|
||||
// 拼接详情页URL
|
||||
$details = str_replace('{}', $torrent_id, 'details.php?id={}&hit=1');
|
||||
$details_url = $protocol . self::$sites[$sid]['base_url'] . '/' .$details;
|
||||
print "种子详情页:".$details_url.PHP_EOL;
|
||||
$details_html = download($details_url, $cookie, $userAgent);
|
||||
// 删种检查
|
||||
if (strpos($details_html, '没有该ID的种子') != false) {
|
||||
echo '种子已被删除!'.PHP_EOL;
|
||||
self::sendNotify('404');
|
||||
return null;
|
||||
}
|
||||
return $details_html;
|
||||
}
|
||||
/**
|
||||
* 微信通知cookie失效,延时15秒提示
|
||||
* @param $siteName
|
||||
*/
|
||||
private static function cookieExpired($siteName)
|
||||
{
|
||||
global $configALL;
|
||||
$configALL[$siteName]['cookie'] = '';
|
||||
|
||||
ff($siteName. '站点,cookie已过期,请更新后重新辅种!');
|
||||
sleepIYUU(15, 'cookie已过期,请更新后重新辅种!已加入排除列表');
|
||||
}
|
||||
/**
|
||||
* IYUUAutoReseed做种客户端转移
|
||||
*/
|
||||
@ -755,6 +694,100 @@ class AutoReseed
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 辅种前置检查
|
||||
* @param $k int 客户端key
|
||||
* @param $torrent array 可辅的种子
|
||||
* @param $infohash_Dir array 当前客户端hash目录对应字典
|
||||
* @param $downloadDir string 可辅种子的资源目录
|
||||
* @param $_url string 种子临时连接
|
||||
* @return bool
|
||||
*/
|
||||
private static function reseedCheck($k, $torrent, $infohash_Dir, $downloadDir, $_url)
|
||||
{
|
||||
global $configALL;
|
||||
|
||||
$info_hash = $torrent['info_hash'];
|
||||
$sid = $torrent['sid'];
|
||||
$torrent_id = $torrent['torrent_id'];
|
||||
$siteName = self::$sites[$sid]['site'];
|
||||
|
||||
// 配置与passkey检测
|
||||
if (empty($configALL[$siteName]) || empty($configALL[$siteName]['passkey'])) {
|
||||
//echo '-------因当前' .$siteName. "站点未设置passkey,已跳过!!".PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
return false;
|
||||
} else {
|
||||
echo "clients_".$k."正在辅种... {$siteName}".PHP_EOL;
|
||||
}
|
||||
// cookie检测
|
||||
if (in_array($siteName, self::$cookieCheck) && empty($configALL[$siteName]['cookie'])) {
|
||||
echo '-------因当前' .$siteName. '站点未设置cookie,已跳过!!' .PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
return false;
|
||||
}
|
||||
// 流控检测
|
||||
if (isset($configALL[$siteName]['limit'])) {
|
||||
echo "-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL;
|
||||
// 流控日志
|
||||
if ($siteName == 'hdchina') {
|
||||
$details_page = str_replace('{}', $torrent_id, 'details.php?id={}&hit=1');
|
||||
$_url = 'https://' .self::$sites[$sid]['base_url']. '/' .$details_page;
|
||||
}
|
||||
wlog('clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL."-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL, 'reseedLimit');
|
||||
self::$wechatMsg['reseedSkip']++;
|
||||
return false;
|
||||
}
|
||||
// 重复做种检测
|
||||
if (isset($infohash_Dir[$info_hash])) {
|
||||
echo '-------与客户端现有种子重复:'.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedRepeat']++;
|
||||
return false;
|
||||
}
|
||||
// 历史添加检测
|
||||
if (is_file(self::$cacheHash . $info_hash.'.txt')) {
|
||||
echo '-------当前种子上次辅种已成功添加,已跳过! '.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedPass']++;
|
||||
return false;
|
||||
}
|
||||
// 检查站点是否可以辅种
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
// 操作站点流控的配置
|
||||
if (isset($configALL[$siteName]['limitRule']) && $configALL[$siteName]['limitRule']) {
|
||||
$limitRule = $configALL[$siteName]['limitRule'];
|
||||
if (isset($limitRule['count']) && isset($limitRule['sleep'])) {
|
||||
if ($limitRule['count'] <= 0) {
|
||||
echo '-------当前站点辅种数量已满足规则,保障账号安全已跳过:'.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedPass']++;
|
||||
return false;
|
||||
} else {
|
||||
// 异步间隔流控算法:各站独立、执行时间最优
|
||||
$lastTime = isset($limitRule['time']) ? $limitRule['time'] : 0; // 最近一次辅种成功的时间
|
||||
if ($lastTime) {
|
||||
$interval = time() - $lastTime; // 间隔时间
|
||||
if ($interval < $limitRule['sleep']) {
|
||||
$t = $limitRule['sleep'] - $interval + mt_rand(1, 5);
|
||||
do {
|
||||
echo microtime(true)." 为账号安全,辅种进程休眠 {$t} 秒后继续...".PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo '-------当前站点流控规则错误,缺少count或sleep参数!请重新配置!'.$_url.PHP_EOL.PHP_EOL;
|
||||
self::$wechatMsg['reseedPass']++;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 过滤已转移的种子hash
|
||||
*/
|
||||
|
@ -456,3 +456,12 @@ function isWin()
|
||||
{
|
||||
return (DIRECTORY_SEPARATOR == '\\') ? true : false;
|
||||
}
|
||||
|
||||
function sleepIYUU($t, $msg)
|
||||
{
|
||||
echo $msg . PHP_EOL;
|
||||
do {
|
||||
echo microtime(true).$msg.' '.$t.'秒后继续...'.PHP_EOL;
|
||||
sleep(1);
|
||||
} while (--$t > 0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user