From b543ddac59feb38043b8e0b4543d622b2622a787 Mon Sep 17 00:00:00 2001 From: Alone <675061370@qq.com> Date: Sat, 14 Sep 2024 17:10:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E7=A7=8B=E8=8A=82=E5=BF=AB=E4=B9=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 192 +------------------------------------------------ 1 file changed, 1 insertion(+), 191 deletions(-) diff --git a/app/common.php b/app/common.php index e857414..a1d1317 100644 --- a/app/common.php +++ b/app/common.php @@ -780,194 +780,4 @@ function determineIsType($url) { // 默认值是夸克网盘,返回 0 return 0; } -} - - -/** - * 网络资源搜索源一 - * @return array - */ - -function source1($title) -{ - $d = []; - - return $d; -} - -/** - * 网络资源搜索源二(5条线路) - * 每个线路只取第一个 - * @return array - */ -function source2($title) -{ - $urlDefault = "http://s.kkkob.com"; //http://s.kkkob.com - $url2 = []; - $res = curlHelper($urlDefault."/v/api/getToken", "GET")['body']; - $res = json_decode($res, true); - $token = $res['token'] ?? ''; - if(empty($token)){ - return $url2; - } - - $urlData = array( - 'name' => $title, - 'token' => $token - ); - $urlHeader = array('Content-Type: application/json'); - // 定义正则表达式模式 - $pattern = '/https:\/\/pan\.quark\.cn\/[^\s]*/'; - - //线路2 - $res = curlHelper($urlDefault."/v/api/getJuzi", "POST", json_encode($urlData), $urlHeader)['body']; - $res = json_decode($res, true); - if (!empty($res['list'] ?? [])) { - foreach ($res['list'] as $key => $value) { - if(preg_match($pattern, $value['answer'], $matches)){ - // 匹配成功,$matches[0] 包含了匹配到的链接 - $link = $matches[0]; - $url2[] = [ - 'title' => preg_replace('/\s*[\((]?(夸克)?[\))]?\s*/u', '', $value['question']), - 'url' => $link - ]; - break; - } - } - } - - if(!empty($url2)){ - return $url2; - } - - //线路4 - $res = curlHelper($urlDefault."/v/api/getXiaoyu", "POST", json_encode($urlData), $urlHeader)['body']; - $res = json_decode($res, true); - if (!empty($res['list'] ?? [])) { - foreach ($res['list'] as $key => $value) { - if(preg_match($pattern, $value['answer'], $matches)){ - // 匹配成功,$matches[0] 包含了匹配到的链接 - $link = $matches[0]; - $url2[] = [ - 'title' => preg_replace('/\s*[\((]?(夸克)?[\))]?\s*/u', '', $value['question']), - 'url' => $link - ]; - break; - } - } - } - - - // //线路1 - // $res = curlHelper($urlDefault."/v/api/search", "POST", json_encode($urlData), $urlHeader)['body']; - // $res = json_decode($res, true); - // if (!empty($res['list'] ?? [])) { - // $item = $res['list'][0]; - // // 使用正则表达式进行匹配 - // if (preg_match($pattern, $item['answer'], $matches)) { - // // 匹配成功,$matches[0] 包含了匹配到的链接 - // $link = $matches[0]; - // $url2[] = [ - // 'title' => '①'.preg_replace('/\s*[\((]?(夸克)?[\))]?\s*/u', '', $item['question']), - // 'url' => $link - // ]; - // } - // } - - return $url2; -} - - -/** - * 网络资源搜索源三 - * @return array - */ -function source3($title) -{ - $url3 = []; - $url = 'https://www.qileso.com/tag/quark?s='.$title; - $dom = getDom($url); - $finder = new DomXPath($dom); - // 查询class值为list-group post-list mt-3的元素 - $nodes =$finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' list-group post-list mt-3 ')]//a"); - - if ($nodes->length > 0) { - $firstNode =$nodes->item(0); - $href = $firstNode->getAttribute('href'); - - $dom = getDom($href); - $finder = new DomXPath($dom); - - // 查询包含特定前缀的href属性的所有标签 - $nodes =$finder->query("//@*[starts-with(., 'https://pan.quark.cn/s/')]"); - if ($nodes->length > 0) { - $firstNode =$nodes->item(0); - $value = $firstNode->value; - - // 查询元素 - $nodes =$finder->query("/html/head/title"); - - if ($nodes->length > 0) { - $titleNode =$nodes->item(0); - $titleText =$titleNode->textContent; - // 去掉 " - 奇乐搜" 部分 - $title = preg_replace('/ - 奇乐搜|网盘|夸克/', '', $titleText); - } - - $url3[] = [ - 'title' => '②'.$title, - 'url' => $value - ]; - } - } - - return $url3; -} - - -/** - * 网络资源搜索源四 - * @return array - */ -function source4($title) -{ - $url = 'https://www.pansearch.me/search?keyword='.urlencode($title).'&pan=quark'; - $dom = getDom($url); - $finder = new DomXPath($dom); - - // 使用 XPath 查询选择具有特定类名的元素 - $nodes =$finder->query('//div[contains(concat(" ", normalize-space(@class), " "), " whitespace-pre-wrap ") and contains(concat(" ", normalize-space(@class), " "), " break-all ")]'); - - $results = []; - foreach ($nodes as $node) { - // 获取元素的内容,包括其子元素 - $content = $node->textContent; - - // Initialize an associative array to store parsed data - $parsedItem = [ - 'title' => '', - 'url' => '' - ]; - - // Use regular expressions to extract the title and url - if (preg_match('/名称:(.*?)\n\n描述:/s', $content, $titleMatch)) { - $parsedItem['title'] = '「推荐」'.trim($titleMatch[1]); - } - - if (preg_match('/链接:(https:\/\/pan\.quark\.cn\/s\/[a-zA-Z0-9]+)/', $content, $urlMatch)) { - $parsedItem['url'] = trim($urlMatch[1]); - } - - if ($parsedItem['title'] && $parsedItem['url']) { - $results[] = $parsedItem; - } - - if (count($results) >= 3) { - break; - } - } - - return $results; -} - - +} \ No newline at end of file