2023-06-30 12:49:07 +00:00
|
|
|
|
const {spawn} = require('child_process');
|
2023-07-01 15:42:23 +00:00
|
|
|
|
const path = require('path');
|
|
|
|
|
const { cwd } = require('process');
|
2023-06-12 07:20:45 +00:00
|
|
|
|
|
|
|
|
|
|
2023-06-30 12:49:07 +00:00
|
|
|
|
function seep(time) {
|
|
|
|
|
return new Promise((res) => {
|
|
|
|
|
setTimeout(() => {
|
2023-06-12 07:20:45 +00:00
|
|
|
|
res()
|
2023-06-30 12:49:07 +00:00
|
|
|
|
}, time)
|
2023-06-12 07:20:45 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 12:49:07 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2023-07-01 13:01:05 +00:00
|
|
|
|
* 获取视频截图 (目前不可用,不好使)
|
2023-06-30 12:49:07 +00:00
|
|
|
|
* @param {String} filePath 文件绝对路径
|
2023-07-01 13:01:05 +00:00
|
|
|
|
* @param {number} seconds 时间
|
|
|
|
|
* @param {Promise<String>} save 保存绝对路径(含文件名)
|
|
|
|
|
* @returns {Promise<String>} 文件位置(待定)
|
2023-06-30 12:49:07 +00:00
|
|
|
|
*/
|
2023-07-01 13:01:05 +00:00
|
|
|
|
function getVideoSpecifyTimeImage(filePath, seconds, save) {
|
|
|
|
|
return new Promise((resolve) => {
|
2023-07-01 15:42:23 +00:00
|
|
|
|
const lux = spawn("ffmpeg", ['-ss',`${formatSeconds(seconds)}`,'-i',filePath,'-vframes','1',save],{
|
|
|
|
|
env:{
|
|
|
|
|
path:path.join(cwd(),'./bin/')
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-01 13:01:05 +00:00
|
|
|
|
lux.stdout.on('data', (data) => {
|
|
|
|
|
console.log(data)
|
|
|
|
|
});
|
|
|
|
|
lux.on('close', (code) => {
|
|
|
|
|
console.log("结束")
|
|
|
|
|
console.log(code.toString())
|
|
|
|
|
resolve(save)
|
|
|
|
|
});
|
2023-07-01 15:42:23 +00:00
|
|
|
|
lux.stderr.on("data",(err)=>{
|
|
|
|
|
console.log(String(err))
|
|
|
|
|
})
|
|
|
|
|
console.log(lux)
|
2023-07-01 13:01:05 +00:00
|
|
|
|
})
|
2023-06-30 12:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 12:08:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取视频文件信息
|
|
|
|
|
* @param {String}filePath 文件绝对路径
|
|
|
|
|
* @return {Promise<JSON>} videoInfo
|
|
|
|
|
*/
|
|
|
|
|
function getMediaInfo(filePath) {
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
const lux = spawn("./bin/MediaInfoCLI/MediaInfo.exe", ['--output=JSON', filePath])
|
|
|
|
|
lux.stdout.on('data', (data) => {
|
|
|
|
|
resolve(JSON.parse(data))
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 13:01:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* 制种
|
|
|
|
|
* @param {String}filePath 文件绝对路径
|
|
|
|
|
* @param {String}save 保存绝对路径(含文件名)
|
|
|
|
|
* @return {Promise<String>} 日志
|
|
|
|
|
*/
|
|
|
|
|
function createTorrent(filePath, save) {
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
const lux = spawn("./bin/Transmission/transmission-create", [filePath, '-p', '-t https://zmpt.cc/announce.php', '-o', save])
|
|
|
|
|
let response = '';
|
|
|
|
|
lux.stdout.on('data', (data) => {
|
|
|
|
|
response += data
|
|
|
|
|
});
|
|
|
|
|
lux.stdout.on('close', (code) => {
|
|
|
|
|
resolve(response)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 12:49:07 +00:00
|
|
|
|
|
|
|
|
|
function dow(info, callback) {
|
2023-07-01 15:42:23 +00:00
|
|
|
|
const lux = spawn("yt-dlp", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url],{
|
|
|
|
|
env:{
|
|
|
|
|
path:path.join(cwd(),'./bin/')
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-06-30 12:49:07 +00:00
|
|
|
|
lux.stdout.on('data', (data) => {
|
|
|
|
|
console.log(String(data))
|
|
|
|
|
callback(String(data), false)
|
|
|
|
|
});
|
|
|
|
|
lux.on('close', (code) => {
|
|
|
|
|
console.log("结束")
|
|
|
|
|
callback(code, true)
|
|
|
|
|
});
|
2023-06-12 07:20:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 13:01:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* 秒到时分秒
|
|
|
|
|
* @param value 秒
|
|
|
|
|
* @return {string|number} 返回时间格式[00:00:00]
|
|
|
|
|
*/
|
|
|
|
|
function formatSeconds(value) {
|
|
|
|
|
var secondTime = parseInt(value);// 秒
|
|
|
|
|
var minuteTime = 0;// 分
|
|
|
|
|
var hourTime = 0;// 小时
|
|
|
|
|
if (secondTime > 60) {//如果秒数大于60,将秒数转换成整数
|
|
|
|
|
//获取分钟,除以60取整数,得到整数分钟
|
|
|
|
|
minuteTime = parseInt(secondTime / 60);
|
|
|
|
|
//获取秒数,秒数取佘,得到整数秒数
|
|
|
|
|
secondTime = parseInt(secondTime % 60);
|
|
|
|
|
//如果分钟大于60,将分钟转换成小时
|
|
|
|
|
if (minuteTime > 60) {
|
|
|
|
|
//获取小时,获取分钟除以60,得到整数小时
|
|
|
|
|
hourTime = parseInt(minuteTime / 60);
|
|
|
|
|
//获取小时后取佘的分,获取分钟除以60取佘的分
|
|
|
|
|
minuteTime = parseInt(minuteTime % 60);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var result = "" + secondTime > 10 ? secondTime : '0' + secondTime;
|
|
|
|
|
|
|
|
|
|
if (minuteTime > 0) {
|
|
|
|
|
result = "" + minuteTime > 10 ? minuteTime : '0' + minuteTime + ":" + result;
|
|
|
|
|
} else {
|
|
|
|
|
result = "" + "00" + ":" + result;
|
|
|
|
|
}
|
|
|
|
|
if (hourTime > 0) {
|
|
|
|
|
result = "" + hourTime > 10 ? hourTime : '0' + hourTime + ":" + result;
|
|
|
|
|
} else {
|
|
|
|
|
result = "" + "00" + ":" + result;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2023-06-30 12:49:07 +00:00
|
|
|
|
|
2023-06-12 07:20:45 +00:00
|
|
|
|
module.exports = {
|
|
|
|
|
seep,
|
2023-06-30 12:49:07 +00:00
|
|
|
|
dow,
|
2023-07-01 13:01:05 +00:00
|
|
|
|
getVideoSpecifyTimeImage,
|
2023-07-01 12:08:54 +00:00
|
|
|
|
getMediaInfo,
|
2023-07-01 13:01:05 +00:00
|
|
|
|
createTorrent
|
2023-06-12 07:20:45 +00:00
|
|
|
|
}
|