mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-19 09:30:10 +08:00
[fix] Return value must be of type array, fixes #204
This commit is contained in:
parent
2782e2af42
commit
3fdf4c25de
@ -25,6 +25,7 @@ use Bhp\Log\Log;
|
|||||||
use Bhp\Plugin\BasePlugin;
|
use Bhp\Plugin\BasePlugin;
|
||||||
use Bhp\Plugin\Plugin;
|
use Bhp\Plugin\Plugin;
|
||||||
use Bhp\TimeLock\TimeLock;
|
use Bhp\TimeLock\TimeLock;
|
||||||
|
use Bhp\Util\ArrayR\ArrayR;
|
||||||
use Bhp\Util\Exceptions\NoLoginException;
|
use Bhp\Util\Exceptions\NoLoginException;
|
||||||
|
|
||||||
class MainSite extends BasePlugin
|
class MainSite extends BasePlugin
|
||||||
@ -75,14 +76,14 @@ class MainSite extends BasePlugin
|
|||||||
* @param int $num
|
* @param int $num
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function fetchCustomAids(int $num = 30): array
|
protected function fetchCustomArchives(int $num = 30): array
|
||||||
{
|
{
|
||||||
if (getConf('main_site.fetch_aids_mode') == 'random') {
|
if (getConf('main_site.fetch_aids_mode') == 'random') {
|
||||||
// 随机热门稿件榜单
|
// 随机热门稿件榜单
|
||||||
return $this->getTopArchives($num);
|
return $this->getTopArchives($num);
|
||||||
} else {
|
} else {
|
||||||
// 固定获取关注UP稿件榜单, 不足会随机补全
|
// 固定获取关注UP稿件榜单, 不足会随机补全
|
||||||
return $this->getFollowUpAids($num);
|
return $this->getFollowUpArchives($num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ class MainSite extends BasePlugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 稿件列表
|
// 稿件列表
|
||||||
$aids = $this->fetchCustomAids($actual_num);
|
$aids = $this->fetchCustomArchives($actual_num);
|
||||||
//
|
//
|
||||||
Log::info("主站任务: 预投币稿件 " . implode(" ", $aids));
|
Log::info("主站任务: 预投币稿件 " . implode(" ", $aids));
|
||||||
// 投币
|
// 投币
|
||||||
@ -155,14 +156,9 @@ class MainSite extends BasePlugin
|
|||||||
//
|
//
|
||||||
if ($response['code']) {
|
if ($response['code']) {
|
||||||
Log::warning("主站任务: 获取首页推荐失败 {$response['code']} -> {$response['message']}");
|
Log::warning("主站任务: 获取首页推荐失败 {$response['code']} -> {$response['message']}");
|
||||||
return $this->getDayRankingArchives($num);
|
return $this->getTopFeedRCMDArchives($num);
|
||||||
}
|
|
||||||
//
|
|
||||||
if ($num == 1) {
|
|
||||||
return [array_rand($response['data']['archives'], $num)];
|
|
||||||
} else {
|
|
||||||
return array_rand($response['data']['archives'], $num);
|
|
||||||
}
|
}
|
||||||
|
return ArrayR::toSlice($response['data']['archives'], $num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,27 +166,19 @@ class MainSite extends BasePlugin
|
|||||||
* @param int $num
|
* @param int $num
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getDayRankingArchives(int $num): array
|
protected function getTopFeedRCMDArchives(int $num): array
|
||||||
{
|
{
|
||||||
$archives = [];
|
$new_archives = [];
|
||||||
$rand_nums = [];
|
|
||||||
//
|
//
|
||||||
$response = ApiVideo::ranking();
|
$response = ApiVideo::topFeedRCMD();
|
||||||
|
$archives = ArrayR::toSlice($response['data']['item'], $num);
|
||||||
//
|
//
|
||||||
for ($i = 0; $i < $num; $i++) {
|
foreach ($archives as $archive) {
|
||||||
while (true) {
|
$archive['aid'] = $archive['id'];
|
||||||
$rand_num = mt_rand(1, 99);
|
unset($archive['id']);
|
||||||
if (in_array($rand_num, $rand_nums)) {
|
$new_archives[] = $archive;
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
$rand_nums[] = $rand_num;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
return $new_archives;
|
||||||
$archives[] = $response['data']['list'][$rand_nums[$i]];
|
|
||||||
}
|
|
||||||
//
|
|
||||||
return $archives;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,28 +186,29 @@ class MainSite extends BasePlugin
|
|||||||
* @param int $num
|
* @param int $num
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getFollowUpAids(int $num): array
|
protected function getFollowUpArchives(int $num): array
|
||||||
{
|
{
|
||||||
$aids = [];
|
$archives = [];
|
||||||
//
|
//
|
||||||
$response = ApiDynamicSvr::followUpDynamic();
|
$response = ApiDynamicSvr::followUpDynamic();
|
||||||
//
|
//
|
||||||
if ($response['code']) {
|
if ($response['code']) {
|
||||||
Log::warning("主站任务: 获取UP稿件失败 {$response['code']} -> {$response['message']}");
|
Log::warning("主站任务: 获取UP稿件失败 {$response['code']} -> {$response['message']}");
|
||||||
return $aids;
|
} else {
|
||||||
|
foreach ($response['data']['cards'] as $i => $card) {
|
||||||
|
// if ($i >= $num) break;
|
||||||
|
// JSON_ERROR_CTRL_CHAR
|
||||||
|
$temp = preg_replace('/[\x00-\x1F]/', '', $card['card']);
|
||||||
|
$archives[] = json_decode($temp, true);
|
||||||
}
|
}
|
||||||
//
|
$archives = ArrayR::toSlice($archives, $num, false);
|
||||||
foreach ($response['data']['cards'] as $index => $card) {
|
|
||||||
if ($index >= $num) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$aids[] = $card['desc']['rid'];
|
|
||||||
}
|
}
|
||||||
// 此处补全缺失
|
// 此处补全缺失
|
||||||
if (count($aids) < $num) {
|
if (($t_num = count($archives)) < $num) {
|
||||||
$aids = array_merge($aids, $this->getTopArchives($num - count($aids)));
|
Log::warning("主站任务: 获取UP稿件数量不足,将自动补全随机稿件。");
|
||||||
|
$archives = array_merge($archives, $this->getTopArchives($num - $t_num));
|
||||||
}
|
}
|
||||||
return $aids;
|
return $archives;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,7 +277,7 @@ class MainSite extends BasePlugin
|
|||||||
{
|
{
|
||||||
if (!getConf('main_site.share', false, 'bool')) return true;
|
if (!getConf('main_site.share', false, 'bool')) return true;
|
||||||
|
|
||||||
$archives = $this->fetchCustomAids(10);
|
$archives = $this->fetchCustomArchives(10);
|
||||||
$archive = array_pop($archives);
|
$archive = array_pop($archives);
|
||||||
$aid = (string)$archive['aid'];
|
$aid = (string)$archive['aid'];
|
||||||
|
|
||||||
@ -314,10 +303,16 @@ class MainSite extends BasePlugin
|
|||||||
{
|
{
|
||||||
if (!getConf('main_site.watch', false, 'bool')) return true;
|
if (!getConf('main_site.watch', false, 'bool')) return true;
|
||||||
|
|
||||||
$archives = $this->fetchCustomAids(10);
|
$archives = $this->fetchCustomArchives(10);
|
||||||
$archive = array_pop($archives);
|
$archive = array_pop($archives);
|
||||||
|
//
|
||||||
|
if (isset($archive['duration']) && is_int($archive['duration'])) {
|
||||||
|
$info = $archive;
|
||||||
|
} else {
|
||||||
// 额外处理信息
|
// 额外处理信息
|
||||||
$info = $this->getArchiveInfo((string)$archive['aid']);
|
$info = $this->getArchiveInfo((string)$archive['aid']);
|
||||||
|
}
|
||||||
|
//
|
||||||
$aid = (string)$info['aid'];
|
$aid = (string)$info['aid'];
|
||||||
$cid = (string)$info['cid'];
|
$cid = (string)$info['cid'];
|
||||||
$duration = (int)$info['duration'];
|
$duration = (int)$info['duration'];
|
||||||
@ -358,8 +353,10 @@ class MainSite extends BasePlugin
|
|||||||
protected function getArchiveInfo(string $aid): array
|
protected function getArchiveInfo(string $aid): array
|
||||||
{
|
{
|
||||||
$response = ApiPlayer::pageList($aid);
|
$response = ApiPlayer::pageList($aid);
|
||||||
return $response['data'];
|
//
|
||||||
|
$archive_info = $response['data'][0];
|
||||||
|
$archive_info['aid'] = $aid;
|
||||||
|
return $archive_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,8 @@ device_version: 0.0.1
|
|||||||
app:
|
app:
|
||||||
bili_a: # Android
|
bili_a: # Android
|
||||||
package: "tv.danmaku.bili"
|
package: "tv.danmaku.bili"
|
||||||
version: "7.3.0"
|
version: "7.14.1"
|
||||||
build: "7030300"
|
build: "7141100"
|
||||||
channel: "bili"
|
channel: "bili"
|
||||||
device: "phone"
|
device: "phone"
|
||||||
mobi_app: "android"
|
mobi_app: "android"
|
||||||
@ -15,7 +15,7 @@ app:
|
|||||||
secret_key: "NTYwYzUyY2NkMjg4ZmVkMDQ1ODU5ZWQxOGJmZmQ5NzM"
|
secret_key: "NTYwYzUyY2NkMjg4ZmVkMDQ1ODU5ZWQxOGJmZmQ5NzM"
|
||||||
app_key_n: "NzgzYmJiNzI2NDQ1MWQ4Mg=="
|
app_key_n: "NzgzYmJiNzI2NDQ1MWQ4Mg=="
|
||||||
secret_key_n: "MjY1MzU4M2M4ODczZGVhMjY4YWI5Mzg2OTE4YjFkNjU="
|
secret_key_n: "MjY1MzU4M2M4ODczZGVhMjY4YWI5Mzg2OTE4YjFkNjU="
|
||||||
statistics: '{"appId":1,"platform":3,"version":"7.3.0","abtest":""}'
|
statistics: '{"appId":1,"platform":3,"version":"7.14.1","abtest":""}'
|
||||||
bili_i: # IOS
|
bili_i: # IOS
|
||||||
app_key: "MjdlYjUzZmM5MDU4ZjhjMw=="
|
app_key: "MjdlYjUzZmM5MDU4ZjhjMw=="
|
||||||
secret_key: "YzJlZDUzYTc0ZWVlZmUzY2Y5OWZiZDAxZDhjOWMzNzU="
|
secret_key: "YzJlZDUzYTc0ZWVlZmUzY2Y5OWZiZDAxZDhjOWMzNzU="
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class ApiTask
|
|||||||
* @var array|string[]
|
* @var array|string[]
|
||||||
*/
|
*/
|
||||||
protected static array $payload = [
|
protected static array $payload = [
|
||||||
'statistics' => '{"appId":1,"platform":3,"version":"7.3.0","abtest":""}',
|
'statistics' => '{"appId":1,"platform":3,"version":"7.14.1","abtest":""}',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class ApiTask
|
|||||||
* @var array|string[]
|
* @var array|string[]
|
||||||
*/
|
*/
|
||||||
protected static array $payload = [
|
protected static array $payload = [
|
||||||
'statistics' => '{"appId":1,"platform":3,"version":"7.3.0","abtest":""}',
|
'statistics' => '{"appId":1,"platform":3,"version":"7.14.1","abtest":""}',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,4 +44,3 @@ class ApiDynamicSvr
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class ApiLogin
|
|||||||
// $payload = [
|
// $payload = [
|
||||||
// 'cid' => $cid,
|
// 'cid' => $cid,
|
||||||
// 'tel' => $phone,
|
// 'tel' => $phone,
|
||||||
// 'statistics' => '{"appId":1,"platform":3,"version":"7.3.0","abtest":""}',
|
// 'statistics' => '{"appId":1,"platform":3,"version":"7.14.1","abtest":""}',
|
||||||
// ];
|
// ];
|
||||||
// {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"4e292933816755442c1568e2043b8e41","recaptcha_url":""}}
|
// {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"4e292933816755442c1568e2043b8e41","recaptcha_url":""}}
|
||||||
// {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"","recaptcha_url":"https://www.bilibili.com/h5/project-msg-auth/verify?ct=geetest\u0026recaptcha_token=ad520c3a4a3c46e29b1974d85efd2c4b\u0026gee_gt=1c0ea7c7d47d8126dda19ee3431a5f38\u0026gee_challenge=c772673050dce482b9f63ff45b681ceb\u0026hash=ea2850a43cc6b4f1f7b925d601098e5e"}}
|
// {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"","recaptcha_url":"https://www.bilibili.com/h5/project-msg-auth/verify?ct=geetest\u0026recaptcha_token=ad520c3a4a3c46e29b1974d85efd2c4b\u0026gee_gt=1c0ea7c7d47d8126dda19ee3431a5f38\u0026gee_challenge=c772673050dce482b9f63ff45b681ceb\u0026hash=ea2850a43cc6b4f1f7b925d601098e5e"}}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class ApiEvent
|
|||||||
* @var array|string[]
|
* @var array|string[]
|
||||||
*/
|
*/
|
||||||
protected static array $payload = [
|
protected static array $payload = [
|
||||||
'statistics' => '{"appId":1,"platform":3,"version":"7.3.0","abtest":""}',
|
'statistics' => '{"appId":1,"platform":3,"version":"7.14.1","abtest":""}',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -72,5 +72,18 @@ class ApiVideo
|
|||||||
return Request::getJson(true, 'other', $url, $payload);
|
return Request::getJson(true, 'other', $url, $payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页填充物 max=30
|
||||||
|
* @param int $ps
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function topFeedRCMD(int $ps = 30): array
|
||||||
|
{
|
||||||
|
$url = 'https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd';
|
||||||
|
$payload = [
|
||||||
|
'ps' => $ps,
|
||||||
|
];
|
||||||
|
return Request::getJson(true, 'other', $url, $payload);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -36,7 +36,21 @@ class ArrayR
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机部分切片
|
||||||
|
* @param array $arr
|
||||||
|
* @param int $num
|
||||||
|
* @param bool $random
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function toSlice(array $arr, int $num, bool $random = true): array
|
||||||
|
{
|
||||||
|
if ($random) {
|
||||||
|
//shuffle 将数组顺序随即打乱
|
||||||
|
shuffle($arr);
|
||||||
|
}
|
||||||
|
//array_slice 取该数组中的某一段
|
||||||
|
return array_slice($arr, 0, $num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user