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

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

View File

@@ -1,27 +1,52 @@
const { spawn } = require('child_process');
const {spawn} = require('child_process');
function seep(time){
return new Promise((res)=>{
setTimeout(()=>{
function seep(time) {
return new Promise((res) => {
setTimeout(() => {
res()
},time)
}, time)
})
}
function dow(info,callback){
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) => {
console.log(String(data))
callback(String(data),false)
});
lux.on('close', (code) => {
console.log("结束")
callback(code,true)
});
/**
* 获取视频长度
* @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) {
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) => {
console.log(String(data))
callback(String(data), false)
});
lux.on('close', (code) => {
console.log("结束")
callback(code, true)
});
}
module.exports = {
seep,
dow
dow,
getVideoTotalLength
}