ptSend/util/Video/Update.js

50 lines
1.6 KiB
JavaScript

const schedule = require('node-schedule');
const { getSub,updateSkip } = require('../sql/video');
const { getQqListData } = require("../getList/qq.js")
const { addDownList } = require("../sql/download.js");
const { getConfig } = require('../config/config');
// 检查更新并将更新推送下载
async function addDown(i) {
// 判断视频网站
if (i.url.indexOf("v.qq.com") != -1) {
let cid = i.url.split("/")[5].replace(".html","")
console.log(cid)
let list = await getQqListData(cid)
console.log(list)
list = list.item_datas
let newlist = []
for(let i in list){
if(!isNaN(Number(list[i].item_params.title))){
newlist.push(list[i])
}
}
for (let j = i.skip - 1; j < newlist.length; j++) {
let v = newlist[j]
await addDownList(v.item_params.title, `https://v.qq.com/x/cover/${cid}/${v.item_params.vid}.html`, `${getConfig().downloadPath}/${i.sid}`, new Date().getTime(), 0, i.sid)
}
await updateSkip(list.length + 1,i.id)
// console.log(JSON.stringify(list))
}
}
async function CheckUpdate() {
let date = new Date()
let hours = date.getHours()
let minutes = date.getMinutes()
let all = await getSub()
for (let i of all) {
let time = i.time.split(":")
if (hours == time[0] && minutes == time[1] || global.start) {
addDown(i)
}
}
global.start = false
}
console.log("开始定时检测更新")
// 设置定时器 每分钟检测更新
global.start = false
let job = schedule.scheduleJob('0 * * * * *', () => {
CheckUpdate()
});