ptSend/util/sql/video.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-07-12 16:21:57 +08:00
const { run, getAll } = require("./base");
2023-07-12 20:41:05 +08:00
const dayjs = require("dayjs");
2023-07-12 16:21:57 +08:00
2023-07-12 20:41:05 +08:00
async function addSub(info){
2023-07-12 16:21:57 +08:00
2023-07-12 20:41:05 +08:00
let selSql = `select * from VideoInfo where sid='${info.sid}' and season=${info.season}`
let list = await getAll(selSql)
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,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)
2023-07-13 09:44:47 +08:00
}
2023-07-22 15:56:26 +08:00
// 获取所有订阅 (不包括已完成)
2023-07-13 09:44:47 +08:00
async function getSub(){
2023-07-22 15:56:26 +08:00
let sql = `select * from VideoInfo where enable=1`
2023-07-13 09:44:47 +08:00
let list = await getAll(sql)
return list
2023-07-12 20:41:05 +08:00
}
2023-07-22 15:56:26 +08:00
2023-07-13 10:05:32 +08:00
async function delSub(id){
let sql = `delete from VideoInfo where id=${id}`
await run(sql)
}
2023-07-22 15:56:26 +08:00
async function updateSkip(num,id){
let sql = `update VideoInfo set skip=${num} where id=${id}`
await run(sql)
2023-08-22 15:00:31 +08:00
// 清理完成的订阅
await updateState(id)
}
// skip = 总集数 设置完成
async function updateState(id){
2023-09-03 17:22:27 +08:00
let info = await getVideoInfoById(id)
console.log(JSON.stringify(info))
2023-08-22 15:03:34 +08:00
if(info.skip > info.count){
2023-08-22 15:00:31 +08:00
let sql = `update VideoInfo set enable=2 where id=${id}`
await run(sql)
}
2023-07-22 15:56:26 +08:00
}
2023-07-22 23:04:26 +08:00
// 通过sid获取媒体信息
async function getVideoInfo(sid){
let sql = `select * from VideoInfo where sid=?`
let info = await getAll(sql,sid)
if(info.length > 0){
return info[0]
}else{
return false
}
}
2023-08-22 15:00:31 +08:00
// 通过id获取媒体信息
async function getVideoInfoById(id){
let sql = `select * from VideoInfo where id=?`
let info = await getAll(sql,id)
if(info.length > 0){
return info[0]
}else{
return false
}
}
2023-07-12 20:41:05 +08:00
module.exports = {
2023-07-13 09:44:47 +08:00
addSub,
2023-07-13 10:05:32 +08:00
getSub,
2023-07-22 15:56:26 +08:00
delSub,
2023-07-22 23:04:26 +08:00
updateSkip,
getVideoInfo
2023-07-12 16:21:57 +08:00
}