From b675e3033db81aa39e543f6ecc883938cd501ff6 Mon Sep 17 00:00:00 2001 From: theluyuan <1162963624@qq.com> Date: Mon, 7 Aug 2023 22:05:55 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=A7=BB=E5=8A=A8=E5=A4=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/videoInfo.js | 4 +-- util/SendSeed/index.js | 7 ++--- util/ptgen/index.js | 4 +-- util/sql/download.js | 8 ++--- util/utils.js | 70 +++++++++++++++++++++++++++++------------- 5 files changed, 59 insertions(+), 34 deletions(-) diff --git a/router/videoInfo.js b/router/videoInfo.js index 5d68ef5..ec799a4 100644 --- a/router/videoInfo.js +++ b/router/videoInfo.js @@ -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) }) diff --git a/util/SendSeed/index.js b/util/SendSeed/index.js index eb6818b..7ff7748 100644 --- a/util/SendSeed/index.js +++ b/util/SendSeed/index.js @@ -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("未下载完成") } diff --git a/util/ptgen/index.js b/util/ptgen/index.js index 60f5e25..2154d85 100644 --- a/util/ptgen/index.js +++ b/util/ptgen/index.js @@ -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 } \ No newline at end of file diff --git a/util/sql/download.js b/util/sql/download.js index 16ef78e..12898a2 100644 --- a/util/sql/download.js +++ b/util/sql/download.js @@ -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 = { diff --git a/util/utils.js b/util/utils.js index 52cd740..066bdec 100644 --- a/util/utils.js +++ b/util/utils.js @@ -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 } \ No newline at end of file