弹幕查询

This commit is contained in:
Jerry Yan 2022-07-12 14:45:50 +08:00
parent 94dafde0a4
commit 23dfef114e
5 changed files with 83 additions and 2 deletions

View File

@ -2,7 +2,9 @@
namespace App\Http\Controllers;
use App\Models\VideoDanmakus;
use App\Models\Videos;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
class DanmakuQueryController extends BaseController
@ -10,8 +12,33 @@ class DanmakuQueryController extends BaseController
public function index()
{
$video_list = Videos::query()->withCount("danmakus")->orderByDesc("created_at")->limit(20)->get();
return view("danmaku", [
return view("danmaku.index", [
"video_list" => $video_list,
]);
}
public function specific_search(Request $request, string $bvid)
{
$video = Videos::query()->withCount("danmakus")->where("bvid", "=", $bvid)->firstOrFail();
$keyword = $request->get("keyword", "");
if ($keyword) {
$query = VideoDanmakus::query()->where("video_bvid", "=", $bvid);
$keyword_split = explode(" ", $keyword);
foreach ($keyword_split as $_keyword) {
if (mb_strlen(trim($_keyword)) > 0) {
$query->where(function ($_query) use ($_keyword) {
$_query->where("content", "like", "%{$_keyword}%", "or")->where("from", "like", "%${_keyword}%", "or");
});
}
}
$danmakus = $query->orderBy("created_at", "asc")->get();
} else {
$danmakus = [];
}
return view("danmaku.search_index", [
"keyword" => $keyword,
"video" => $video,
"danmakus" => $danmakus,
]);
}
}

View File

@ -0,0 +1,53 @@
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>录播节目单查询</title>
</head>
<body>
@include("header")
<div>
<h3>{{$video->title}}</h3>
<h4>弹幕数:{{$video->danmakus_count}}</h4>
</div>
<form action="">
<label for="keyword">查找弹幕关键词,支持搜索用户名,空格隔开查找多个关键词</label>
<input type="text" name="keyword" id="keyword" value="{{$keyword}}">
<input type="submit">
</form>
@if($keyword)
<table border>
<thead>
<tr>
<td>发送人</td>
<td>弹幕内容</td>
<td>发送时间</td>
</tr>
</thead>
<tbody>
@foreach($danmakus as $danmaku)
<tr>
<td>
@switch($danmaku->platform_id)
@case(1)
<img src="https://cdn.jerryyan.net/luboimg/bilibili.ico" alt="B站" style="width: 1em; height: 1em;">
<a href="https://space.bilibili.com/{{$danmaku->from_mid}}" target="_blank">{{$danmaku->from}}</a>
@break(1)
@case(2)
<img src="https://cdn.jerryyan.net/luboimg/ixigua.ico" alt="西瓜视频" style="width: 1em; height: 1em;">
<a href="https://www.ixigua.com/home/{{$danmaku->from_mid}}/" target="_blank">{{$danmaku->from}}</a>
@break(2)
@default
{{$danmaku->from}}
@break(2)
@endswitch
</td>
<td>{{$danmaku->content}}</td>
<td>{{$danmaku->created_at}}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
@include("footer")
</body>
</html>

View File

@ -4,7 +4,7 @@
<div>
导航:
<a href="/">节目单查询</a>
<a href="/danmakus">直播弹幕查询</a>
<a href="/programs" style="color: gray" title="数据不全,待补充">节目查询</a>
<a href="/danmakus" style="color: gray" title="数据不全,待补充">直播弹幕查询</a>
</div>
</div>

View File

@ -16,5 +16,6 @@ use Illuminate\Support\Facades\Route;
Route::get('/', "\\App\\Http\\Controllers\\CommentQueryController@index");
Route::get('/programs', "\\App\\Http\\Controllers\\ProgramQueryController@index");
Route::get('/danmakus', "\\App\\Http\\Controllers\\DanmakuQueryController@index");
Route::get('/danmakus/{bvid}', "\\App\\Http\\Controllers\\DanmakuQueryController@specific_search");
Route::get('/upload', "\\App\\Http\\Controllers\\FileController@index");
Route::post('/upload', "\\App\\Http\\Controllers\\FileController@upload");