mirror of
				https://gitee.com/ledc/IYUUAutoReseed
				synced 2025-10-31 08:49:48 +00:00 
			
		
		
		
	优化前置检查逻辑
This commit is contained in:
		| @@ -36,6 +36,11 @@ class AutoReseed | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public static $noReseed = []; |     public static $noReseed = []; | ||||||
|  |     /** | ||||||
|  | 	 * cookie检查 | ||||||
|  | 	 * @var array | ||||||
|  | 	 */ | ||||||
|  | 	public static $cookieCheck = ['hdchina','hdcity']; | ||||||
|     /** |     /** | ||||||
|      * 缓存路径 |      * 缓存路径 | ||||||
|      * @var string |      * @var string | ||||||
| @@ -131,8 +136,7 @@ class AutoReseed | |||||||
|                     self::$links[$k]['type'] = $v['type']; |                     self::$links[$k]['type'] = $v['type']; | ||||||
|                     self::$links[$k]['rpc'] = $client; |                     self::$links[$k]['rpc'] = $client; | ||||||
|                     $result = $client->status(); |                     $result = $client->status(); | ||||||
|  |                     print $v['type'].':'.$v['host']." Rpc连接 [{$result}] \n"; | ||||||
|                     print $v['type'].':'.$v['host']." Rpc连接 [{$result->result}] \n"; |  | ||||||
|                     // 检查是否转移种子的做种客户端? |                     // 检查是否转移种子的做种客户端? | ||||||
|                     if (isset($v['move']) && $v['move']) { |                     if (isset($v['move']) && $v['move']) { | ||||||
|                         self::$move = array($k,$v['type']); |                         self::$move = array($k,$v['type']); | ||||||
| @@ -288,9 +292,9 @@ class AutoReseed | |||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case 'qBittorrent':                     |                 case 'qBittorrent':                     | ||||||
|  |                     if ($is_url) { | ||||||
|                         $extra_options['paused'] = 'true'; |                         $extra_options['paused'] = 'true'; | ||||||
|                         $extra_options['autoTMM'] = 'false';	//关闭自动种子管理 |                         $extra_options['autoTMM'] = 'false';	//关闭自动种子管理 | ||||||
|                     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 { | ||||||
|                         $extra_options['name'] = 'torrents'; |                         $extra_options['name'] = 'torrents'; | ||||||
| @@ -351,7 +355,7 @@ class AutoReseed | |||||||
| 		// 爱语飞飞token | 		// 爱语飞飞token | ||||||
| 		$hashArray['sign'] = Oauth::getSign(); | 		$hashArray['sign'] = Oauth::getSign(); | ||||||
| 		$hashArray['version'] = self::VER; | 		$hashArray['version'] = self::VER; | ||||||
|         // 写日志 | 		// 写请求日志 | ||||||
| 		if (true) { | 		if (true) { | ||||||
| 			// 文件句柄 | 			// 文件句柄 | ||||||
| 			$resource = fopen(self::$cacheDir.'hashString.txt', "wb"); | 			$resource = fopen(self::$cacheDir.'hashString.txt', "wb"); | ||||||
| @@ -363,8 +367,8 @@ class AutoReseed | |||||||
| 		echo "正在提交辅种信息…… \n"; | 		echo "正在提交辅种信息…… \n"; | ||||||
| 		$res = $curl->post(self::$apiUrl . self::$endpoints['reseed'], $hashArray); | 		$res = $curl->post(self::$apiUrl . self::$endpoints['reseed'], $hashArray); | ||||||
| 		$resArray = json_decode($res->response, true); | 		$resArray = json_decode($res->response, true); | ||||||
|         // 写日志 | 		// 写返回日志 | ||||||
|         if (true) { | 		if(true){ | ||||||
| 			// 文件句柄 | 			// 文件句柄 | ||||||
| 			$resource = fopen(self::$cacheDir.'reseed.txt', "wb"); | 			$resource = fopen(self::$cacheDir.'reseed.txt', "wb"); | ||||||
| 			// 成功:返回写入字节数,失败返回false | 			// 成功:返回写入字节数,失败返回false | ||||||
| @@ -372,48 +376,79 @@ class AutoReseed | |||||||
| 			fclose($resource); | 			fclose($resource); | ||||||
| 		} | 		} | ||||||
| 		// 判断返回值 | 		// 判断返回值 | ||||||
|         if (isset($resArray['errmsg']) && ($resArray['errmsg'] == 'ok')) { | 		if ( isset($resArray['errmsg']) && ($resArray['errmsg'] == 'ok') ) { | ||||||
| 			echo "辅种信息提交成功!!! \n\n"; | 			echo "辅种信息提交成功!!! \n\n"; | ||||||
|         } else { | 		}else{ | ||||||
| 			$errmsg = isset($resArray['errmsg']) ? $resArray['errmsg'] : '远端服务器无响应,请稍后重试!'; | 			$errmsg = isset($resArray['errmsg']) ? $resArray['errmsg'] : '远端服务器无响应,请稍后重试!'; | ||||||
| 			echo '-----辅种失败,原因:' .$errmsg. " \n\n"; | 			echo '-----辅种失败,原因:' .$errmsg. " \n\n"; | ||||||
| 			exit(1); | 			exit(1); | ||||||
| 		} | 		} | ||||||
|         // 可辅种站点信息列表 | 		// 可辅种站点信息 | ||||||
| 		$sites = $resArray['sites']; | 		$sites = $resArray['sites']; | ||||||
|         self::$wechatMsg['sitesCount'] = count($sites); |  | ||||||
| 		#p($sites); | 		#p($sites); | ||||||
|  | 		// 支持站点数量 | ||||||
|  | 		self::$wechatMsg['sitesCount'] = count($sites); | ||||||
| 		// 按客户端循环辅种 开始 | 		// 按客户端循环辅种 开始 | ||||||
| 		foreach (self::$links as $k => $v) { | 		foreach (self::$links as $k => $v) { | ||||||
| 			$reseed = $infohash_Dir = array(); | 			$reseed = $infohash_Dir = array(); | ||||||
|             // info_hash 对应的下载目录 | 			// info_hash与下载目录对应表 | ||||||
| 			$infohash_Dir = self::$links[$k]['hash']; | 			$infohash_Dir = self::$links[$k]['hash']; | ||||||
|  | 			#p($infohash_Dir); | ||||||
| 			if (empty($resArray['clients_'.$k])) { | 			if (empty($resArray['clients_'.$k])) { | ||||||
| 				echo "clients_".$k."没有查询到可辅种数据 \n\n"; | 				echo "clients_".$k."没有查询到可辅种数据 \n\n"; | ||||||
| 				continue; | 				continue; | ||||||
| 			}			 | 			}			 | ||||||
|             #p($infohash_Dir); | 			// 当前客户端可辅种数据 | ||||||
|             // 当前客户端辅种数据 |  | ||||||
| 			$reseed = $resArray['clients_'.$k]; | 			$reseed = $resArray['clients_'.$k]; | ||||||
| 			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) { | ||||||
|  | 					$_url = $url = ''; | ||||||
|  | 					$download_page = $details_url = ''; | ||||||
| 					// 匹配的辅种数据累加 | 					// 匹配的辅种数据累加 | ||||||
| 					self::$wechatMsg['reseedCount']++; | 					self::$wechatMsg['reseedCount']++; | ||||||
| 					// 站点id | 					// 站点id | ||||||
| 					$sitesID = $value['sid'];					 | 					$sitesID = $value['sid'];					 | ||||||
|                     $url = $_url = ''; |  | ||||||
|                     $download_page = $details_url = ''; |  | ||||||
| 					// 页面规则 | 					// 页面规则 | ||||||
| 					$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'])) { | 					/** | ||||||
|                         echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置passkey,已跳过!!' . "\n\n"; | 					 * 前置检测 | ||||||
|  | 					 */ | ||||||
|  | 					// passkey检测 | ||||||
|  | 					if ( empty($configALL[$sites[$sitesID]['site']]['passkey']) ) { | ||||||
|  | 						echo '-------因当前' .$sites[$sitesID]['site']. "站点未设置passkey,已跳过!! \n\n"; | ||||||
| 						self::$wechatMsg['reseedSkip']++; | 						self::$wechatMsg['reseedSkip']++; | ||||||
| 						continue; | 						continue; | ||||||
| 					} | 					} | ||||||
|                     // 种子URL组合方式区分 | 					// cookie检测 | ||||||
|  | 					if ( in_array($sites[$sitesID]['site'], self::$cookieCheck) && empty($configALL[$sites[$sitesID]['site']]['cookie']) ) { | ||||||
|  | 						echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置cookie,已跳过!!' . "\n\n"; | ||||||
|  | 						self::$wechatMsg['reseedSkip']++; | ||||||
|  | 						continue; | ||||||
|  | 					} | ||||||
|  | 					// 流控检测 | ||||||
|  | 					if ( isset($configALL[$sites[$sitesID]['site']]['limit']) ) { | ||||||
|  | 						echo "-------因当前" .$sites[$sitesID]['site']. "站点触发流控,已跳过!! {$_url} \n\n"; | ||||||
|  | 						self::$wechatMsg['reseedSkip']++; | ||||||
|  | 						continue; | ||||||
|  | 					} | ||||||
|  | 					// 重复做种检测 | ||||||
|  | 					if ( isset($infohash_Dir[$value['info_hash']]) ) { | ||||||
|  | 						echo '-------与客户端现有种子重复:'.$_url."\n\n"; | ||||||
|  | 						self::$wechatMsg['reseedRepeat']++; | ||||||
|  | 						continue; | ||||||
|  | 					} | ||||||
|  | 					// 历史添加检测 | ||||||
|  | 					if ( is_file(self::$cacheHash . $value['info_hash'].'.txt') ) { | ||||||
|  | 						echo '-------当前种子上次辅种已成功添加,已跳过! '.$_url."\n\n"; | ||||||
|  | 						self::$wechatMsg['reseedPass']++; | ||||||
|  | 						continue; | ||||||
|  | 					} | ||||||
|  | 					/** | ||||||
|  | 					 * 种子URL组合方式区分 | ||||||
|  | 					 */ | ||||||
| 					switch ($sites[$sitesID]['site']) { | 					switch ($sites[$sitesID]['site']) { | ||||||
| 						case 'ttg': | 						case 'ttg': | ||||||
| 							$url = $_url."/". $configALL[$sites[$sitesID]['site']]['passkey']; | 							$url = $_url."/". $configALL[$sites[$sitesID]['site']]['passkey']; | ||||||
| @@ -441,33 +476,13 @@ class AutoReseed | |||||||
| 					 */ | 					 */ | ||||||
| 					// 判断是否具有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']])) { | 						// 特殊站点:推送给下载器种子元数据 | ||||||
|                             // 与客户端现有种子重复 |  | ||||||
|                             echo '-------与客户端现有种子重复:'.$_url."\n\n"; |  | ||||||
|                             self::$wechatMsg['reseedRepeat']++; |  | ||||||
|                             continue; |  | ||||||
|                         } else { |  | ||||||
|                             // 判断上次是否成功添加? |  | ||||||
|                             if (is_file(self::$cacheHash . $value['info_hash'].'.txt')) { |  | ||||||
|                                 echo '-------当前种子上次辅种已成功添加,已跳过!'.$_url."\n\n"; |  | ||||||
|                                 self::$wechatMsg['reseedPass']++; |  | ||||||
|                                 continue; |  | ||||||
|                             } |  | ||||||
|                             // 种子元数据获取 |  | ||||||
| 						switch ($sites[$sitesID]['site']) { | 						switch ($sites[$sitesID]['site']) { | ||||||
| 							case 'hdchina': | 							case 'hdchina': | ||||||
|                                     if (empty($configALL[$sites[$sitesID]['site']]['cookie'])) { |  | ||||||
|                                         echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置cookie,已跳过!!' . "\n\n"; |  | ||||||
|                                         self::$wechatMsg['reseedSkip']++; |  | ||||||
|                                         break; |  | ||||||
|                                     } |  | ||||||
|                                     if (isset($configALL[$sites[$sitesID]['site']]['limit'])) { |  | ||||||
|                                         echo "当前站点触发人机验证,已加入排除列表 \n"; |  | ||||||
|                                     } |  | ||||||
| 								$cookie = isset($configALL[$sites[$sitesID]['site']]['cookie']) ? $configALL[$sites[$sitesID]['site']]['cookie'] : ''; | 								$cookie = isset($configALL[$sites[$sitesID]['site']]['cookie']) ? $configALL[$sites[$sitesID]['site']]['cookie'] : ''; | ||||||
| 								$userAgent = $configALL['default']['userAgent']; | 								$userAgent = $configALL['default']['userAgent']; | ||||||
| 								// 拼接URL | 								// 拼接URL | ||||||
| @@ -480,43 +495,39 @@ class AutoReseed | |||||||
| 								$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,'">')); | ||||||
| 								$_url = 'https://' .$sites[$sitesID]['base_url']. '/' . $_url; | 								$_url = 'https://' .$sites[$sitesID]['base_url']. '/' . $_url; | ||||||
| 								print "种子下载页:".$_url. "\n"; | 								print "种子下载页:".$_url. "\n"; | ||||||
| 								$url = download($_url, $cookie, $userAgent); | 								$url = download($_url, $cookie, $userAgent); | ||||||
|                                     if (strpos($url, '系统检测到过多的种子下载请求') != false) { | 								if(strpos($url,'系统检测到过多的种子下载请求') != false){ | ||||||
|                                         echo "触发人机验证 \n"; | 									echo "当前站点触发人机验证,已加入排除列表 \n"; | ||||||
| 									ff($sites[$sitesID]['site']. ' 触发人机验证,请重新设置!'); | 									ff($sites[$sitesID]['site']. ' 触发人机验证,请重新设置!'); | ||||||
|                                         self::$noReseed[] = 'hdchina'; |  | ||||||
| 									$configALL[$sites[$sitesID]['site']]['limit'] = 1; | 									$configALL[$sites[$sitesID]['site']]['limit'] = 1; | ||||||
|  | 									self::$noReseed[] = 'hdchina'; | ||||||
| 								} | 								} | ||||||
| 								break; | 								break; | ||||||
| 							case 'hdcity': | 							case 'hdcity': | ||||||
|                                     if (empty($configALL[$sites[$sitesID]['site']]['cookie'])) { |  | ||||||
|                                         echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置cookie,已跳过!!' . "\n\n"; |  | ||||||
|                                         self::$wechatMsg['reseedSkip']++; |  | ||||||
|                                         break; |  | ||||||
|                                     } |  | ||||||
| 								$cookie = isset($configALL[$sites[$sitesID]['site']]['cookie']) ? $configALL[$sites[$sitesID]['site']]['cookie'] : ''; | 								$cookie = isset($configALL[$sites[$sitesID]['site']]['cookie']) ? $configALL[$sites[$sitesID]['site']]['cookie'] : ''; | ||||||
| 								$userAgent = $configALL['default']['userAgent']; | 								$userAgent = $configALL['default']['userAgent']; | ||||||
| 								print "种子:".$_url. "\n"; | 								print "种子:".$_url. "\n"; | ||||||
|                                     if (isset($configALL[$sites[$sitesID]['site']]['cuhash'])) { | 								if ( isset($configALL[$sites[$sitesID]['site']]['cuhash']) ) { | ||||||
| 									// 已获取cuhash | 									// 已获取cuhash | ||||||
| 									# code... | 									# code... | ||||||
|                                     } else { | 								}else { | ||||||
| 									// 获取cuhash | 									// 获取cuhash | ||||||
| 									$html = download('https://' .$sites[$sitesID]['base_url']. '/pt', $cookie, $userAgent); | 									$html = download('https://' .$sites[$sitesID]['base_url']. '/pt', $cookie, $userAgent); | ||||||
| 									// 提取种子下载地址 | 									// 提取种子下载地址 | ||||||
|                                         $offset = strpos($html, 'cuhash='); | 									$offset = strpos($html,'cuhash='); | ||||||
| 									$len = strlen('cuhash='); | 									$len = strlen('cuhash='); | ||||||
|                                         $cuhashTemp = substr($html, $offset+$len, 40); | 									$cuhashTemp = substr($html,$offset+$len,40); | ||||||
|                                         $configALL[$sites[$sitesID]['site']]['cuhash'] = substr($cuhashTemp, 0, strpos($cuhashTemp, '"')); | 									$configALL[$sites[$sitesID]['site']]['cuhash'] = substr($cuhashTemp,0,strpos($cuhashTemp,'"')); | ||||||
| 								} | 								} | ||||||
| 								$url = $_url."&cuhash=". $configALL[$sites[$sitesID]['site']]['cuhash']; | 								$url = $_url."&cuhash=". $configALL[$sites[$sitesID]['site']]['cuhash']; | ||||||
| 								// 城市下载种子时会302转向 | 								// 城市下载种子时会302转向 | ||||||
| 								$url = download($url, $cookie, $userAgent); | 								$url = download($url, $cookie, $userAgent); | ||||||
| 								break; | 								break; | ||||||
| 							default: | 							default: | ||||||
|  | 								// 默认站点:推送给下载器种子URL链接 | ||||||
| 								break; | 								break; | ||||||
| 						} | 						} | ||||||
| 						// 把拼接的种子URL,推送给下载器 | 						// 把拼接的种子URL,推送给下载器 | ||||||
| @@ -533,12 +544,11 @@ class AutoReseed | |||||||
| 							fclose($resource); | 							fclose($resource); | ||||||
| 							self::$wechatMsg['reseedSuccess']++; | 							self::$wechatMsg['reseedSuccess']++; | ||||||
| 							continue; | 							continue; | ||||||
|                             } else { | 						}else{ | ||||||
| 							// 失败的种子 | 							// 失败的种子 | ||||||
|                                 // 站点类型判断 | 							// 不同站点的错误提示 | ||||||
| 							switch ($sites[$sitesID]['site']) { | 							switch ($sites[$sitesID]['site']) { | ||||||
| 								case 'hdcity': | 								case 'hdcity': | ||||||
|                                         echo '当前' .$sites[$sitesID]['site']. '站点是配置cuhash(不是passkey),添加成功说明配置正确!如果添加任务失败,请查阅常见问题!!' . "\n"; |  | ||||||
| 									break; | 									break; | ||||||
| 								default: | 								default: | ||||||
| 									break; | 									break; | ||||||
| @@ -547,14 +557,13 @@ class AutoReseed | |||||||
| 							self::$wechatMsg['reseedError']++; | 							self::$wechatMsg['reseedError']++; | ||||||
| 							continue; | 							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']]) ) { | ||||||
| 							// 站点类型判断 | 							// 站点类型判断 | ||||||
| 							switch ($sites[$sitesID]['site']) { | 							switch ($sites[$sitesID]['site']) { | ||||||
| 								case 'hdchina': | 								case 'hdchina': | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user