新增种子删除上报功能!

master v1.1.0
iyuu.cn 5 years ago
parent 3abc02d660
commit da88f3e7fc
  1. 100
      app/AutoReseed.php
  2. 6
      readme.md

@ -15,17 +15,17 @@ class AutoReseed
// 版本号 // 版本号
const VER = '1.0.0'; const VER = '1.0.0';
// RPC连接 // RPC连接
public static $links = array(); private static $links = array();
// 客户端配置 // 客户端配置
public static $clients = array(); private static $clients = array();
// 站点列表 // 站点列表
public static $sites = array(); private static $sites = array();
// 不辅种的站点 'ourbits','hdchina' // 不辅种的站点 'ourbits','hdchina'
public static $noReseed = array(); private static $noReseed = array();
// 不转移的站点 'hdarea','hdbd' // 不转移的站点 'hdarea','hdbd'
public static $noMove = array('hdarea'); private static $noMove = array('hdarea');
// cookie检查 // cookie检查
public static $cookieCheck = array('hdchina','hdcity'); private static $cookieCheck = array('hdchina','hdcity');
// 缓存路径 // 缓存路径
public static $cacheDir = TORRENT_PATH.'cache'.DS; public static $cacheDir = TORRENT_PATH.'cache'.DS;
public static $cacheHash = TORRENT_PATH.'cachehash'.DS; public static $cacheHash = TORRENT_PATH.'cachehash'.DS;
@ -33,18 +33,19 @@ class AutoReseed
// API接口配置 // API接口配置
public static $apiUrl = 'http://api.iyuu.cn'; public static $apiUrl = 'http://api.iyuu.cn';
public static $endpoints = array( public static $endpoints = array(
'infohash'=> '/api/infohash',
'sites' => '/api/sites',
'login' => '/user/login', 'login' => '/user/login',
'sites' => '/api/sites',
'infohash'=> '/api/infohash',
'notify' => '/api/notify',
); );
// curl // curl
public static $curl = null; private static $curl = null;
// 退出状态码 // 退出状态码
public static $ExitCode = 0; public static $ExitCode = 0;
// 客户端转移做种 // 客户端转移做种
public static $move = null; private static $move = null;
// 微信消息体 // 微信消息体
public static $wechatMsg = array( private static $wechatMsg = array(
'hashCount' => 0, // 提交给服务器的hash总数 'hashCount' => 0, // 提交给服务器的hash总数
'sitesCount' => 0, // 可辅种站点总数 'sitesCount' => 0, // 可辅种站点总数
'reseedCount' => 0, // 返回的总数据 'reseedCount' => 0, // 返回的总数据
@ -54,6 +55,14 @@ class AutoReseed
'reseedSkip' => 0, // 跳过:因未设置passkey,而跳过 'reseedSkip' => 0, // 跳过:因未设置passkey,而跳过
'reseedPass' => 0, // 忽略:因上次成功添加、存在缓存,而跳过 'reseedPass' => 0, // 忽略:因上次成功添加、存在缓存,而跳过
); );
// 错误通知消息体
private static $errNotify = array(
'sign' => '',
'site' => '',
'sid' => 0,
'torrent_id'=> 0,
'error' => '',
);
// 初始化 // 初始化
public static function init() public static function init()
{ {
@ -193,6 +202,9 @@ class AutoReseed
return true; return true;
} else { } else {
$errmsg = isset($result['result']) ? $result['result'] : '未知错误,请稍后重试!'; $errmsg = isset($result['result']) ? $result['result'] : '未知错误,请稍后重试!';
if (strpos($errmsg, 'http error 404: Not Found') !== false) {
self::sendNotify('404');
}
print "-----RPC添加种子任务,失败 [{$errmsg}]" . PHP_EOL.PHP_EOL; print "-----RPC添加种子任务,失败 [{$errmsg}]" . PHP_EOL.PHP_EOL;
} }
break; break;
@ -298,12 +310,16 @@ class AutoReseed
// 匹配的辅种数据累加 // 匹配的辅种数据累加
self::$wechatMsg['reseedCount']++; self::$wechatMsg['reseedCount']++;
// 站点id // 站点id
$sitesID = $value['sid']; $sid = $value['sid'];
// 种子id
$torrent_id = $value['torrent_id'];
// 站点名 // 站点名
$siteName = $sites[$sitesID]['site']; $siteName = $sites[$sid]['site'];
// 错误通知
self::setNotify($siteName, $sid, $torrent_id);
// 页面规则 // 页面规则
$download_page = str_replace('{}', $value['torrent_id'], $sites[$sitesID]['download_page']); $download_page = str_replace('{}', $torrent_id, $sites[$sid]['download_page']);
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$download_page; $_url = 'https://' .$sites[$sid]['base_url']. '/' .$download_page;
echo "clients_".$k."正在辅种... {$siteName}".PHP_EOL; echo "clients_".$k."正在辅种... {$siteName}".PHP_EOL;
/** /**
* 前置检测 * 前置检测
@ -325,8 +341,8 @@ class AutoReseed
echo "-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL; echo "-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL;
// 流控日志 // 流控日志
if ($siteName == 'hdchina') { if ($siteName == 'hdchina') {
$details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1'); $details_page = str_replace('{}', $torrent_id, 'details.php?id={}&hit=1');
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$details_page; $_url = 'https://' .$sites[$sid]['base_url']. '/' .$details_page;
} }
wlog('clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL."-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL, 'reseedLimit'); wlog('clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL."-------因当前" .$siteName. "站点触发流控,已跳过!! {$_url}".PHP_EOL.PHP_EOL, 'reseedLimit');
self::$wechatMsg['reseedSkip']++; self::$wechatMsg['reseedSkip']++;
@ -364,7 +380,7 @@ class AutoReseed
$userAgent = $configALL['default']['userAgent']; $userAgent = $configALL['default']['userAgent'];
// 拼接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[$sid]['base_url']. '/' .$details_page;
print "种子详情页:".$details_url.PHP_EOL; print "种子详情页:".$details_url.PHP_EOL;
$details_html = download($details_url, $cookie, $userAgent); $details_html = download($details_url, $cookie, $userAgent);
if (empty($details_html)) { if (empty($details_html)) {
@ -380,13 +396,14 @@ class AutoReseed
break; break;
} }
if (strpos($details_html, '没有该ID的种子') != false) { if (strpos($details_html, '没有该ID的种子') != false) {
# code... 错误通知 echo '种子已被删除!'.PHP_EOL;
self::sendNotify('404');
// 标志:跳过辅种 // 标志:跳过辅种
$reseedPass = true; $reseedPass = true;
break; break;
} }
// 提取种子下载地址 // 提取种子下载地址
$download_page = str_replace('{}', '', $sites[$sitesID]['download_page']); $download_page = str_replace('{}', '', $sites[$sid]['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);
// 种子地址 // 种子地址
@ -397,7 +414,7 @@ class AutoReseed
$reseedPass = true; $reseedPass = true;
break; break;
} }
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' . $_url; $_url = 'https://' .$sites[$sid]['base_url']. '/' . $_url;
print "种子下载页:".$_url.PHP_EOL; print "种子下载页:".$_url.PHP_EOL;
$url = download($_url, $cookie, $userAgent); $url = download($_url, $cookie, $userAgent);
if (strpos($url, '第一次下载提示') != false) { if (strpos($url, '第一次下载提示') != false) {
@ -431,7 +448,7 @@ class AutoReseed
# code... # code...
} else { } else {
// 获取cuhash // 获取cuhash
$html = download('https://' .$sites[$sitesID]['base_url']. '/pt', $cookie, $userAgent); $html = download('https://' .$sites[$sid]['base_url']. '/pt', $cookie, $userAgent);
// 提取种子下载地址 // 提取种子下载地址
$offset = strpos($html, 'cuhash='); $offset = strpos($html, 'cuhash=');
$len = strlen('cuhash='); $len = strlen('cuhash=');
@ -441,6 +458,12 @@ class AutoReseed
$url = $_url."&cuhash=". $configALL[$siteName]['cuhash']; $url = $_url."&cuhash=". $configALL[$siteName]['cuhash'];
// 城市下载种子时会302转向 // 城市下载种子时会302转向
$url = download($url, $cookie, $userAgent); $url = download($url, $cookie, $userAgent);
if (strpos($url, 'Non-exist torrent id!') != false) {
echo '种子已被删除!'.PHP_EOL;
self::sendNotify('404');
// 标志:跳过辅种
$reseedPass = true;
}
break; break;
default: default:
// 默认站点:推送给下载器种子URL链接 // 默认站点:推送给下载器种子URL链接
@ -681,4 +704,37 @@ class AutoReseed
$desp .= '忽略:'.self::$wechatMsg['reseedPass']. ' [成功添加存在缓存]' .$br; $desp .= '忽略:'.self::$wechatMsg['reseedPass']. ' [成功添加存在缓存]' .$br;
return ff($text, $desp); return ff($text, $desp);
} }
/**
* 错误的种子通知服务器
*/
private static function sendNotify($error = '')
{
self::$errNotify['error'] = $error;
$notify = http_build_query(self::$errNotify);
self::$errNotify = array(
'sign' => '',
'site' => '',
'sid' => 0,
'torrent_id'=> 0,
'error' => '',
);
$res = self::$curl->get(self::$apiUrl.self::$endpoints['notify'].'?'.$notify);
$res = json_decode($res->response, true);
if (isset($res['data']['success']) && $res['data']['success']) {
echo '感谢您的参与,种子被删除,上报成功!!'.PHP_EOL;
}
return true;
}
/**
* 设置通知主体
*/
private static function setNotify($siteName = '', $sid = 0, $torrent_id = 0)
{
self::$errNotify = array(
'sign' => Oauth::getSign(),
'site' => $siteName,
'sid' => $sid,
'torrent_id'=> $torrent_id,
);
}
} }

@ -114,6 +114,12 @@ http://api.iyuu.cn/docs.php?type=expand
| 小城流水 | ¥5元 | 2020年1月22日22:14 | | 小城流水 | ¥5元 | 2020年1月22日22:14 |
| 国旗(未署名) | ¥8.8元 | 2020年1月22日23:28 | | 国旗(未署名) | ¥8.8元 | 2020年1月22日23:28 |
| 当下丶 | ¥100元 | 2020年1月28日1:45 | | 当下丶 | ¥100元 | 2020年1月28日1:45 |
| 陈君政 | ¥10元 | 2020年2月3日11:32 |
| 不寐夜游 | ¥10元 | 2020年2月8日17:17 |
| Jack | ¥10元 | 2020年2月13日08:05 |
| 陈伟平 | ¥28.88元 | 2020年2月13日12:35 |
| PhalApi Pro商业授权 | ¥-950元 | 2020年2月14日21:56 |
| jonnaszheng | ¥10元 | 2020年2月15日10:25 |
补充说明: 补充说明:

Loading…
Cancel
Save