This commit is contained in:
Default
2025-04-21 22:32:40 +08:00
parent 52236ab6f7
commit f21ece4de1
8 changed files with 204 additions and 80 deletions

View File

@@ -1,14 +1,18 @@
{site:forgelist count="3" d_key="d_key" d_val="novel" cache_life="1000"} {site:helper func="initHomeTKD" /}
<!-- {site:forgelist count="3" d_key="d_key" d_val="novel" cache_life="1000"}
<li> <li>
Index: {$d_key} Index: {$d_key}
Title: {$novel.n_forge_title} Title: {$novel.n_forge_title}
Author: {$novel.n_name_pinyin} Author: {$novel.n_name_pinyin}
</li> </li>
{/site:forgelist} {/site:forgelist} -->
<!-- {novel:ranklist count="10" sort_type="total" n_status="wanjie" n_sex="man" d_key="d_key" d_val="novel" cache_life="1000"} <!-- {novel:ranklist count="10" sort_type="total" n_status="wanjie" n_sex="man" d_key="d_key" d_val="novel" cache_life="1000"}
<li> <li>
{php}var_dump($novel){/php}
Index: {$d_key} Index: {$d_key}
Title: {$novel.n_name} Title: {$novel.n_name}
Author: {$novel.n_category} Author: {$novel.n_category}

View File

@@ -158,9 +158,9 @@ class SiteContext
* @param string $strDiff * @param string $strDiff
* @return string * @return string
*/ */
public function converterTemplate(string $strCode,string $strDiff="0"): string public function converterTemplate(string $strCode, string $strDiff = "0"): string
{ {
$strTitleTemplate = $this->DomainModel->getFomartSubject($strCode,$strDiff); $strTitleTemplate = $this->DomainModel->getFomartSubject($strCode, $strDiff);
return ConverterMovel::convert($strTitleTemplate); return ConverterMovel::convert($strTitleTemplate);
} }
@@ -262,4 +262,16 @@ class SiteContext
return $arrResult; return $arrResult;
} }
/**
* 视图反向控制器(注释函数),在视图开头调用,用来初始化一些操作。这里尽量不要复杂逻辑。这是个样例
*
* @return void
*/
public function initHomeTKD()
{
ConverterMovel::setVal([
'strSiteName' => $this->DomainModel->d_name,
]);
}
} }

View File

@@ -74,6 +74,26 @@ class Scheduler
*/ */
public function crawlFull() public function crawlFull()
{ {
$Site = $this->getSite();
$arrVSourceId = [];
$arrVSourceId[] = ['v_source_id' => 66281];
$arrAllVideoInfoPage = $Site->getVideoInfoPageList($arrVSourceId);
foreach ($arrAllVideoInfoPage as $VideoInfoPage) {
$arrVideo = $VideoInfoPage->getVideo();
print_r($arrVideo);
}
return;
$intLimit = 10; $intLimit = 10;
$Site = $this->getSite(); $Site = $this->getSite();
@@ -91,32 +111,37 @@ class Scheduler
]; ];
$arrVideoPageList = $Site->getVideoPageList($arrFilter); $arrVideoPageList = $Site->getVideoPageList($arrFilter);
$arrVideoPager = $arrVideoPageList[0]->getVideoPager();
foreach ($arrVideoPageList as $VideoPage) { $arrVSourceId = [];
$arrAllVideoPager = $VideoPage->getVideoPager();
$arrVSourceId = []; foreach ($arrVideoPager['list'] as $arrVideoPager) {
foreach ($arrAllVideoPager['list'] as $arrVideoPager) { $arrVSourceId[] = ['v_source_id' => (int)$arrVideoPager['vod_id']];
$arrVSourceId[] = ['v_source_id' => (int)$arrVideoPager['vod_id']];
}
$arrAllVideoInfoPage = $Site->getVideoInfoPageList($arrVSourceId);
foreach ($arrAllVideoInfoPage as $VideoInfoPage) {
$arrVideo = $VideoInfoPage->getVideo();
print_r($arrVideo);
}
} }
$arrAllVideoInfoPage = $Site->getVideoInfoPageList($arrVSourceId);
foreach ($arrAllVideoInfoPage as $VideoInfoPage) {
$arrVideo = $VideoInfoPage->getVideo();
print_r($arrVideo);
}
// foreach ($arrVideoPageList as $VideoPage) {
// $arrAllVideoPager = $VideoPage->getVideoPager();
// $arrVSourceId = [];
// foreach ($arrAllVideoPager['list'] as $arrVideoPager) {
// $arrVSourceId[] = ['v_source_id' => (int)$arrVideoPager['vod_id']];
// }
// $arrAllVideoInfoPage = $Site->getVideoInfoPageList($arrVSourceId);
// foreach ($arrAllVideoInfoPage as $VideoInfoPage) {
// $arrVideo = $VideoInfoPage->getVideo();
// print_r($arrVideo);
// }
// }
} }
} }
$arrCover = [];
if ($arrCover) {
// $Site->downRemoteImgToLocal($arrCover);
}
return; return;
} }
} }

View File

@@ -68,18 +68,8 @@ class Site
], ],
'headers' => [ 'headers' => [
'User-Agent' => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36', 'User-Agent' => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Referer' => $this->strDomain, 'Referer' => $this->strDomain,
'Connection' => 'keep-alive', 'Connection' => 'keep-alive',
'sec-ch-ua' => '"Not/A)Brand";v="8", "Chromium";v="130", "Google Chrome";v="130"',
'sec-ch-ua-mobile' => '?1',
'sec-ch-ua-platform' => '"Android"',
'sec-fetch-dest' => 'document',
'sec-fetch-mode' => 'navigate',
'sec-fetch-site' => 'same-origin',
'sec-fetch-user' => '?1',
'upgrade-insecure-requests' => '1',
], ],
'pool_size' => 20, 'pool_size' => 20,
'verify' => false, 'verify' => false,
@@ -261,7 +251,7 @@ class Site
*/ */
public function getVideoUri(int $intVSourceId): string public function getVideoUri(int $intVSourceId): string
{ {
return sprintf('/inc/api_mac10.php?ac=detail&tds=%s', $intVSourceId); return sprintf('/inc/api_mac10.php?ac=detail&ids=%s', $intVSourceId);
} }
/** /**
@@ -279,17 +269,12 @@ class Site
$arrPromises = []; $arrPromises = [];
foreach ($arrFilter as $intKey => $arrItem) { foreach ($arrFilter as $intKey => $arrItem) {
$arrFilter[$intKey]['uri'] = $this->getVideoUri($arrItem['v_source_id']); $arrFilter[$intKey]['uri'] = $this->getVideoUri($arrItem['v_source_id']);
$arrPromises[$intKey] = $arrFilter[$intKey]['uri'];
$arrPromises[$intKey] = $this->getClient()->getAsync($arrFilter[$intKey]['uri']);
} }
print_r($arrFilter);
$arrResults = Promise\Utils::settle($arrPromises)->wait(); $arrResults = Promise\Utils::settle($arrPromises)->wait();
var_dump($arrResults);
return [];
$arrSuccessfulResults = array_filter($arrResults, function ($arrResult) { $arrSuccessfulResults = array_filter($arrResults, function ($arrResult) {
return $arrResult['state'] === 'fulfilled'; return $arrResult['state'] === 'fulfilled';
}); });
@@ -297,8 +282,6 @@ class Site
foreach ($arrSuccessfulResults as $intKey => $arrResult) { foreach ($arrSuccessfulResults as $intKey => $arrResult) {
$Response = $arrResult['value']; $Response = $arrResult['value'];
var_dump($arrResult);
$strContent = $Response->getBody()->getContents();; $strContent = $Response->getBody()->getContents();;
$VideoInfoPage = $this->getVideoInfoPage($this, $arrFilter[$intKey]['uri']); $VideoInfoPage = $this->getVideoInfoPage($this, $arrFilter[$intKey]['uri']);

View File

@@ -44,7 +44,7 @@ class VideoInfoPage extends BasePage
], ],
]; ];
/** /**
* Undocumented function * Undocumented function
* *
* @return array * @return array
@@ -54,6 +54,16 @@ class VideoInfoPage extends BasePage
if (empty($this->arrVideo)) { if (empty($this->arrVideo)) {
$this->arrVideo = json_decode($this->getContent(), true); $this->arrVideo = json_decode($this->getContent(), true);
$this->arrVideo = $this->arrVideo['list'][0];
$this->arrVideo['vod_play_url'] = str_replace('#', '$', $this->arrVideo['vod_play_url']);
$this->arrVideo['vod_play_url'] = explode('$', $this->arrVideo['vod_play_url']);
$this->arrVideo['vod_play_url'] = array_chunk($this->arrVideo['vod_play_url'], 2);
foreach ($this->arrVideo['vod_play_url'] as $intKey => $arrVal) {
$this->arrVideo['vod_play_url'][$intKey] = [
'name' => $arrVal[0],
'url' => $arrVal[1],
];
}
} }
return $this->arrVideo; return $this->arrVideo;

View File

@@ -7,7 +7,7 @@ use think\template\TagLib;
class Novel extends TagLib class Novel extends TagLib
{ {
protected $tags = [ protected $tags = [
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val', 'close' => 1], 'list' => ['attr' => 'count,n_category,sort_type,n_status,n_sex,diff_key,cache_life,d_key,d_val', 'close' => 1],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 1], 'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 1],
'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0], 'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0],
'info' => ['attr' => 'n_id,n_key', 'close' => 0], 'info' => ['attr' => 'n_id,n_key', 'close' => 0],
@@ -15,6 +15,8 @@ class Novel extends TagLib
'status' => ['attr' => 'd_key,d_val'], 'status' => ['attr' => 'd_key,d_val'],
'sex' => ['attr' => 'd_key,d_val'], 'sex' => ['attr' => 'd_key,d_val'],
'category' => ['attr' => 'd_key,d_val,n_sex'], 'category' => ['attr' => 'd_key,d_val,n_sex'],
'ranklist' => ['attr' => 'count,sort_type,n_status,n_sex,diff_key,cache_life,d_key,d_val', 'close' => 1],
]; ];
private function customBuildVar($mixedArgs) private function customBuildVar($mixedArgs)
@@ -27,8 +29,67 @@ class Novel extends TagLib
} }
/** /**
* novel 自定义标签 * tagRankList
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagRankList($tag, $content)
{
$count = $tag['count'] ?? '10';
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "all";
$n_sex = $tag['n_sex'] ?? "all";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$sort_type = $this->customBuildVar($sort_type);
$n_status = $this->customBuildVar($n_status);
$n_sex = $this->customBuildVar($n_sex);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\${$arrDataName} = app(\\app\\services\\NovelService::class)->getRankList([
'count' => {$count},
'sort_type' => {$sort_type},
'n_status' => {$n_status},
'n_sex' => {$n_sex},
'diff_key' => {$diff_key},
'cache_life' => {$cache_life}
]);
if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* tagPagerExp
*
* @param array $tag
* @param string $content
* @return void
*/ */
public function tagPagerExp($tag, $content) public function tagPagerExp($tag, $content)
{ {
@@ -36,7 +97,11 @@ class Novel extends TagLib
} }
/** /**
* novel 自定义标签 * tagPager
*
* @param array $tag
* @param string $content
* @return void
*/ */
public function tagPager($tag, $content) public function tagPager($tag, $content)
{ {

View File

@@ -20,6 +20,7 @@ class Site extends TagLib
'replace' => ['attr' => 'code,diff', 'close' => 0], 'replace' => ['attr' => 'code,diff', 'close' => 0],
'forgelist' => ['attr' => 'count,diff_key,cache_life,d_key,d_val', 'close' => 1], 'forgelist' => ['attr' => 'count,diff_key,cache_life,d_key,d_val', 'close' => 1],
'helper' => ['attr' => 'func', 'close' => 0],
]; ];
private function customBuildVar($mixedArgs) private function customBuildVar($mixedArgs)
@@ -31,28 +32,48 @@ class Site extends TagLib
} }
} }
/**
* 小说详情URL生成器
*
* @param array $n_id
* @return string
*/
public function tagHelper($tag)
{
$strFunc = (string)$tag['func'];
/** // $strFunc = $this->customBuildVar($strFunc);
* tagRankList
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagForgeList($tag, $content)
{
$count = $tag['count'] ?? '10';
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$diff_key = $this->customBuildVar($diff_key); $strParse = <<<EOD
$cache_life = $this->customBuildVar($cache_life); <?php
app(\\app\\services\\SiteContext::class)->{$strFunc}();
?>
EOD;
return $strParse;
}
$arrDataName = randomString(5);
$strParse = <<<EOT /**
* tagRankList
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagForgeList($tag, $content)
{
$count = $tag['count'] ?? '10';
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php <?php
\${$arrDataName} = app(\\app\\services\\SiteContext::class)->getForgeList([ \${$arrDataName} = app(\\app\\services\\SiteContext::class)->getForgeList([
'count' => {$count}, 'count' => {$count},
@@ -64,16 +85,16 @@ if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})):
?> ?>
EOT; EOT;
$strParse .= <<<EOT $strParse .= <<<EOT
<?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?> <?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?>
EOT; EOT;
$strParse .= $content; $strParse .= $content;
$strParse .= <<<EOT $strParse .= <<<EOT
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?> <?php endif; ?>
EOT; EOT;
return $strParse; return $strParse;
} }
/** /**
* cfg 标签处理函数-系统配置 * cfg 标签处理函数-系统配置
@@ -258,7 +279,7 @@ EOD;
$strStatus = isset($tag['status']) ? $tag['status'] : 'all'; $strStatus = isset($tag['status']) ? $tag['status'] : 'all';
$strOrder = isset($tag['order']) ? $tag['order'] : ''; $strOrder = isset($tag['order']) ? $tag['order'] : '';
$intPage = isset($tag['page']) ? $tag['page'] : 1; $intPage = isset($tag['page']) ? $tag['page'] : 1;
$strGender = $this->customBuildVar($strGender); $strGender = $this->customBuildVar($strGender);
$strCategory = $this->customBuildVar($strCategory); $strCategory = $this->customBuildVar($strCategory);
$strStatus = $this->customBuildVar($strStatus); $strStatus = $this->customBuildVar($strStatus);
@@ -297,11 +318,6 @@ EOD;
return $strParse; return $strParse;
} }
/** /**
* 内容替换 * 内容替换
* *
@@ -343,7 +359,7 @@ EOD;
$page_code = $this->customBuildVar($page_code); $page_code = $this->customBuildVar($page_code);
$diff = $this->customBuildVar($diff); $diff = $this->customBuildVar($diff);
$num = $this->customBuildVar($num); $num = $this->customBuildVar($num);
$arrDataName = randomString(5); $arrDataName = randomString(5);
$strParse = <<<EOT $strParse = <<<EOT

View File

@@ -374,4 +374,13 @@ resData = [
</li> </li>
{/site:forgelist} {/site:forgelist}
# 14、 视图反向控制器(注释函数),在视图开头调用,用来初始化一些操作。这里尽量不要复杂逻辑
# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号)
$func # SiteContext 里面的方法名
# 样例
{site:helper func="initHomeTKD" /}
``` ```