add 文件制种,截图

This commit is contained in:
SummerTail 2023-07-01 21:01:05 +08:00
parent ab4783d544
commit 0781193f3d
2 changed files with 76 additions and 16 deletions

View File

@ -10,7 +10,7 @@ const router = new Router()
router.get("/test", async (ctx) => { router.get("/test", async (ctx) => {
let url = ctx.query.url let url = ctx.query.url
await utils.getMediaInfo(url).then(value => { await utils.createTorrent(url,'C:\\Users\\SummerTail\\Downloads\\Video\\斗破苍穹.年番.Fights.Break.Sphere.S05E06.2022.2160p.WEB-DL.H265.AAC-ADWeb.torrent').then(value => {
ctx.body = { ctx.body = {
code: 0, code: 0,
msg: "Test", msg: "Test",

View File

@ -11,23 +11,27 @@ function seep(time) {
/** /**
* 获取视频长度 * 获取视频截图 (目前不可用,不好使)
* @param {String} filePath 文件绝对路径 * @param {String} filePath 文件绝对路径
* @returns {number} 时长() * @param {number} seconds 时间
* @param {Promise<String>} save 保存绝对路径(含文件名)
* @returns {Promise<String>} 文件位置(待定)
*/ */
function getVideoTotalLength(filePath) { function getVideoSpecifyTimeImage(filePath, seconds, save) {
const lux = spawn("./bin/ffmpeg.exe", ['-i', filePath, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv="p=0"']) return new Promise((resolve) => {
console.log("join") console.info(formatSeconds(seconds))
lux.stdout.on('data', (data) => { const lux = spawn("./bin/ffmpeg.exe", ['-ss', formatSeconds(seconds), '-i', filePath, '-vframes 1', save])
console.log("开始") lux.stdout.on('data', (data) => {
console.log(data) console.log("开始")
}); console.log(data)
lux.on('close', (code) => { });
console.log("结束") lux.on('close', (code) => {
console.log(code.toString()) console.log("结束")
}); console.log(code.toString())
resolve(save)
});
return 0; })
} }
/** /**
@ -44,6 +48,25 @@ function getMediaInfo(filePath) {
}) })
} }
/**
* 制种
* @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)
})
})
}
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])
@ -57,10 +80,47 @@ function dow(info, callback) {
}); });
} }
/**
* 秒到时分秒
* @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;
}
module.exports = { module.exports = {
seep, seep,
dow, dow,
getVideoTotalLength, getVideoSpecifyTimeImage,
getMediaInfo, getMediaInfo,
createTorrent
} }