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");
|
2023-07-31 22:03:45 +08:00
|
|
|
const { getVideoInfo } = require("../sql/video.js");
|
|
|
|
const { mkdirRecursions } = require("../markdir.js");
|
|
|
|
const { default: axios } = require("axios");
|
|
|
|
const FormData = require('form-data');
|
2023-09-03 16:59:13 +08:00
|
|
|
const { getConfig } = require("../config/config.js");
|
|
|
|
// let newDir = "K:/zuozhongtest"
|
|
|
|
function getId(url) {
|
2023-07-31 22:03:45 +08:00
|
|
|
// 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)
|
2023-09-03 16:59:13 +08:00
|
|
|
if (ep.start == ep.end) {
|
2023-08-08 20:16:09 +08:00
|
|
|
form.append("name", info.title.replace("Epxxx", "E" + info.ep))
|
2023-09-03 16:59:13 +08:00
|
|
|
} else {
|
|
|
|
if (ep.start == 1 && ep.end == vinfo.count) {
|
2023-08-22 15:00:31 +08:00
|
|
|
form.append("name", info.title.replace("Epxxx", ""))
|
2023-09-03 16:59:13 +08:00
|
|
|
} 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
|
|
|
}
|
2023-09-03 16:59:13 +08:00
|
|
|
await setDownStateVid(info.vid, 2)
|
2023-07-31 22:03:45 +08:00
|
|
|
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 + "/")
|
2023-07-31 22:03:45 +08:00
|
|
|
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")
|
2023-09-03 16:59:13 +08:00
|
|
|
form.append("uplver", "yes")
|
2023-07-31 22:03:45 +08:00
|
|
|
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({
|
2023-09-03 16:59:13 +08:00
|
|
|
headers: { ...form.getHeaders(), Cookie: getConfig().vCookies }
|
|
|
|
});
|
2023-07-31 22:03:45 +08:00
|
|
|
let res = await instance.post("https://zmpt.cc/takeupload.php", form, {
|
|
|
|
proxy: false
|
|
|
|
})
|
|
|
|
console.log(res.headers.refresh)
|
|
|
|
instance = axios.create({
|
2023-09-03 16:59:13 +08:00
|
|
|
headers: { Cookie: getConfig().vCookies }
|
|
|
|
});
|
2023-07-31 22:03:45 +08:00
|
|
|
await instance({
|
|
|
|
method: 'get',
|
|
|
|
url: "https://zmpt.cc/download.php?id=" + getId(res.headers.refresh),
|
|
|
|
responseType: 'stream',
|
|
|
|
proxy: false
|
2023-09-03 16:59:13 +08:00
|
|
|
}).then(response => {
|
2023-07-31 22:26:30 +08:00
|
|
|
response.data.pipe(fs.createWriteStream(path.join(cwd(), `/downtor/${new Date().getTime()}.torrent`)));
|
2023-09-03 16:59:13 +08:00
|
|
|
})
|
2023-07-31 22:03:45 +08:00
|
|
|
}
|
2023-07-23 01:03:29 +08:00
|
|
|
|
2023-07-31 22:03:45 +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
|
|
|
|
2023-07-31 22:03:45 +08:00
|
|
|
return desc
|
2023-07-23 01:03:29 +08:00
|
|
|
}
|
|
|
|
|
2023-07-31 22:03:45 +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)
|
2023-07-31 22:03:45 +08:00
|
|
|
if (state) {
|
2023-09-03 16:59:13 +08:00
|
|
|
// 删除tmp
|
2023-07-31 22:03:45 +08:00
|
|
|
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/"))
|
2023-07-31 22:03:45 +08:00
|
|
|
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
|
|
|
// 获取图片
|
2023-07-31 22:03:45 +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)
|
2023-07-31 22:03:45 +08:00
|
|
|
await getVideoSpecifyTimeImage(info.newPath + "/" + info.rname, time * i, path.join(cwd(), "/tmp/imgs/" + i + ".jpg"))
|
2023-07-23 01:03:29 +08:00
|
|
|
}
|
2023-07-31 22:03:45 +08:00
|
|
|
// await updateSeed(info.vid,)
|
|
|
|
let desc = await createDesc(info.newPath + "/" + info.rname, info.vid)
|
|
|
|
console.log(desc)
|
|
|
|
|
|
|
|
try {
|
|
|
|
// 发种
|
|
|
|
await updateSeed(info, desc)
|
|
|
|
|
2023-09-03 16:59:13 +08:00
|
|
|
} catch (err) {
|
2023-07-31 22:03:45 +08:00
|
|
|
console.log(err)
|
|
|
|
console.log("发种失败")
|
|
|
|
}
|
2023-09-03 16:59:13 +08:00
|
|
|
let newDir = getConfig().torrentSavePath
|
2023-07-31 22:03:45 +08:00
|
|
|
// 移动到做种文件夹
|
|
|
|
mkdirRecursions(newDir + "/" + info.seedName + "/")
|
2023-08-07 22:05:55 +08:00
|
|
|
// fs.renameSync(info.newPath + "/" + info.rname, newDir + "/" + info.seedName + "/" + info.rname);
|
2023-09-03 16:59:13 +08:00
|
|
|
moveDir(info.newPath + "/", newDir + "/" + info.seedName + "/")
|
2023-07-31 22:03:45 +08:00
|
|
|
// 删除下载的文件夹
|
|
|
|
deleteFolder(info.newPath)
|
|
|
|
} else {
|
2023-07-23 01:03:29 +08:00
|
|
|
console.log("未下载完成")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
sendSeed
|
|
|
|
}
|