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 | ||||
|      */ | ||||
|     public static $noReseed = []; | ||||
|     /** | ||||
| 	 * cookie检查 | ||||
| 	 * @var array | ||||
| 	 */ | ||||
| 	public static $cookieCheck = ['hdchina','hdcity']; | ||||
|     /** | ||||
|      * 缓存路径 | ||||
|      * @var string | ||||
| @@ -131,8 +136,7 @@ class AutoReseed | ||||
|                     self::$links[$k]['type'] = $v['type']; | ||||
|                     self::$links[$k]['rpc'] = $client; | ||||
|                     $result = $client->status(); | ||||
|  | ||||
|                     print $v['type'].':'.$v['host']." Rpc连接 [{$result->result}] \n"; | ||||
|                     print $v['type'].':'.$v['host']." Rpc连接 [{$result}] \n"; | ||||
|                     // 检查是否转移种子的做种客户端? | ||||
|                     if (isset($v['move']) && $v['move']) { | ||||
|                         self::$move = array($k,$v['type']); | ||||
| @@ -288,9 +292,9 @@ class AutoReseed | ||||
|                     } | ||||
|                     break; | ||||
|                 case 'qBittorrent':                     | ||||
|                     if ($is_url) { | ||||
|                         $extra_options['paused'] = 'true'; | ||||
|                         $extra_options['autoTMM'] = 'false';	//关闭自动种子管理 | ||||
|                     if ($is_url) { | ||||
|                         $result = self::$links[$rpcKey]['rpc']->add($torrent, $save_path, $extra_options);			// 种子URL添加下载任务 | ||||
|                     } else { | ||||
|                         $extra_options['name'] = 'torrents'; | ||||
| @@ -351,7 +355,7 @@ class AutoReseed | ||||
| 		// 爱语飞飞token | ||||
| 		$hashArray['sign'] = Oauth::getSign(); | ||||
| 		$hashArray['version'] = self::VER; | ||||
|         // 写日志 | ||||
| 		// 写请求日志 | ||||
| 		if (true) { | ||||
| 			// 文件句柄 | ||||
| 			$resource = fopen(self::$cacheDir.'hashString.txt', "wb"); | ||||
| @@ -363,7 +367,7 @@ class AutoReseed | ||||
| 		echo "正在提交辅种信息…… \n"; | ||||
| 		$res = $curl->post(self::$apiUrl . self::$endpoints['reseed'], $hashArray); | ||||
| 		$resArray = json_decode($res->response, true); | ||||
|         // 写日志 | ||||
| 		// 写返回日志 | ||||
| 		if(true){ | ||||
| 			// 文件句柄 | ||||
| 			$resource = fopen(self::$cacheDir.'reseed.txt', "wb"); | ||||
| @@ -379,41 +383,72 @@ class AutoReseed | ||||
| 			echo '-----辅种失败,原因:' .$errmsg. " \n\n"; | ||||
| 			exit(1); | ||||
| 		} | ||||
|         // 可辅种站点信息列表 | ||||
| 		// 可辅种站点信息 | ||||
| 		$sites = $resArray['sites']; | ||||
|         self::$wechatMsg['sitesCount'] = count($sites); | ||||
| 		#p($sites); | ||||
| 		// 支持站点数量 | ||||
| 		self::$wechatMsg['sitesCount'] = count($sites); | ||||
| 		// 按客户端循环辅种 开始 | ||||
| 		foreach (self::$links as $k => $v) { | ||||
| 			$reseed = $infohash_Dir = array(); | ||||
|             // info_hash 对应的下载目录 | ||||
| 			// info_hash与下载目录对应表 | ||||
| 			$infohash_Dir = self::$links[$k]['hash']; | ||||
| 			#p($infohash_Dir); | ||||
| 			if (empty($resArray['clients_'.$k])) { | ||||
| 				echo "clients_".$k."没有查询到可辅种数据 \n\n"; | ||||
| 				continue; | ||||
| 			}			 | ||||
|             #p($infohash_Dir); | ||||
|             // 当前客户端辅种数据 | ||||
| 			// 当前客户端可辅种数据 | ||||
| 			$reseed = $resArray['clients_'.$k]; | ||||
| 			foreach ($reseed as $info_hash => $vv) { | ||||
| 				// 当前种子哈希对应的目录 | ||||
| 				$downloadDir = $infohash_Dir[$info_hash]; | ||||
| 				foreach ($vv['torrent'] as $id => $value) { | ||||
| 					$_url = $url = ''; | ||||
| 					$download_page = $details_url = ''; | ||||
| 					// 匹配的辅种数据累加 | ||||
| 					self::$wechatMsg['reseedCount']++; | ||||
| 					// 站点id | ||||
| 					$sitesID = $value['sid'];					 | ||||
|                     $url = $_url = ''; | ||||
|                     $download_page = $details_url = ''; | ||||
| 					// 页面规则 | ||||
| 					$download_page = str_replace('{}', $value['torrent_id'], $sites[$sitesID]['download_page']); | ||||
| 					$_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$download_page; | ||||
| 					/** | ||||
| 					 * 前置检测 | ||||
| 					 */ | ||||
| 					// passkey检测 | ||||
| 					if ( empty($configALL[$sites[$sitesID]['site']]['passkey']) ) { | ||||
|                         echo '-------因当前' .$sites[$sitesID]['site']. '站点未设置passkey,已跳过!!' . "\n\n"; | ||||
| 						echo '-------因当前' .$sites[$sitesID]['site']. "站点未设置passkey,已跳过!! \n\n"; | ||||
| 						self::$wechatMsg['reseedSkip']++; | ||||
| 						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']) { | ||||
| 						case 'ttg': | ||||
| 							$url = $_url."/". $configALL[$sites[$sitesID]['site']]['passkey']; | ||||
| @@ -445,29 +480,9 @@ class AutoReseed | ||||
| 						/** | ||||
| 						 *  可以辅种 | ||||
| 						 */ | ||||
|                         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']) { | ||||
| 							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'] : ''; | ||||
| 								$userAgent = $configALL['default']['userAgent']; | ||||
| 								// 拼接URL | ||||
| @@ -485,18 +500,13 @@ class AutoReseed | ||||
| 								print "种子下载页:".$_url. "\n"; | ||||
| 								$url = download($_url, $cookie, $userAgent); | ||||
| 								if(strpos($url,'系统检测到过多的种子下载请求') != false){ | ||||
|                                         echo "触发人机验证 \n"; | ||||
| 									echo "当前站点触发人机验证,已加入排除列表 \n"; | ||||
| 									ff($sites[$sitesID]['site']. ' 触发人机验证,请重新设置!'); | ||||
|                                         self::$noReseed[] = 'hdchina'; | ||||
| 									$configALL[$sites[$sitesID]['site']]['limit'] = 1; | ||||
| 									self::$noReseed[] = 'hdchina'; | ||||
| 								} | ||||
| 								break; | ||||
| 							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'] : ''; | ||||
| 								$userAgent = $configALL['default']['userAgent']; | ||||
| 								print "种子:".$_url. "\n"; | ||||
| @@ -517,6 +527,7 @@ class AutoReseed | ||||
| 								$url = download($url, $cookie, $userAgent); | ||||
| 								break; | ||||
| 							default: | ||||
| 								// 默认站点:推送给下载器种子URL链接 | ||||
| 								break; | ||||
| 						} | ||||
| 						// 把拼接的种子URL,推送给下载器 | ||||
| @@ -535,10 +546,9 @@ class AutoReseed | ||||
| 							continue; | ||||
| 						}else{ | ||||
| 							// 失败的种子 | ||||
|                                 // 站点类型判断 | ||||
| 							// 不同站点的错误提示 | ||||
| 							switch ($sites[$sitesID]['site']) { | ||||
| 								case 'hdcity': | ||||
|                                         echo '当前' .$sites[$sitesID]['site']. '站点是配置cuhash(不是passkey),添加成功说明配置正确!如果添加任务失败,请查阅常见问题!!' . "\n"; | ||||
| 									break; | ||||
| 								default: | ||||
| 									break; | ||||
| @@ -547,7 +557,6 @@ class AutoReseed | ||||
| 							self::$wechatMsg['reseedError']++; | ||||
| 							continue; | ||||
| 						} | ||||
|                         } | ||||
| 					}else{ | ||||
| 						/** | ||||
| 						 *  不辅种 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user