add 发种与下载种子 移动到做种文件夹

This commit is contained in:
theluyuan 2023-07-31 22:03:45 +08:00
parent 655703f5fe
commit 3f8f14c024
16 changed files with 226 additions and 71 deletions

Binary file not shown.

View File

@ -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",

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

View File

@ -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

View File

@ -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("未下载完成")
}

View File

@ -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))

View File

@ -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;
}

View File

@ -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 = {

View File

@ -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)
}
// 获取所有订阅 (不包括已完成)

View File

@ -115,6 +115,26 @@ function getMediaInfo(filePath) {
})
}
/**
* 发布种子的获取视频文件信息
* @param {String}filePath 文件绝对路径
* @return {Promise<JSON>} 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
}

View File

@ -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(){

View File

@ -45,19 +45,21 @@
</el-input>
</div>
<div style="display: flex;align-items: center;padding: 5px">
<el-select value-key="browsecat">
<el-option :value="418">日漫</el-option>
<el-option :value="417">国漫</el-option>
<el-option :value="403">综艺</el-option>
<el-option :value="402">电视剧</el-option>
<el-option :value="422">纪录片</el-option>
<el-select v-model="type" value-key="browsecat">
<el-option :value="418" label="日漫">日漫</el-option>
<el-option :value="417" label="国漫">国漫</el-option>
<el-option :value="403" label="综艺">综艺</el-option>
<el-option :value="402" label="电视剧">电视剧</el-option>
<el-option :value="422" label="纪录片">纪录片</el-option>
</el-select>
<div style="padding: 12px">
<el-checkbox-button label="tags[4][]" key="1">禁转</el-checkbox-button>
<el-checkbox-button label="tags[4][]" key="3">官方</el-checkbox-button>
<el-checkbox-button label="tags[4][]" key="5">国语</el-checkbox-button>
<el-checkbox-button label="tags[4][]" key="6">中字</el-checkbox-button>
<el-checkbox-button label="tags[4][]" key="7">HDR</el-checkbox-button>
<el-checkbox-group v-model="tags" size="large">
<el-checkbox-button label="1">禁转</el-checkbox-button>
<el-checkbox-button label="3">官方</el-checkbox-button>
<el-checkbox-button label="5">国语</el-checkbox-button>
<el-checkbox-button label="6">中字</el-checkbox-button>
<el-checkbox-button label="7">HDR</el-checkbox-button>
</el-checkbox-group>
</div>
</div>
@ -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',