diff --git a/app/AutoReseed.php b/app/AutoReseed.php index 808ed2f..5faa8bc 100644 --- a/app/AutoReseed.php +++ b/app/AutoReseed.php @@ -11,7 +11,7 @@ use IYUU\Library\Table; class AutoReseed { // 版本号 - const VER = '1.9.0'; + const VER = '1.9.1'; // RPC连接 private static $links = []; // 客户端配置 @@ -106,7 +106,7 @@ class AutoReseed foreach ($list as $value) { echo $value.PHP_EOL; } - $res = self::$curl->get(self::$apiUrl.self::$endpoints['sites'].'?sign='.Oauth::getSign()); + $res = self::$curl->get(self::$apiUrl.self::$endpoints['sites'].'?sign='.Oauth::getSign().'&version='.self::VER); $rs = json_decode($res->response, true); $sites = isset($rs['data']['sites']) && $rs['data']['sites'] ? $rs['data']['sites'] : false; // 数据写入本地 @@ -336,8 +336,6 @@ class AutoReseed // 当前种子哈希对应的目录 $downloadDir = $infohash_Dir[$info_hash]; foreach ($vv['torrent'] as $id => $value) { - $_url = $url = ''; - $download_page = $details_url = ''; // 匹配的辅种数据累加 self::$wechatMsg['reseedCount']++; // 站点id @@ -355,13 +353,15 @@ class AutoReseed self::setNotify($siteName, $sid, $torrent_id); // 页面规则 $download_page = str_replace('{}', $torrent_id, $sites[$sid]['download_page']); - $_url = 'https://' .$sites[$sid]['base_url']. '/' .$download_page; + // 协议 + $protocol = $sites[$sid]['is_https'] == 0 ? 'http://' : 'https://'; + $_url = $protocol . $sites[$sid]['base_url']. '/' .$download_page; /** * 前置检测 */ - // passkey检测 - if (empty($configALL[$siteName]['passkey'])) { + // 配置与passkey检测 + if (empty($configALL[$siteName]) || empty($configALL[$siteName]['passkey'])) { //echo '-------因当前' .$siteName. "站点未设置passkey,已跳过!!".PHP_EOL.PHP_EOL; self::$wechatMsg['reseedSkip']++; continue; @@ -406,6 +406,34 @@ class AutoReseed 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组合方式区分 */ @@ -418,7 +446,7 @@ class AutoReseed $userAgent = $configALL['default']['userAgent']; // 拼接URL $details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1'); - $details_url = 'https://' .$sites[$sid]['base_url']. '/' .$details_page; + $details_url = $protocol .$sites[$sid]['base_url']. '/' .$details_page; print "种子详情页:".$details_url.PHP_EOL; $details_html = download($details_url, $cookie, $userAgent); if (empty($details_html)) { @@ -439,8 +467,7 @@ class AutoReseed break; } // 提取种子下载地址 - $download_page = str_replace('{}', '', $sites[$sid]['download_page']); - $offset = strpos($details_html, $download_page); + $offset = strpos($details_html, str_replace('{hash}', '', $sites[$sid]['download_page'])); if ($offset === false) { echo 'cookie已过期,请更新后重新辅种!'.PHP_EOL; $reseedPass = true; @@ -448,13 +475,13 @@ class AutoReseed } $urlTemp = substr($details_html, $offset, 50); // 种子地址 - $hash = substr($urlTemp, 0, strpos($urlTemp, '">')); - if (empty($hash)) { + $download_page = substr($urlTemp, 0, strpos($urlTemp, '">')); + if (empty($download_page)) { echo '未知错误,未提取到种子URL,请联系脚本作者!'.PHP_EOL; $reseedPass = true; break; } - $_url = 'https://' .$sites[$sid]['base_url']. '/' . $hash; + $_url = $protocol . $sites[$sid]['base_url']. '/' . $download_page; print "种子下载页:".$_url.PHP_EOL; $url = download($_url, $cookie, $userAgent); #p($url); @@ -487,14 +514,14 @@ class AutoReseed # code... } else { // 获取cuhash - $html = download('https://' .$sites[$sid]['base_url']. '/pt', $cookie, $userAgent); + $html = download($protocol .$sites[$sid]['base_url']. '/pt', $cookie, $userAgent); // 提取种子下载地址 $offset = strpos($html, 'cuhash='); $len = strlen('cuhash='); $cuhashTemp = substr($html, $offset+$len, 40); $configALL[$siteName]['cuhash'] = substr($cuhashTemp, 0, strpos($cuhashTemp, '"')); } - $url = $_url."&cuhash=". $configALL[$siteName]['cuhash']; + $url = str_replace('{cuhash}', $configALL[$siteName]['cuhash'], $_url); // 城市下载种子时会302转向 $url = download($url, $cookie, $userAgent); if (strpos($url, 'Non-exist torrent id!') != false) { @@ -533,6 +560,14 @@ class AutoReseed $log = 'clients_'.$k.PHP_EOL.$downloadDir.PHP_EOL.$url.PHP_EOL.PHP_EOL; if ($ret) { // 成功的种子 + // 操作流控参数 + if (isset($configALL[$siteName]['limitRule']) && $configALL[$siteName]['limitRule']) { + $limitRule = $configALL[$siteName]['limitRule']; + if ($limitRule['count']) { + $configALL[$siteName]['limitRule']['count']--; + $configALL[$siteName]['limitRule']['time'] = time(); + } + } wlog($log, $value['info_hash'], self::$cacheHash); wlog($log, 'reseedSuccess'); // 成功累加 @@ -773,36 +808,38 @@ class AutoReseed } return false; } + /** * 获取站点种子的URL + * @param string $site + * @param string $_url + * @return string */ private static function getTorrentUrl($site = '', $_url = '') { global $configALL; - switch ($site) { - case 'ttg': - $url = $_url."/". $configALL[$site]['passkey']; - break; - case 'm-team': - case 'moecat': - case 'hdbd': - $ip_type = ''; - if (isset($configALL[$site]['ip_type'])) { - $ip_type = $configALL[$site]['ip_type'] == 'ipv6' ? '&ipv6=1' : ''; - } - $url = $_url."&passkey=". $configALL[$site]['passkey'] . $ip_type. "&https=1"; - break; - case 'dicmusic': - $_url = str_replace('{torrent_pass}', $configALL[$site]['passkey'], $_url); - $url = str_replace('{authkey}', $configALL[$site]['authkey'], $_url); - break; - default: - if (strpos($_url,'{passkey}') !== false) { - $url = str_replace('{passkey}', $configALL[$site]['passkey'], $_url); - } else { - $url = $_url."&passkey=". $configALL[$site]['passkey']; + // 兼容旧配置 + if (isset($configALL[$site]['passkey']) && $configALL[$site]['passkey']) { + if (!isset($configALL[$site]['url_replace'])) { + $configALL[$site]['url_replace'] = array('{passkey}' => $configALL[$site]['passkey']); + } + if (!isset($configALL[$site]['url_join'])) { + $configALL[$site]['url_join'] = array(); + if (in_array($site, array('m-team','mocat','hdbd'))) { + if (isset($configALL[$site]['ip_type'])) { + $configALL[$site]['url_join'][] = $configALL[$site]['ip_type'].'=1'; + } + $configALL[$site]['url_join'][] = 'https=1'; } - break; + } + } + // 通用操作:替换 + if (isset($configALL[$site]['url_replace']) && $configALL[$site]['url_replace']) { + $url = strtr($_url, $configALL[$site]['url_replace']); + } + // 通用操作:拼接 + if (isset($configALL[$site]['url_join']) && $configALL[$site]['url_join']) { + $url = $url.(strpos($url, '?') === false ? '?' : '&').implode('&',$configALL[$site]['url_join']); } return $url; } diff --git a/config/config.sample.php b/config/config.sample.php index 759724b..aa1b757 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -111,6 +111,11 @@ return array( 'max' => '280GB', ), ), + 'url_replace' => array(), + 'url_join' => array( + //'ipv6=1', // 种子Tracker的IP地址选择 可选:ipv4,ipv6 + //'https=1', + ), ), // hddolby 'hddolby' => array( @@ -119,6 +124,8 @@ return array( // 如果需要自动辅种,必须配置 'passkey' => '', 'id' => 0, // 用户ID(不是用户名) + 'url_replace' => array(), + 'url_join' => array(), ), // hdhome 'hdhome' => array( @@ -127,6 +134,8 @@ return array( // 如果需要自动辅种,必须配置 'passkey' => '', 'id' => 0, // 用户ID(不是用户名) + 'url_replace' => array(), + 'url_join' => array(), ), // PTHome 'pthome' => array( @@ -135,6 +144,8 @@ return array( // 如果需要自动辅种,必须配置 'passkey' => '', 'id' => 0, // 用户ID(不是用户名) + 'url_replace' => array(), + 'url_join' => array(), ), // MoeCat 'moecat' => array( @@ -143,8 +154,11 @@ return array( // 如果需要自动辅种,必须配置 'passkey' => '', 'id' => 0, // 用户ID(不是用户名) - // 种子Tracker的IP地址选择 可选:ipv4,ipv6 - 'ip_type' => 'ipv4', + 'url_replace' => array(), + 'url_join' => array( + //'ipv6=1', // 种子Tracker的IP地址选择 可选:ipv4,ipv6 + //'https=1', + ), ), // m-team 'm-team' => array( @@ -152,8 +166,11 @@ return array( 'cookie' => 'tp=', // 15.m-team的passkey 【必须配置】 'passkey' => '', - // 种子Tracker的IP地址选择 可选:ipv4,ipv6 - 'ip_type' => 'ipv4', + 'url_replace' => array(), + 'url_join' => array( + //'ipv6=1', // 种子Tracker的IP地址选择 可选:ipv4,ipv6 + 'https=1', + ), 'clients' => array( array( 'type' => 'transmission', // 支持:transmission、qBittorrent @@ -178,6 +195,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), 'workingMode' => 1, 'watch' => '', 'filter' => array( @@ -193,6 +212,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // tjupt 'tjupt' => array( @@ -200,6 +221,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // btschool 'btschool' => array( @@ -207,6 +230,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // HDSky 'hdsky' => array( @@ -214,6 +239,12 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'limitRule' => array( + 'count' => 50, // 每次辅种50个 + 'sleep' => 15, // 最少休眠15秒 + ), + 'url_replace' => array(), + 'url_join' => array(), ), // TorrentCCF 'torrentccf' => array( @@ -221,6 +252,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // PTMSG 'ptmsg' => array( @@ -228,6 +261,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // totheglory 'ttg' => array( @@ -236,6 +271,8 @@ return array( // 如果需要自动辅种,必须配置 'passkey' => '', // 如果需要rss订阅,必须配置 + 'url_replace' => array(), + 'url_join' => array(), 'rss' => '', ), // nanyangpt @@ -244,6 +281,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // springsunday.net 'ssd' => array( @@ -251,6 +290,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // yingk 'yingk' => array( @@ -258,6 +299,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdcity 'hdcity' => array( @@ -265,6 +308,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置cuhash 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // 52pt.site '52pt' => array( @@ -272,6 +317,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // brobits 'brobits' => array( @@ -279,6 +326,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // beitai 'beitai' => array( @@ -286,6 +335,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // eastgame 'eastgame' => array( @@ -293,6 +344,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // soulvoice 'soulvoice' => array( @@ -300,6 +353,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // chdbits 'chdbits' => array( @@ -307,6 +362,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // leaguehd 'leaguehd' => array( @@ -314,6 +371,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // ptsbao 'ptsbao' => array( @@ -321,6 +380,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdchina 'hdchina' => array( @@ -328,6 +389,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdarea 'hdarea' => array( @@ -335,6 +398,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdtime 'hdtime' => array( @@ -342,6 +407,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // 1ptba '1ptba' => array( @@ -349,6 +416,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hd4fans 'hd4fans' => array( @@ -356,6 +425,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hddisk.life 'hdbug' => array( @@ -363,6 +434,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // opencd皇后 'opencd' => array( @@ -370,6 +443,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdstreet 'hdstreet' => array( @@ -377,6 +452,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // joyhd 'joyhd' => array( @@ -384,6 +461,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // dmhy幼儿园 'dmhy' => array( @@ -391,6 +470,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdu 'upxin' => array( @@ -398,6 +479,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // oshen 'oshen' => array( @@ -405,6 +488,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // discfan港知堂 'discfan' => array( @@ -412,6 +497,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdzone 'hdzone' => array( @@ -419,6 +506,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // nicept老师 'nicept' => array( @@ -426,6 +515,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdbd伊甸园 'hdbd' => array( @@ -433,6 +524,11 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array( + //'ipv6=1', // 种子Tracker的IP地址选择 可选:ipv4,ipv6 + //'https=1', + ), ), // byr北邮 'byr' => array( @@ -440,6 +536,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // CCFBits 'ccfbits' => array( @@ -447,6 +545,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdbits 'hdbits' => array( @@ -454,6 +554,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // PTPBD 'ptpbd' => array( @@ -461,6 +563,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // HD-T 'hd-torrents' => array( @@ -468,6 +572,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // skyeysnow天雪 'skyeysnow' => array( @@ -475,6 +581,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // pt.sjtu葡萄 'pt' => array( @@ -482,6 +590,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdroute 'hdroute' => array( @@ -489,6 +599,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // haidan 'haidan' => array( @@ -496,6 +608,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // hdfans 'hdfans' => array( @@ -503,6 +617,8 @@ return array( 'cookie' => '', // 如果需要自动辅种,必须配置 'passkey' => '', + 'url_replace' => array(), + 'url_join' => array(), ), // 配置结束,后面的一行不能删除,必须保留!!! );