diff --git a/db/database.db b/db/database.db index 86e820d..a409dca 100644 Binary files a/db/database.db and b/db/database.db differ diff --git a/package.json b/package.json index 4d8a3e4..77d7fdc 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "axios": "^1.4.0", "cheerio": "1.0.0-rc.12", "dayjs": "^1.11.8", + "form-data": "^4.0.0", "koa": "^2.14.2", "koa-body": "^6.0.1", "koa-router": "^12.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1834c3c..5cfc07a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,6 +10,9 @@ dependencies: dayjs: specifier: ^1.11.8 version: 1.11.8 + form-data: + specifier: ^4.0.0 + version: 4.0.0 koa: specifier: ^2.14.2 version: 2.14.2 diff --git a/tmp/imgs/1.jpg b/tmp/imgs/1.jpg deleted file mode 100644 index 4236f0e..0000000 Binary files a/tmp/imgs/1.jpg and /dev/null differ diff --git a/tmp/imgs/2.jpg b/tmp/imgs/2.jpg deleted file mode 100644 index e27fbfc..0000000 Binary files a/tmp/imgs/2.jpg and /dev/null differ diff --git a/tmp/imgs/3.jpg b/tmp/imgs/3.jpg deleted file mode 100644 index 69691c8..0000000 Binary files a/tmp/imgs/3.jpg and /dev/null differ diff --git a/tmp/torrent/[只是离婚的关系].zhi shi li hun de guan xi. 2023.S01.WEB-DL.2160p.HEVC.AAC@ZmWeb.torrent b/tmp/torrent/[只是离婚的关系].zhi shi li hun de guan xi. 2023.S01.WEB-DL.2160p.HEVC.AAC@ZmWeb.torrent deleted file mode 100644 index 89dad52..0000000 Binary files a/tmp/torrent/[只是离婚的关系].zhi shi li hun de guan xi. 2023.S01.WEB-DL.2160p.HEVC.AAC@ZmWeb.torrent and /dev/null differ diff --git a/util/Download/index.js b/util/Download/index.js index 77ec7d4..3792c11 100644 --- a/util/Download/index.js +++ b/util/Download/index.js @@ -1,5 +1,5 @@ const path = require('path') -const {dow, fileIsExist,getMediaInfo} = require("../utils.js"); +const { dow, fileIsExist, getMediaInfo } = require("../utils.js"); const { mkdirRecursions } = require('../markdir.js'); const schedule = require('node-schedule'); const { setDownState, getDownList } = require('../sql/download.js'); @@ -8,107 +8,109 @@ const fs = require("fs"); const { sendSeed } = require('../SendSeed/index.js'); // 小于10添加0 -function addZeor(num){ - if(num < 10){ +function addZeor(num) { + if (num < 10) { return "0" + num - }else{ + } else { return num } } // 重命名 -async function reName(dinfo){ +async function reName(dinfo) { let vinfo = await getVideoInfo(dinfo.vid) console.log(vinfo) - if(vinfo){ + if (vinfo) { let info = await getMediaInfo(dinfo.save + "/" + dinfo.title + ".mp4") - console.log(info,dinfo.save + "/" + dinfo.title + ".mp4") + console.log(info, dinfo.save + "/" + dinfo.title + ".mp4") info = info.media.track let Video; let Audio; - for(let i of info){ - if(i["@type"] == "Video"){ + for (let i of info) { + if (i["@type"] == "Video") { Video = i } - if(i["@type"] == "Audio"){ + if (i["@type"] == "Audio") { Audio = i break } } // 判断时长 0 为下载 1 下载完成 2 做种 3 没有下载完成或没有会员 - if(Video.Duration < 4 * 60){ + if (Video.Duration < 4 * 60) { return { state: 3 } } let fbl = 0 - if(Video.Height > 3000){ + if (Video.Height > 3000) { fbl = 4320 - }else if(Video.Height > 1440){ + } else if (Video.Height > 1440) { fbl = 2160 - }else if(Video.Height > 1080){ + } else if (Video.Height > 1080) { fbl = 1440 - }else if(Video.Height > 720){ + } else if (Video.Height > 720) { fbl = 1080 - }else if(Video.Height > 480){ + } else if (Video.Height > 480) { fbl = 720 - }else { + } else { fbl = 480 } - let rname = `[${vinfo.name}].${vinfo.rename}.${vinfo.year}.S${addZeor(vinfo.season)}E${addZeor(dinfo.title)}.WEB-DL.${fbl}p.${Video.Format}.${Audio.Format}@ZmWeb.mp4` - let state = fs.renameSync(dinfo.save + "/" + dinfo.title + ".mp4",dinfo.save + "/" + rname) + let rname = `${vinfo.name}.${vinfo.rename}.${vinfo.year}.S${addZeor(vinfo.season)}E${addZeor(dinfo.title)}.WEB-DL.${fbl}p.${Video.Format}.${Audio.Format}@ZmWeb.mp4` + let state = fs.renameSync(dinfo.save + "/" + dinfo.title + ".mp4", dinfo.save + "/" + rname) let newPath = "" - let tem = dinfo.save.split("/") + let tem = dinfo.save.split("/") tem.pop() - let seedName = `[${vinfo.name}].${vinfo.rename}.${vinfo.year}.S${addZeor(vinfo.season)}.WEB-DL.${fbl}p.${Video.Format}.${Audio.Format}@ZmWeb` + let seedName = `${vinfo.name}.${vinfo.rename}.${vinfo.year}.S${addZeor(vinfo.season)}.WEB-DL.${fbl}p.${Video.Format}.${Audio.Format}@ZmWeb` tem.push(seedName) newPath = tem.join("/") return { state: 1, - info:{ + info: { vid: dinfo.vid, oldPath: dinfo.save, newPath: newPath, seedName, title: `${vinfo.rename} ${vinfo.year} S${addZeor(vinfo.season)}Epxxx WEB-DL ${fbl}p ${Video.Format} ${Audio.Format}@ZmWeb`, Duration: Video.Duration, - rname + rname, + ep: addZeor(dinfo.title), + fbl } } - }else{ + } else { console.log("未找到当前剧集信息") - return{ + return { state: 0 } } - + } // 当前下载状态 let state = false -async function CheckDown(){ - if(state){ +async function CheckDown() { + if (state) { return } let list = await getDownList() - if(list.length > 0){ + if (list.length > 0) { state = true let dinfo = list[0] mkdirRecursions(dinfo.save) - dow(dinfo,async (msg,s)=>{ + dow(dinfo, async (msg, s) => { console.log(String(msg)) - if(s){ + if (s) { let exist = fileIsExist(dinfo.save + "/" + dinfo.title + ".mp4") - if(exist){ + if (exist) { // 设置状态 let s = await reName(dinfo) - await setDownState(dinfo.id,s.state) + await setDownState(dinfo.id, s.state) state = false - if(s.info){ + if (s.info) { sendSeed(s.info) } - }else{ + } else { // 重新下载 console.log("下载失败重新下载") state = false diff --git a/util/SendSeed/index.js b/util/SendSeed/index.js index 3ffdf37..d236713 100644 --- a/util/SendSeed/index.js +++ b/util/SendSeed/index.js @@ -2,29 +2,116 @@ const fs = require("fs") const { getMediaState } = require("../sql/download.js"); const path = require("path"); const { cwd } = require("process"); -const { createTorrent, getVideoSpecifyTimeImage } = require("../utils.js"); - -async function updateSeed(){ - +const { createTorrent, getVideoSpecifyTimeImage, uploadImg, getMediaInfoSend, deleteFolder } = require("../utils.js"); +const { getVideoInfo } = require("../sql/video.js"); +const { mkdirRecursions } = require("../markdir.js"); +const { default: axios } = require("axios"); +const FormData = require('form-data'); +let newDir = "K:/zuozhongtest" +function getId(url){ + // 1; url=download.php?id=10796 + return url.split("?")[1].split("=")[1] +} +async function updateSeed(info, desc) { + let vinfo = await getVideoInfo(info.vid) + let form = new FormData() + form.append('file', fs.createReadStream(path.join(cwd(), "/tmp/torrent/" + info.seedName.replace(" ",".") + ".torrent"))) + form.append("name", info.title.replace("Epxxx", "E" + info.ep)) + form.append("small_descr", vinfo.subtitle) + form.append("url", vinfo.imdb) + form.append("descr", desc) + form.append("type", vinfo.type) + let tags = vinfo.tags.split(",") + for (let i of tags) { + form.append("tags[4][]", i) + } + form.append("medium_sel[4]", "10") + form.append("team_sel[4]", "7") + form.append("uplver","yes") + let fbl = { + 4320: "9", + 2160: "5", + 1440: "6", + 1080: "1", + 720: "8", + 480: "7" + } + form.append("standard_sel[4]", fbl[info.fbl]) + let instance = axios.create({ + headers: {...form.getHeaders(),Cookie:"c_secure_uid=MTQwMzg%3D; c_secure_pass=166f7662c2f2b83df7bfab6707e1af7d; c_secure_ssl=eWVhaA%3D%3D; c_secure_tracker_ssl=eWVhaA%3D%3D; c_secure_login=bm9wZQ%3D%3D"} + }); + let res = await instance.post("https://zmpt.cc/takeupload.php", form, { + proxy: false + }) + console.log(res.headers.refresh) + instance = axios.create({ + headers: {Cookie:"c_secure_uid=MTQwMzg%3D; c_secure_pass=166f7662c2f2b83df7bfab6707e1af7d; c_secure_ssl=eWVhaA%3D%3D; c_secure_tracker_ssl=eWVhaA%3D%3D; c_secure_login=bm9wZQ%3D%3D"} + }); + await instance({ + method: 'get', + url: "https://zmpt.cc/download.php?id=" + getId(res.headers.refresh), + responseType: 'stream', + proxy: false + }).then(response => { + response.data.pipe(fs.createWriteStream(path.join(cwd(), "/tmp/downtor/dow.torrent"))); + }) } -async function sendSeed(info){ +async function createDesc(filepath, vid) { + let urllist = [] + for (let i = 1; i < 4; i++) { + let data = await uploadImg(path.join(cwd(), "/tmp/imgs/" + i + ".jpg")) + urllist.push("[img]" + data.url + "[/img]") + } + let mediainfo = await getMediaInfoSend(filepath) + let desc = await getVideoInfo(vid) + desc = desc.desc + desc += `\n[quote]${mediainfo}[/quote]\n` + desc += urllist.join("\n") + + return desc +} + +async function sendSeed(info) { console.log(info) let state = await getMediaState(info.vid) console.log(state) - if(state){ + if (state) { + // 删除tmp + await deleteFolder(path.join(cwd(), "/tmp")) + await mkdirRecursions(path.join(cwd(), "/tmp/torrent/")) + await mkdirRecursions(path.join(cwd(), "/tmp/downtor/")) + await mkdirRecursions(path.join(cwd(), "/tmp/imgs/")) // 重命名文件夹 fs.renameSync(info.oldPath, info.newPath); // 创建种子 - await createTorrent(info.newPath,path.join(cwd(),"/tmp/torrent/" + info.seedName + ".torrent")) + await createTorrent(info.newPath, path.join(cwd(), "/tmp/torrent/" + info.seedName.replace(" ",".") + ".torrent")) // 获取图片 - for(let i = 1; i < 4; i++){ + for (let i = 1; i < 4; i++) { let time = info.Duration time = Math.floor(time / 4) - await getVideoSpecifyTimeImage(info.newPath + "/" + info.rname,time * i,path.join(cwd(),"/tmp/imgs/" + i + ".jpg")) + await getVideoSpecifyTimeImage(info.newPath + "/" + info.rname, time * i, path.join(cwd(), "/tmp/imgs/" + i + ".jpg")) } - await updateSeed(info.vid,) - }else{ + // await updateSeed(info.vid,) + let desc = await createDesc(info.newPath + "/" + info.rname, info.vid) + console.log(desc) + + try { + // 发种 + await updateSeed(info, desc) + + } catch(err) { + console.log(err) + console.log("发种失败") + } + // 移动到做种文件夹 + mkdirRecursions(newDir + "/" + info.seedName + "/") + fs.renameSync(info.newPath + "/" + info.rname, newDir + "/" + info.seedName + "/" + info.rname); + // 删除下载的文件夹 + deleteFolder(info.newPath) + + + } else { console.log("未下载完成") } diff --git a/util/Video/Update.js b/util/Video/Update.js index 0b9a747..a3e216b 100644 --- a/util/Video/Update.js +++ b/util/Video/Update.js @@ -7,12 +7,14 @@ const { addDownList } = require("../sql/download.js") async function addDown(i) { // 判断视频网站 if (i.url.indexOf("v.qq.com") != -1) { - let cid = i.url.split("/")[5].replace(".html") + let cid = i.url.split("/")[5].replace(".html","") + console.log(cid) let list = await getQqListData(cid) + console.log(list) list = list.item_datas for (let j = i.skip - 1; j < list.length; j++) { let v = list[j] - await addDownList(v.item_params.title, `https://v.qq.com/x/cover/${cid}/${v.item_params.vid}.html`, `d:/aaa/${i.sid}`, new Date().getTime(), 0, i.sid) + await addDownList(v.item_params.title, `https://v.qq.com/x/cover/${cid}/${v.item_params.vid}.html`, `k:/dltest/${i.sid}`, new Date().getTime(), 0, i.sid) } await updateSkip(list.length + 1,i.id) // console.log(JSON.stringify(list)) diff --git a/util/markdir.js b/util/markdir.js index 8678623..e5b5d12 100644 --- a/util/markdir.js +++ b/util/markdir.js @@ -27,7 +27,7 @@ function mkdir(dir) { */ function mkdirRecursions(dir) { let isExists = getStat(dir); - console.log(isExists) + console.log(isExists,dir) //如果该路径且不是文件,返回true if (isExists && isExists.isDirectory()) { return true; @@ -41,7 +41,10 @@ function mkdirRecursions(dir) { let status = mkdirRecursions(tempDir); let mkdirStatus; if (status) { - mkdirStatus = mkdir(dir); + console.log("mark",dir) + + mkdir(dir); + mkdirStatus = true } return mkdirStatus; } diff --git a/util/sql/download.js b/util/sql/download.js index eedf261..16ef78e 100644 --- a/util/sql/download.js +++ b/util/sql/download.js @@ -36,10 +36,12 @@ 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 + // 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/sql/video.js b/util/sql/video.js index c9f38aa..e2b07f3 100644 --- a/util/sql/video.js +++ b/util/sql/video.js @@ -8,8 +8,8 @@ async function addSub(info){ if(list.length != 0){ return "订阅已存在" } - let sql = `insert into VideoInfo(name,rename,skip,desc,url,subtitle,img,year,time,subTime,enable,season,sid,count,imdb) values(?,?,?,?,?,?,?,?,?,${new Date().getTime()},1,?,?,?,?)` - await run(sql,info.name,info.rename,info.skip,info.desc,info.url,info.subtitle,info.img,info.year,info.time,info.season,info.sid,info.count,info.imdb) + let sql = `insert into VideoInfo(name,rename,skip,desc,url,subtitle,img,year,time,subTime,enable,season,sid,count,imdb,type,tags) values(?,?,?,?,?,?,?,?,?,${new Date().getTime()},1,?,?,?,?,?,?)` + await run(sql,info.name,info.rename,info.skip,info.desc,info.url,info.subtitle,info.img,info.year,info.time,info.season,info.sid,info.count,info.imdb,info.type,info.tags) } // 获取所有订阅 (不包括已完成) diff --git a/util/utils.js b/util/utils.js index 739193b..52cd740 100644 --- a/util/utils.js +++ b/util/utils.js @@ -115,6 +115,26 @@ function getMediaInfo(filePath) { }) } +/** + * 发布种子的获取视频文件信息 + * @param {String}filePath 文件绝对路径 + * @return {Promise} videoInfo + */ +function getMediaInfoSend(filePath) { + return new Promise((resolve) => { + let all = "" + const lux = spawn("MediaInfo.exe", [filePath]) + lux.stdout.on('data', (data) => { + all += String(data) + }); + lux.stdout.on('close', () => { + resolve(all) + }) + + + }) +} + /** * 制种 * @param {String}filePath 文件绝对路径 @@ -202,6 +222,31 @@ function fileIsExist(filePath){ } } +/** + * 删除文件夹 + * @param {string} 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) + } + } + + module.exports = { seep, dow, @@ -211,5 +256,7 @@ module.exports = { getTencentVideoPlayList, uploadImg, spawn, - fileIsExist + fileIsExist, + getMediaInfoSend, + deleteFolder } \ No newline at end of file diff --git a/view/src/api/Video.js b/view/src/api/Video.js index ae27a7d..43445ba 100644 --- a/view/src/api/Video.js +++ b/view/src/api/Video.js @@ -24,8 +24,8 @@ export async function getImdbName(url) { } }) } -export async function addSubscribe({name, rename, desc, year, season, ep, url, img, subtitle, time,skip,sid,count,imdb}) { - return await base.post("/videoInfo/addSubscribe", {name, rename, desc, year, season, ep, url, img, subtitle, time,skip,sid,count,imdb}) +export async function addSubscribe(data) { + return await base.post("/videoInfo/addSubscribe", data) } export async function getSubscribe(){ diff --git a/view/src/page/subscribe/addSubscribe.vue b/view/src/page/subscribe/addSubscribe.vue index f8bc8c0..0cbc3c4 100644 --- a/view/src/page/subscribe/addSubscribe.vue +++ b/view/src/page/subscribe/addSubscribe.vue @@ -45,19 +45,21 @@
- - 日漫 - 国漫 - 综艺 - 电视剧 - 纪录片 + + 日漫 + 国漫 + 综艺 + 电视剧 + 纪录片
- 禁转 - 官方 - 国语 - 中字 - HDR + + 禁转 + 官方 + 国语 + 中字 + HDR +
@@ -102,6 +104,8 @@ const img = ref("") const time = ref("") const name = ref("") const count = ref(0) +const type = ref() +const tags = ref([]) async function onSubmit(name) { let res = await searchVideo(name) @@ -167,10 +171,14 @@ async function addsubscribe() { skip: season.value, sid: vid, count: count.value, - imdb: imdb + imdb: imdb, + type:type.value, + tags: tags.value.join(",") } + let ignore = ["imdb"] for (let i in data) { - if (!data[i]) { + if (!data[i] && !ignore.includes(i)) { + console.log(i,data[i]) ElMessage({ message: '请完整填写内容!', type: 'error',