add 订阅自动检查更新
This commit is contained in:
38
util/Video/Update.js
Normal file
38
util/Video/Update.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const schedule = require('node-schedule');
|
||||
const { getSub,updateSkip } = require('../sql/video');
|
||||
const { getQqListData } = require("../getList/qq.js")
|
||||
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 list = await getQqListData(cid)
|
||||
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 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]) {
|
||||
addDown(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log("开始定时检测更新")
|
||||
// 设置定时器 每分钟检测更新
|
||||
let job = schedule.scheduleJob('0 * * * * *', () => {
|
||||
CheckUpdate()
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
const puppeteer = require("puppeteer")
|
||||
const { seep } = require("../utils.js");
|
||||
|
||||
async function getQqListData(url) {
|
||||
const { seep, spawn } = require("../utils.js");
|
||||
// 无头浏览器模式 暂时禁用
|
||||
async function getQqListDataBack(url) {
|
||||
const browser = await puppeteer.launch({
|
||||
// 关闭无头模式,方便我们看到这个无头浏览器执行的过程
|
||||
headless: false,
|
||||
@@ -85,6 +85,24 @@ async function getQqListData(url) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getQqListData(cid){
|
||||
return new Promise((resolve) => {
|
||||
const lux = spawn("getTencentVideoPlayList", [cid, 'vversion_name=8.2.95;', 1])
|
||||
lux.stdout.on('data', (data) => {
|
||||
resolve(JSON.parse(String(data)))
|
||||
});
|
||||
lux.stderr.on("data",(a)=>{
|
||||
console.log(a)
|
||||
})
|
||||
lux.stdout.on("error",(err)=>{
|
||||
console.log(err)
|
||||
})
|
||||
lux.stderr.on("error",(err)=>{
|
||||
console.log(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
getQqListData
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
const { run, getAll } = require("./base");
|
||||
|
||||
function addDownList(title,url,save,downDate,isOk,vid){
|
||||
let sql = `insert into download(title,url,save,downDate,isOk,vid) values(?,?,?,?,?,?)`
|
||||
run(sql,title,url,save,downDate,isOk,vid)
|
||||
// state 0未下载 1下载完成 2已发种
|
||||
function addDownList(title,url,save,downDate,state,vid){
|
||||
let sql = `insert into download(title,url,save,downDate,state,vid) values(?,?,?,?,?,?)`
|
||||
run(sql,title,url,save,downDate,state,vid)
|
||||
}
|
||||
|
||||
async function getDownList(){
|
||||
|
||||
@@ -12,20 +12,29 @@ async function addSub(info){
|
||||
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)
|
||||
}
|
||||
|
||||
// 获取所有订阅 (不包括已完成)
|
||||
async function getSub(){
|
||||
let sql = `select * from VideoInfo`
|
||||
let sql = `select * from VideoInfo where enable=1`
|
||||
let list = await getAll(sql)
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function delSub(id){
|
||||
let sql = `delete from VideoInfo where id=${id}`
|
||||
await run(sql)
|
||||
}
|
||||
|
||||
async function updateSkip(num,id){
|
||||
let sql = `update VideoInfo set skip=${num} where id=${id}`
|
||||
await run(sql)
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
addSub,
|
||||
getSub,
|
||||
delSub
|
||||
delSub,
|
||||
updateSkip
|
||||
}
|
||||
@@ -1,10 +1,22 @@
|
||||
const { spawn } = require('child_process');
|
||||
const { spawn: spawn2 } = require('child_process');
|
||||
const path = require('path');
|
||||
const { cwd } = require('process');
|
||||
const { readFile, createReadStream } = require("fs");
|
||||
const { post } = require("axios");
|
||||
const https = require('https')
|
||||
|
||||
// 设置环境变量为自带的bin
|
||||
function spawn(exe, arg, config) {
|
||||
if (!config) {
|
||||
config = {}
|
||||
}
|
||||
config.env = {
|
||||
path: [path.join(cwd(), '/bin'), path.join(cwd(), '/bin/MediaInfoCLI'), path.join(cwd(), '/bin/Transmission')].join(";")
|
||||
}
|
||||
|
||||
return spawn2(exe, arg, config)
|
||||
}
|
||||
|
||||
function seep(time) {
|
||||
return new Promise((res) => {
|
||||
setTimeout(() => {
|
||||
@@ -22,16 +34,16 @@ async function uploadImg(filePath) {
|
||||
console.log(data)
|
||||
try {
|
||||
let res = await post('https://image.zmpt.cc/upload/localhost', {
|
||||
file:data
|
||||
},{
|
||||
file: data
|
||||
}, {
|
||||
proxy: false,
|
||||
headers:{
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
console.log(res)
|
||||
return res.data
|
||||
}catch(err){
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return err
|
||||
}
|
||||
@@ -45,7 +57,7 @@ async function uploadImg(filePath) {
|
||||
*/
|
||||
function getTencentVideoPlayList(cid) {
|
||||
return new Promise((resolve) => {
|
||||
const lux = spawn("./bin/getTencentVideoPlayList.exe", [cid, 'vversion_name=8.2.95;', 1])
|
||||
const lux = spawn("getTencentVideoPlayList.exe", [cid, 'vversion_name=8.2.95;', 1])
|
||||
lux.stdout.on('data', (data) => {
|
||||
resolve(JSON.parse(String(data)))
|
||||
});
|
||||
@@ -89,7 +101,7 @@ function getVideoSpecifyTimeImage(filePath, seconds, save) {
|
||||
*/
|
||||
function getMediaInfo(filePath) {
|
||||
return new Promise((resolve) => {
|
||||
const lux = spawn("./bin/MediaInfoCLI/MediaInfo.exe", ['--output=JSON', filePath])
|
||||
const lux = spawn("MediaInfo.exe", ['--output=JSON', filePath])
|
||||
lux.stdout.on('data', (data) => {
|
||||
resolve(JSON.parse(data))
|
||||
});
|
||||
@@ -104,7 +116,7 @@ function getMediaInfo(filePath) {
|
||||
*/
|
||||
function createTorrent(filePath, save) {
|
||||
return new Promise((resolve) => {
|
||||
const lux = spawn("./bin/Transmission/transmission-create", [filePath, '-p', '-t https://zmpt.cc/announce.php', '-o', save])
|
||||
const lux = spawn("transmission-create", [filePath, '-p', '-t https://zmpt.cc/announce.php', '-o', save])
|
||||
let response = '';
|
||||
lux.stdout.on('data', (data) => {
|
||||
response += data
|
||||
@@ -176,5 +188,6 @@ module.exports = {
|
||||
getMediaInfo,
|
||||
createTorrent,
|
||||
getTencentVideoPlayList,
|
||||
uploadImg
|
||||
uploadImg,
|
||||
spawn
|
||||
}
|
||||
Reference in New Issue
Block a user