add 移动多文件
This commit is contained in:
parent
4bc2504a44
commit
b675e3033d
@ -1,5 +1,5 @@
|
||||
const Router = require("koa-router")
|
||||
const {search, gen_douban} = require("../util/ptgen")
|
||||
const {serach, gen_douban} = require("../util/ptgen")
|
||||
const axios = require("axios")
|
||||
const cheerio = require("cheerio");
|
||||
const {addSub, getSub, delSub} = require("../util/sql/video"); // HTML页面解析
|
||||
@ -13,7 +13,7 @@ const router = new Router({
|
||||
*/
|
||||
router.get("/searchVideo", async (ctx) => {
|
||||
let name = ctx.query.name
|
||||
ctx.body = await search(name)
|
||||
ctx.body = await serach(name)
|
||||
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,7 @@ const fs = require("fs")
|
||||
const { getMediaState } = require("../sql/download.js");
|
||||
const path = require("path");
|
||||
const { cwd } = require("process");
|
||||
const { createTorrent, getVideoSpecifyTimeImage, uploadImg, getMediaInfoSend, deleteFolder } = require("../utils.js");
|
||||
const { createTorrent, getVideoSpecifyTimeImage, uploadImg, getMediaInfoSend, deleteFolder, moveDir } = require("../utils.js");
|
||||
const { getVideoInfo } = require("../sql/video.js");
|
||||
const { mkdirRecursions } = require("../markdir.js");
|
||||
const { default: axios } = require("axios");
|
||||
@ -106,11 +106,10 @@ async function sendSeed(info) {
|
||||
}
|
||||
// 移动到做种文件夹
|
||||
mkdirRecursions(newDir + "/" + info.seedName + "/")
|
||||
fs.renameSync(info.newPath + "/" + info.rname, newDir + "/" + info.seedName + "/" + info.rname);
|
||||
// fs.renameSync(info.newPath + "/" + info.rname, newDir + "/" + info.seedName + "/" + info.rname);
|
||||
moveDir(info.newPath + "/" ,newDir + "/" + info.seedName + "/")
|
||||
// 删除下载的文件夹
|
||||
deleteFolder(info.newPath)
|
||||
|
||||
|
||||
} else {
|
||||
console.log("未下载完成")
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
const axios = require("axios")
|
||||
const cheerio = require("cheerio"); // HTML页面解析
|
||||
async function search(name) {
|
||||
async function serach(name) {
|
||||
const list = await axios.get(`https://movie.douban.com/j/subject_suggest?q=${name}`, {
|
||||
proxy: false,
|
||||
})
|
||||
@ -212,6 +212,6 @@ async function gen_douban(sid) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
serach: search,
|
||||
serach,
|
||||
gen_douban
|
||||
}
|
@ -38,10 +38,10 @@ async function addVideoInfo(cover){
|
||||
// 获取当前剧集是否下载完成
|
||||
// todo 多集连发
|
||||
async function getMediaState(vid){
|
||||
// let sql = `select * from download where vid=? and state!=1`
|
||||
// let list = await getAll(sql,vid)
|
||||
// return !list.length
|
||||
return true
|
||||
let sql = `select * from download where vid=? and state!=1`
|
||||
let list = await getAll(sql,vid)
|
||||
return !list.length
|
||||
// return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -11,7 +11,7 @@ function spawn(exe, arg, config) {
|
||||
if (!config) {
|
||||
config = {}
|
||||
}
|
||||
config.env = {...process.env}
|
||||
config.env = { ...process.env }
|
||||
config.env.Path = [path.join(cwd(), '/bin'), path.join(cwd(), '/bin/MediaInfoCLI'), path.join(cwd(), '/bin/Transmission')].join(";")
|
||||
|
||||
return spawn2(exe, arg, config)
|
||||
@ -110,7 +110,7 @@ function getMediaInfo(filePath) {
|
||||
console.log(all)
|
||||
resolve(JSON.parse(all))
|
||||
})
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
@ -130,7 +130,7 @@ function getMediaInfoSend(filePath) {
|
||||
lux.stdout.on('close', () => {
|
||||
resolve(all)
|
||||
})
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
@ -156,7 +156,7 @@ function createTorrent(filePath, save) {
|
||||
|
||||
|
||||
function dow(info, callback) {
|
||||
console.log( ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url].join(" "))
|
||||
console.log(['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url].join(" "))
|
||||
const lux = spawn("yt-dlp", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url], {
|
||||
env: {
|
||||
path: path.join(cwd(), './bin/')
|
||||
@ -214,12 +214,12 @@ function formatSeconds(value) {
|
||||
* @param {string} filePath 文件路径
|
||||
* @returns {boolean} true存在,false不存在
|
||||
*/
|
||||
function fileIsExist(filePath){
|
||||
function fileIsExist(filePath) {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return true
|
||||
} else {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,21 +230,46 @@ function fileIsExist(filePath){
|
||||
function deleteFolder(filePath) {
|
||||
const files = []
|
||||
if (fs.existsSync(filePath)) {
|
||||
const files = fs.readdirSync(filePath)
|
||||
files.forEach((file) => {
|
||||
const nextFilePath = `${filePath}/${file}`
|
||||
const states = fs.statSync(nextFilePath)
|
||||
if (states.isDirectory()) {
|
||||
//recurse
|
||||
deleteFolder(nextFilePath)
|
||||
} else {
|
||||
//delete file
|
||||
fs.unlinkSync(nextFilePath)
|
||||
}
|
||||
})
|
||||
fs.rmdirSync(filePath)
|
||||
const files = fs.readdirSync(filePath)
|
||||
files.forEach((file) => {
|
||||
const nextFilePath = `${filePath}/${file}`
|
||||
const states = fs.statSync(nextFilePath)
|
||||
if (states.isDirectory()) {
|
||||
//recurse
|
||||
deleteFolder(nextFilePath)
|
||||
} else {
|
||||
//delete file
|
||||
fs.unlinkSync(nextFilePath)
|
||||
}
|
||||
})
|
||||
fs.rmdirSync(filePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件夹下的所有文件(不包括文件夹)
|
||||
* @param {string} sourceFolder 源文件夹
|
||||
* @param {string} targetFolder 目标文件夹
|
||||
*/
|
||||
function moveDir(sourceFolder,targetFolder ){
|
||||
try {
|
||||
// 读取源文件夹中的所有文件
|
||||
const files = fs.readdirSync(sourceFolder);
|
||||
|
||||
// 遍历源文件夹中的文件
|
||||
files.forEach(file => {
|
||||
// 构建源文件和目标文件的完整路径
|
||||
const sourcePath = path.join(sourceFolder, file);
|
||||
const targetPath = path.join(targetFolder, file);
|
||||
|
||||
// 移动文件
|
||||
fs.renameSync(sourcePath, targetPath);
|
||||
console.log(`成功移动文件 ${file}`);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('无法读取源文件夹或移动文件:', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
@ -258,5 +283,6 @@ module.exports = {
|
||||
spawn,
|
||||
fileIsExist,
|
||||
getMediaInfoSend,
|
||||
deleteFolder
|
||||
deleteFolder,
|
||||
moveDir
|
||||
}
|
Loading…
Reference in New Issue
Block a user