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');
|
|
|
|
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")))
|
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-08-08 20:16:09 +08:00
|
|
|
if(ep.start == ep.end){
|
|
|
|
form.append("name", info.title.replace("Epxxx", "E" + info.ep))
|
|
|
|
}else{
|
|
|
|
form.append("name", info.title.replace("Epxxx", "E" + ep.start + "-" + "E" + ep.end))
|
|
|
|
}
|
2023-08-08 20:47:46 +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")
|
|
|
|
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 => {
|
2023-07-31 22:26:30 +08:00
|
|
|
response.data.pipe(fs.createWriteStream(path.join(cwd(), `/downtor/${new Date().getTime()}.torrent`)));
|
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) {
|
|
|
|
// 删除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/"))
|
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-07-31 22:03:45 +08:00
|
|
|
await createTorrent(info.newPath, path.join(cwd(), "/tmp/torrent/" + info.seedName.replace(" ",".") + ".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)
|
|
|
|
|
|
|
|
} catch(err) {
|
|
|
|
console.log(err)
|
|
|
|
console.log("发种失败")
|
|
|
|
}
|
|
|
|
// 移动到做种文件夹
|
|
|
|
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 + "/")
|
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
|
|
|
|
}
|