2023-07-22 23:04:26 +08:00
|
|
|
const path = require('path')
|
2023-07-31 22:03:45 +08:00
|
|
|
const { dow, fileIsExist, getMediaInfo } = require("../utils.js");
|
2023-07-22 23:04:26 +08:00
|
|
|
const { mkdirRecursions } = require('../markdir.js');
|
|
|
|
const schedule = require('node-schedule');
|
|
|
|
const { setDownState, getDownList } = require('../sql/download.js');
|
|
|
|
const { getVideoInfo } = require('../sql/video.js');
|
2023-07-23 01:03:29 +08:00
|
|
|
const fs = require("fs");
|
|
|
|
const { sendSeed } = require('../SendSeed/index.js');
|
2023-07-22 23:04:26 +08:00
|
|
|
|
|
|
|
// 小于10添加0
|
2023-07-31 22:03:45 +08:00
|
|
|
function addZeor(num) {
|
|
|
|
if (num < 10) {
|
2023-07-22 23:04:26 +08:00
|
|
|
return "0" + num
|
2023-07-31 22:03:45 +08:00
|
|
|
} else {
|
2023-07-22 23:04:26 +08:00
|
|
|
return num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重命名
|
2023-07-31 22:03:45 +08:00
|
|
|
async function reName(dinfo) {
|
2023-07-22 23:04:26 +08:00
|
|
|
let vinfo = await getVideoInfo(dinfo.vid)
|
|
|
|
console.log(vinfo)
|
2023-07-31 22:03:45 +08:00
|
|
|
if (vinfo) {
|
2023-07-22 23:04:26 +08:00
|
|
|
let info = await getMediaInfo(dinfo.save + "/" + dinfo.title + ".mp4")
|
2023-07-31 22:03:45 +08:00
|
|
|
console.log(info, dinfo.save + "/" + dinfo.title + ".mp4")
|
2023-07-22 23:04:26 +08:00
|
|
|
info = info.media.track
|
|
|
|
let Video;
|
|
|
|
let Audio;
|
2023-07-31 22:03:45 +08:00
|
|
|
for (let i of info) {
|
|
|
|
if (i["@type"] == "Video") {
|
2023-07-22 23:04:26 +08:00
|
|
|
Video = i
|
|
|
|
}
|
2023-07-31 22:03:45 +08:00
|
|
|
if (i["@type"] == "Audio") {
|
2023-07-22 23:04:26 +08:00
|
|
|
Audio = i
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 判断时长 0 为下载 1 下载完成 2 做种 3 没有下载完成或没有会员
|
2023-07-31 22:03:45 +08:00
|
|
|
if (Video.Duration < 4 * 60) {
|
2023-07-23 01:03:29 +08:00
|
|
|
return {
|
|
|
|
state: 3
|
|
|
|
}
|
2023-07-22 23:04:26 +08:00
|
|
|
}
|
|
|
|
let fbl = 0
|
2023-07-31 22:03:45 +08:00
|
|
|
if (Video.Height > 3000) {
|
2023-07-22 23:04:26 +08:00
|
|
|
fbl = 4320
|
2023-07-31 22:03:45 +08:00
|
|
|
} else if (Video.Height > 1440) {
|
2023-07-22 23:04:26 +08:00
|
|
|
fbl = 2160
|
2023-07-31 22:03:45 +08:00
|
|
|
} else if (Video.Height > 1080) {
|
2023-07-22 23:04:26 +08:00
|
|
|
fbl = 1440
|
2023-07-31 22:03:45 +08:00
|
|
|
} else if (Video.Height > 720) {
|
2023-07-22 23:04:26 +08:00
|
|
|
fbl = 1080
|
2023-07-31 22:03:45 +08:00
|
|
|
} else if (Video.Height > 480) {
|
2023-07-22 23:04:26 +08:00
|
|
|
fbl = 720
|
2023-07-31 22:03:45 +08:00
|
|
|
} else {
|
2023-07-22 23:04:26 +08:00
|
|
|
fbl = 480
|
|
|
|
}
|
2023-09-03 17:06:33 +08:00
|
|
|
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`
|
2023-07-31 22:03:45 +08:00
|
|
|
let state = fs.renameSync(dinfo.save + "/" + dinfo.title + ".mp4", dinfo.save + "/" + rname)
|
2023-07-23 01:03:29 +08:00
|
|
|
let newPath = ""
|
2023-07-31 22:03:45 +08:00
|
|
|
let tem = dinfo.save.split("/")
|
2023-07-23 01:03:29 +08:00
|
|
|
tem.pop()
|
2023-09-03 17:06:33 +08:00
|
|
|
let seedName = `${vinfo.name}.${vinfo.rename}.${vinfo.year}.S${addZeor(vinfo.season)}.WEB-DL.${fbl}p.${Video.Format}.${Audio.Format}-ZmWeb`
|
2023-07-23 01:03:29 +08:00
|
|
|
tem.push(seedName)
|
|
|
|
newPath = tem.join("/")
|
|
|
|
return {
|
|
|
|
state: 1,
|
2023-07-31 22:03:45 +08:00
|
|
|
info: {
|
2023-07-23 01:03:29 +08:00
|
|
|
vid: dinfo.vid,
|
|
|
|
oldPath: dinfo.save,
|
|
|
|
newPath: newPath,
|
|
|
|
seedName,
|
2023-09-03 17:06:33 +08:00
|
|
|
title: `${vinfo.rename} ${vinfo.year} S${addZeor(vinfo.season)}Epxxx WEB-DL ${fbl}p ${Video.Format} ${Audio.Format}-ZmWeb`,
|
2023-07-23 01:03:29 +08:00
|
|
|
Duration: Video.Duration,
|
2023-07-31 22:03:45 +08:00
|
|
|
rname,
|
|
|
|
ep: addZeor(dinfo.title),
|
|
|
|
fbl
|
2023-07-23 01:03:29 +08:00
|
|
|
}
|
|
|
|
}
|
2023-07-31 22:03:45 +08:00
|
|
|
} else {
|
2023-07-22 23:04:26 +08:00
|
|
|
console.log("未找到当前剧集信息")
|
2023-07-31 22:03:45 +08:00
|
|
|
return {
|
2023-07-23 01:03:29 +08:00
|
|
|
state: 0
|
|
|
|
}
|
2023-07-22 23:04:26 +08:00
|
|
|
}
|
2023-07-31 22:03:45 +08:00
|
|
|
|
2023-07-22 23:04:26 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-07-31 22:41:42 +08:00
|
|
|
function dowv(dinfo){
|
|
|
|
return new Promise((res)=>{
|
2023-07-31 22:03:45 +08:00
|
|
|
dow(dinfo, async (msg, s) => {
|
2023-07-22 23:04:26 +08:00
|
|
|
console.log(String(msg))
|
2023-07-31 22:03:45 +08:00
|
|
|
if (s) {
|
2023-07-22 23:04:26 +08:00
|
|
|
let exist = fileIsExist(dinfo.save + "/" + dinfo.title + ".mp4")
|
2023-07-31 22:03:45 +08:00
|
|
|
if (exist) {
|
2023-07-22 23:04:26 +08:00
|
|
|
// 设置状态
|
|
|
|
let s = await reName(dinfo)
|
2023-07-31 22:03:45 +08:00
|
|
|
await setDownState(dinfo.id, s.state)
|
2023-07-22 23:04:26 +08:00
|
|
|
state = false
|
2023-07-31 22:03:45 +08:00
|
|
|
if (s.info) {
|
2023-07-31 22:41:42 +08:00
|
|
|
await sendSeed(s.info)
|
2023-07-23 01:03:29 +08:00
|
|
|
}
|
2023-07-31 22:41:42 +08:00
|
|
|
res(s)
|
2023-07-31 22:03:45 +08:00
|
|
|
} else {
|
2023-07-22 23:04:26 +08:00
|
|
|
// 重新下载
|
|
|
|
console.log("下载失败重新下载")
|
|
|
|
state = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2023-07-31 22:41:42 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 当前下载状态
|
|
|
|
let state = false
|
|
|
|
async function CheckDown() {
|
|
|
|
if (state) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let list = await getDownList()
|
|
|
|
if (list.length > 0) {
|
|
|
|
state = true
|
|
|
|
let dinfo = list[0]
|
|
|
|
mkdirRecursions(dinfo.save)
|
|
|
|
await dowv(dinfo)
|
2023-07-22 23:04:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("定时检测下载")
|
|
|
|
// 设置定时器 每分钟检测更新
|
|
|
|
let job = schedule.scheduleJob('* * * * * *', () => {
|
|
|
|
CheckDown()
|
|
|
|
});
|