const fs = require("fs") const { getMediaState, getDownEp, setDownStateVid } = require("../sql/download.js"); const path = require("path"); const { cwd } = require("process"); 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'); 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(/\s+/g, '.') + ".torrent"))) let ep = await getDownEp(info.vid) console.log(ep) 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)) } 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) 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:"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(), `/downtor/${new Date().getTime()}.torrent`))); }) } 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) { // 删除tmp await deleteFolder(path.join(cwd(), "/tmp")) await mkdirRecursions(path.join(cwd(), "/tmp/torrent/")) await mkdirRecursions(path.join(cwd(), "/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.replace(/\s+/g, '.') + ".torrent")) // 获取图片 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 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); moveDir(info.newPath + "/" ,newDir + "/" + info.seedName + "/") // 删除下载的文件夹 deleteFolder(info.newPath) } else { console.log("未下载完成") } } module.exports = { sendSeed }