add 获取视频长度及测试用按钮与请求地址

This commit is contained in:
SummerTail 2023-06-30 20:49:07 +08:00
parent 768bdcc2af
commit fe815b455d
4 changed files with 185 additions and 134 deletions

View File

@ -1,5 +1,6 @@
const Router = require("koa-router") const Router = require("koa-router")
const {getQqListData} = require("../util/getList/qq") const {getQqListData} = require("../util/getList/qq")
const {getVideoTotalLength} = require("../util/utils")
const KoaSSEStream = require('koa-sse-stream'); const KoaSSEStream = require('koa-sse-stream');
const {dowload} = require("../util/download"); const {dowload} = require("../util/download");
const {addDownList, getDownList, setDownState} = require("../util/sql/download"); const {addDownList, getDownList, setDownState} = require("../util/sql/download");
@ -7,6 +8,11 @@ const dayjs = require("dayjs")
const router = new Router() const router = new Router()
// const dowloadlist = [] // const dowloadlist = []
router.get("/test", async (ctx) => {
let url = ctx.query.url
ctx.body = getVideoTotalLength(url)
})
router.get("/getQqList", async (ctx) => { router.get("/getQqList", async (ctx) => {
let url = ctx.query.url let url = ctx.query.url
let videoid = url.split("/") let videoid = url.split("/")
@ -51,6 +57,7 @@ router.get('/msg', KoaSSEStream(SSE_CONF), ctx => {
} }
}) })
let start = false let start = false
function startDown(data) { function startDown(data) {
start = true start = true
dowload(data, async (data2, isok) => { dowload(data, async (data2, isok) => {
@ -65,6 +72,7 @@ function startDown(data){
} }
}) })
} }
setInterval(async () => { setInterval(async () => {
let dowloadlist = await getDownList() let dowloadlist = await getDownList()
if (dowloadlist.length != 0 && !start) { if (dowloadlist.length != 0 && !start) {

View File

@ -9,6 +9,29 @@ function seep(time){
}) })
} }
/**
* 获取视频长度
* @param {String} filePath 文件绝对路径
* @returns {number} 时长()
*/
function getVideoTotalLength(filePath) {
const lux = spawn("./bin/ffmpeg.exe", ['-i', filePath, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv="p=0"'])
console.log("join")
lux.stdout.on('data', (data) => {
console.log("开始")
console.log(data)
});
lux.on('close', (code) => {
console.log("结束")
console.log(code.toString())
});
return 0;
}
function dow(info, callback) { function dow(info, callback) {
const lux = spawn("./bin/yt-dlp.exe", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url]) const lux = spawn("./bin/yt-dlp.exe", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url])
lux.stdout.on('data', (data) => { lux.stdout.on('data', (data) => {
@ -21,7 +44,9 @@ function dow(info,callback){
}); });
} }
module.exports = { module.exports = {
seep, seep,
dow dow,
getVideoTotalLength
} }

View File

@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="./vite.svg" /> <link rel="icon" type="image/svg+xml" href="./vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title> <title>Vite + Vue</title>
<script type="module" crossorigin src="./assets/index-ec9a45aa.js"></script> <script type="module" crossorigin src="./assets/index-ea8b965c.js"></script>
<link rel="stylesheet" href="./assets/index-6ef103ac.css"> <link rel="stylesheet" href="./assets/index-e0450ab1.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -3,14 +3,15 @@
<el-form-item label="视频地址"> <el-form-item label="视频地址">
<div style="display: flex;width: 100%;"> <div style="display: flex;width: 100%;">
<el-input style="width: 100%;" v-model="form.name"/> <el-input style="width: 100%;" v-model="form.name"/>
<el-button style="flex-shrink: 0;margin: 0 10px;" @click="getlist" type="primary">获取</el-button> <el-button style="flex-shrink: 0;margin: 0 10px;" @click="getList" type="primary">获取</el-button>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="第几集开始"> <el-form-item label="第几集开始">
<div style="display: flex;"> <div style="display: flex;">
<el-input v-model="form.start"/> <el-input v-model="form.start"/>
<el-button style="flex-shrink: 0;margin: 0 10px;" @click="setlist" type="primary">设置</el-button> <el-button style="flex-shrink: 0;margin: 0 10px;" @click="setList" type="primary">设置</el-button>
<el-button style="flex-shrink: 0;margin: 0 10px;" @click="test" type="primary">测试按钮</el-button>
</div> </div>
</el-form-item> </el-form-item>
@ -18,7 +19,8 @@
<div style="display: flex;"> <div style="display: flex;">
<el-input v-model="form.save"/> <el-input v-model="form.save"/>
<el-button style="flex-shrink: 0;margin: 0 10px;" @click="dow" type="primary">下载</el-button> <el-button style="flex-shrink: 0;margin: 0 10px;" @click="dow" type="primary">下载</el-button>
<el-button style="flex-shrink: 0;margin: 0 10px;" @click="showmsg" type="primary">查看进度</el-button> <el-button style="flex-shrink: 0;margin: 0 10px;" @click="showMsg" type="primary">查看进度</el-button>
</div> </div>
</el-form-item> </el-form-item>
@ -41,6 +43,7 @@
import {ref} from 'vue'; import {ref} from 'vue';
import {ElLoading, ElMessage} from 'element-plus' import {ElLoading, ElMessage} from 'element-plus'
import axios from 'axios'; import axios from 'axios';
const dialogVisible = ref(false) const dialogVisible = ref(false)
const form = ref({ const form = ref({
name: "https://v.qq.com/x/cover/mzc002007vp35qj.html", name: "https://v.qq.com/x/cover/mzc002007vp35qj.html",
@ -49,7 +52,8 @@ const form = ref({
}) })
const tableData = ref([]) const tableData = ref([])
const table = ref() const table = ref()
function getlist() {
function getList() {
// let load = ElLoading.service() // let load = ElLoading.service()
// window.getlist(form.value.name).then((res) => { // window.getlist(form.value.name).then((res) => {
// console.log(res) // console.log(res)
@ -62,18 +66,20 @@ function getlist() {
tableData.value = r.data tableData.value = r.data
}) })
} }
function setlist() {
function setList() {
table.value.clearSelection() table.value.clearSelection()
for (let i = form.value.start - 1; i < tableData.value.length; i++) { for (let i = form.value.start - 1; i < tableData.value.length; i++) {
console.log(i) console.log(i)
table.value.toggleRowSelection(tableData.value[i], undefined) table.value.toggleRowSelection(tableData.value[i], undefined)
} }
} }
const msg = ref([]) const msg = ref([])
async function dow() { async function dow() {
let list = table.value.getSelectionRows() let list = table.value.getSelectionRows()
if (list.length == 0) { if (list.length === 0) {
ElMessage({ ElMessage({
showClose: true, showClose: true,
message: '请选择要下载的剧集', message: '请选择要下载的剧集',
@ -108,6 +114,7 @@ async function dow() {
type: 'success', type: 'success',
}) })
} }
const source = new EventSource(`/msg`); const source = new EventSource(`/msg`);
source.onmessage = event => { source.onmessage = event => {
// //
@ -116,11 +123,22 @@ source.onmessage = event => {
} }
msg.value.unshift(event.data) msg.value.unshift(event.data)
} }
function showmsg() {
function showMsg() {
dialogVisible.value = true dialogVisible.value = true
} }
function test() {
axios.get("/test", {
params: {url: form.value.name}
}).then((r) => {
console.log(r.data);
})
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.url {} .url {
}
</style> </style>