mirror of
https://github.com/lyz05/danmaku.git
synced 2026-04-27 12:19:56 +08:00
feat: 增加访问量显示
This commit is contained in:
1254
package-lock.json
generated
1254
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@
|
||||
"got": "^11.8.2",
|
||||
"http-errors": "~1.6.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"leancloud-storage": "^4.13.4",
|
||||
"lib-qqwry": "^1.3.2",
|
||||
"moment": "^2.29.4",
|
||||
"morgan": "~1.9.1",
|
||||
|
||||
@@ -4,6 +4,7 @@ const router = express.Router();
|
||||
const {bilibili, mgtv, tencentvideo, youku, iqiyi} = require('./api/base');
|
||||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
|
||||
const memory = require('../utils/memory')
|
||||
const leancloud = require('../utils/leancloud')
|
||||
|
||||
function getscheme(req) {
|
||||
return req.headers['x-forwarded-proto'] || req.protocol;
|
||||
@@ -37,6 +38,7 @@ async function build_response(url) {
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', async function (req, res, next) {
|
||||
leancloud.danmakuAccessAdd({ip: req.ip, url: req.query.url, ua: req.headers['user-agent']})
|
||||
//检查是否包含URL参数
|
||||
if (!req.query.url) {
|
||||
var urls = [mgtv.example_urls[0], bilibili.example_urls[0], tencentvideo.example_urls[0], youku.example_urls[0], iqiyi.example_urls[0]];
|
||||
@@ -59,4 +61,11 @@ router.get('/', async function (req, res, next) {
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/pageinfo', async function (req, res, next) {
|
||||
const today_visited = await leancloud.danmakuQuery(leancloud.currentDay());
|
||||
const lastday_visited = await leancloud.danmakuQuery(leancloud.lastDay());
|
||||
const month_visited = await leancloud.danmakuQuery(leancloud.currentMonth());
|
||||
res.json({today_visited, lastday_visited, month_visited})
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
65
utils/leancloud.js
Normal file
65
utils/leancloud.js
Normal file
@@ -0,0 +1,65 @@
|
||||
const AV = require('leancloud-storage');
|
||||
const {Query, User} = AV;
|
||||
// 引入环境变量
|
||||
require('dotenv').config({path: '../.env'});
|
||||
|
||||
AV.init({
|
||||
appId: process.env.LEANCLOUD_APP_ID,
|
||||
appKey: process.env.LEANCLOUD_APP_KEY,
|
||||
serverURL: "https://dbvunek8.lc-cn-e1-shared.com"
|
||||
});
|
||||
|
||||
function test() {
|
||||
const TestObject = AV.Object.extend('TestObject');
|
||||
const testObject = new TestObject();
|
||||
testObject.set('words', 'Hello world!');
|
||||
testObject.set('number', 123);
|
||||
testObject.save().then((testObject) => {
|
||||
console.log('保存成功。')
|
||||
})
|
||||
}
|
||||
|
||||
function danmakuAccessAdd(obj) {
|
||||
const {ip, url, ua} = obj;
|
||||
const DanmakuAccessObject = AV.Object.extend('DanmakuAccess');
|
||||
const record = new DanmakuAccessObject();
|
||||
record.set('remoteIP', ip);
|
||||
record.set('url', url);
|
||||
record.set('UA', ua);
|
||||
record.save().then()
|
||||
}
|
||||
|
||||
function currentDay() {
|
||||
const date = new Date();
|
||||
const start = new Date(date.setHours(0, 0, 0, 0))
|
||||
const end = new Date(date.setHours(23, 59, 59, 999))
|
||||
return [start,end]
|
||||
}
|
||||
|
||||
function lastDay() {
|
||||
const currentday = currentDay();
|
||||
currentday[0].setDate(currentday[0].getDate() - 1);
|
||||
currentday[1].setDate(currentday[1].getDate() - 1);
|
||||
return currentday
|
||||
}
|
||||
|
||||
function currentMonth() {
|
||||
var date = new Date(), y = date.getFullYear(), m = date.getMonth();
|
||||
var firstDay = new Date(y, m, 1);
|
||||
var lastDay = new Date(y, m + 1, 0);
|
||||
return [firstDay, lastDay]
|
||||
}
|
||||
|
||||
async function danmakuQuery(date) {
|
||||
const query = new AV.Query('DanmakuAccess');
|
||||
query.greaterThanOrEqualTo('createdAt', date[0]);
|
||||
query.lessThan('createdAt', date[1]);
|
||||
|
||||
// query.exists('url');
|
||||
return await query.count()
|
||||
}
|
||||
|
||||
module.exports = {danmakuAccessAdd, danmakuQuery, currentDay, currentMonth, lastDay};
|
||||
|
||||
if (!module.parent) {
|
||||
}
|
||||
@@ -12,91 +12,100 @@
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
|
||||
<!-- Cloudflare Web Analytics -->
|
||||
<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
|
||||
data-cf-beacon='{"token": "938fe927c5c44a888fb536713a2f1025"}'></script>
|
||||
data-cf-beacon='{"token": "938fe927c5c44a888fb536713a2f1025"}'></script>
|
||||
<!-- End Cloudflare Web Analytics -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row text-center">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
主流视频网站弹幕文件解析接口
|
||||
</h1>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="row text-center">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
主流视频网站弹幕文件解析接口
|
||||
</h1>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
<p>
|
||||
这是一个弹幕文件解析接口!输入你要解析的视频地址,即可获得B站弹幕形式的XML文件。<br />
|
||||
通过使用<a href="https:///www.dandanplay.com/">弹弹Play播放器</a>
|
||||
或者<a href='https://tiansh.github.io/us-danmaku/bilibili/'>bilibili ASS 弹幕在线转换项目</a>
|
||||
转换为普通字幕文件,即可在本地播放器中播放。
|
||||
</p>
|
||||
<p>
|
||||
使用方法:在当前页面添加一个查询字符串url<br />
|
||||
目前支持芒果TV,腾讯视频,优酷视频,爱奇艺视频,哔哩哔哩。<br />
|
||||
<strong>温馨提示:点击提交按钮,耐心等待就好,切勿疯狂刷新。</strong><br />
|
||||
<!-- 会对弹幕文本进行去重,去除包含xml标签的非法弹幕文本 -->
|
||||
例子:<br />
|
||||
<% urls.forEach(function(url) { %>
|
||||
<%= path %>?url=<%= url %><br />
|
||||
<% }); %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p>在下方直接输入视频网址,点击提交按钮也可解析。</p>
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">视频网址</label>
|
||||
<div class="col-sm-5">
|
||||
<input type="text" class="form-control" placeholder="URL" name="url">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-1 col-sm-5">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="download" checked='checked'> 强制下载
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-1 col-sm-5">
|
||||
<button type="submit" class="btn btn-primary">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<hr />
|
||||
<footer class="footer">
|
||||
<div class="row">
|
||||
Powered by <a href="https://fly.io/"><strong>Fly.io</strong> </a>
|
||||
<span class="post-meta-divider">|</span>
|
||||
Reference blog:
|
||||
<!-- <a href="https://lxmymjr.github.io/contents/%E4%B8%BB%E6%B5%81%E8%A7%86%E9%A2%91%E7%BD%91%E7%AB%99%E5%BC%B9%E5%B9%95%E4%B8%8B%E8%BD%BD">主流视频网站弹幕下载</a>-->
|
||||
<a href="https://blog.home999.cc/2020/%E5%9F%BA%E4%BA%8E%E9%98%BF%E9%87%8C%E4%BA%91%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0%E5%BC%B9%E5%B9%95%E6%96%87%E4%BB%B6%E8%A7%A3%E6%9E%90%E6%8E%A5%E5%8F%A3">主流视频网站弹幕下载</a>
|
||||
|
||||
</div>
|
||||
<!--
|
||||
<div class="row">
|
||||
今日访问量:{{ getpageinfo.today_visited }}<span class="post-meta-divider">|</span>
|
||||
昨日访问量:{{ getpageinfo.lastday_visited }}<span class="post-meta-divider">|</span>
|
||||
当月访问量:{{ getpageinfo.month_visited }}
|
||||
</div>
|
||||
-->
|
||||
</footer>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
<p>
|
||||
这是一个弹幕文件解析接口!输入你要解析的视频地址,即可获得B站弹幕形式的XML文件。<br/>
|
||||
通过使用<a href="https:///www.dandanplay.com/">弹弹Play播放器</a>
|
||||
或者<a href='https://tiansh.github.io/us-danmaku/bilibili/'>bilibili ASS 弹幕在线转换项目</a>
|
||||
转换为普通字幕文件,即可在本地播放器中播放。
|
||||
</p>
|
||||
<p>
|
||||
使用方法:在当前页面添加一个查询字符串url<br/>
|
||||
目前支持芒果TV,腾讯视频,优酷视频,爱奇艺视频,哔哩哔哩。<br/>
|
||||
<strong>温馨提示:点击提交按钮,耐心等待就好,切勿疯狂刷新。</strong><br/>
|
||||
<!-- 会对弹幕文本进行去重,去除包含xml标签的非法弹幕文本 -->
|
||||
例子:<br/>
|
||||
<% urls.forEach(function(url) { %>
|
||||
<%= path %>?url=<%= url %><br/>
|
||||
<% }); %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p>在下方直接输入视频网址,点击提交按钮也可解析。</p>
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">视频网址</label>
|
||||
<div class="col-sm-5">
|
||||
<input type="text" class="form-control" placeholder="URL" name="url">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-1 col-sm-5">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="download" checked='checked'> 强制下载
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-1 col-sm-5">
|
||||
<button type="submit" class="btn btn-primary">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<hr/>
|
||||
<footer class="footer">
|
||||
<div class="row">
|
||||
Powered by <a href="https://fly.io/"><strong>Fly.io</strong> </a>
|
||||
<span class="post-meta-divider">|</span>
|
||||
Reference blog:
|
||||
<!-- <a href="https://lxmymjr.github.io/contents/%E4%B8%BB%E6%B5%81%E8%A7%86%E9%A2%91%E7%BD%91%E7%AB%99%E5%BC%B9%E5%B9%95%E4%B8%8B%E8%BD%BD">主流视频网站弹幕下载</a>-->
|
||||
<a href="https://blog.home999.cc/2020/%E5%9F%BA%E4%BA%8E%E9%98%BF%E9%87%8C%E4%BA%91%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0%E5%BC%B9%E5%B9%95%E6%96%87%E4%BB%B6%E8%A7%A3%E6%9E%90%E6%8E%A5%E5%8F%A3">主流视频网站弹幕下载</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
今日访问量:<span id="today_visited"></span><span class="post-meta-divider"> | </span>
|
||||
昨日访问量:<span id="lastday_visited"></span><span class="post-meta-divider"> | </span>
|
||||
当月访问量:<span id="month_visited"></span>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
|
||||
$.ajax({
|
||||
url: 'pageinfo',
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
$('#today_visited').text(data.today_visited);
|
||||
$('#lastday_visited').text(data.lastday_visited);
|
||||
$('#month_visited').text(data.month_visited);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user