ptSend/util/SendSeed/index.js

135 lines
4.7 KiB
JavaScript
Raw Normal View History

2023-07-23 01:03:29 +08:00
const fs = require("fs")
2023-08-08 20:47:46 +08:00
const { getMediaState, getDownEp, setDownStateVid } = require("../sql/download.js");
2023-07-23 01:03:29 +08:00
const path = require("path");
const { cwd } = require("process");
2023-08-07 22:05:55 +08:00
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");
const FormData = require('form-data');
const { getConfig } = require("../config/config.js");
// 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()
2023-08-09 13:08:47 +08:00
form.append('file', fs.createReadStream(path.join(cwd(), "/tmp/torrent/" + info.seedName.replace(/\s+/g, '.') + ".torrent")))
2023-08-08 20:16:09 +08:00
let ep = await getDownEp(info.vid)
2023-08-08 20:47:46 +08:00
console.log(ep)
if (ep.start == ep.end) {
2023-08-08 20:16:09 +08:00
form.append("name", info.title.replace("Epxxx", "E" + info.ep))
} else {
if (ep.start == 1 && ep.end == vinfo.count) {
2023-08-22 15:00:31 +08:00
form.append("name", info.title.replace("Epxxx", ""))
} else {
2023-08-22 15:00:31 +08:00
form.append("name", info.title.replace("Epxxx", "E" + ep.start + "-" + "E" + ep.end))
}
2023-08-08 20:16:09 +08:00
}
await setDownStateVid(info.vid, 2)
form.append("small_descr", vinfo.subtitle)
form.append("url", vinfo.imdb)
form.append("descr", desc)
form.append("type", vinfo.type)
2023-08-08 21:50:19 +08:00
form.append("pt_gen", 'https://movie.douban.com/subject/' + info.vid + "/")
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: getConfig().vCookies }
});
let res = await instance.post("https://zmpt.cc/takeupload.php", form, {
proxy: false
})
console.log(res.headers.refresh)
instance = axios.create({
headers: { Cookie: getConfig().vCookies }
});
await instance({
method: 'get',
url: "https://zmpt.cc/download.php?id=" + getId(res.headers.refresh),
responseType: 'stream',
proxy: false
}).then(response => {
2023-07-31 22:26:30 +08:00
response.data.pipe(fs.createWriteStream(path.join(cwd(), `/downtor/${new Date().getTime()}.torrent`)));
})
}
2023-07-23 01:03:29 +08:00
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")
2023-07-23 01:03:29 +08:00
return desc
2023-07-23 01:03:29 +08:00
}
async function sendSeed(info) {
2023-07-23 01:03:29 +08:00
console.log(info)
let state = await getMediaState(info.vid)
console.log(state)
if (state) {
// 删除tmp
await deleteFolder(path.join(cwd(), "/tmp"))
await mkdirRecursions(path.join(cwd(), "/tmp/torrent/"))
2023-07-31 22:19:45 +08:00
await mkdirRecursions(path.join(cwd(), "/downtor/"))
await mkdirRecursions(path.join(cwd(), "/tmp/imgs/"))
2023-07-23 01:03:29 +08:00
// 重命名文件夹
fs.renameSync(info.oldPath, info.newPath);
// 创建种子
2023-08-09 13:08:47 +08:00
await createTorrent(info.newPath, path.join(cwd(), "/tmp/torrent/" + info.seedName.replace(/\s+/g, '.') + ".torrent"))
2023-07-23 01:03:29 +08:00
// 获取图片
for (let i = 1; i < 4; i++) {
2023-07-23 01:03:29 +08:00
let time = info.Duration
time = Math.floor(time / 4)
await getVideoSpecifyTimeImage(info.newPath + "/" + info.rname, time * i, path.join(cwd(), "/tmp/imgs/" + i + ".jpg"))
2023-07-23 01:03:29 +08:00
}
// 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("发种失败")
}
let newDir = getConfig().torrentSavePath
// 移动到做种文件夹
mkdirRecursions(newDir + "/" + info.seedName + "/")
2023-08-07 22:05:55 +08:00
// fs.renameSync(info.newPath + "/" + info.rname, newDir + "/" + info.seedName + "/" + info.rname);
moveDir(info.newPath + "/", newDir + "/" + info.seedName + "/")
// 删除下载的文件夹
deleteFolder(info.newPath)
} else {
2023-07-23 01:03:29 +08:00
console.log("未下载完成")
}
}
module.exports = {
sendSeed
}