ptSend/util/sql/download.js

94 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-06-28 21:11:21 +08:00
const { run, getAll } = require("./base");
2023-06-20 22:34:27 +08:00
2023-07-22 15:56:26 +08:00
// 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)
2023-06-28 21:11:21 +08:00
}
async function getDownList(){
2023-07-22 23:04:26 +08:00
let sql = `select * from download where state == 0`
2023-06-28 21:11:21 +08:00
try{
let list = await getAll(sql)
return list
}catch(err){
console.error(err)
return []
}
}
async function setDownState(id,state){
2023-07-22 23:04:26 +08:00
let sql = `update download set state = ? where id = ?`
2023-06-28 21:11:21 +08:00
await run(sql,state,id)
}
2023-06-29 21:59:57 +08:00
async function getVideoInfo(url){
if(url){
let sql = `select * from VideoInfo where url = '?'`
let list = await getAll(sql,url)
}else{
let sql = `insert into `
}
}
async function addVideoInfo(cover){
}
2023-07-23 01:03:29 +08:00
// 获取当前剧集是否下载完成
// todo 多集连发
2023-07-23 01:03:29 +08:00
async function getMediaState(vid){
2023-08-07 22:05:55 +08:00
let sql = `select * from download where vid=? and state!=1`
let list = await getAll(sql,vid)
return !list.length
// return true
2023-07-23 01:03:29 +08:00
}
2023-08-08 20:16:09 +08:00
/**
* 获取下载的ep开始与结束
* @param {string} vid 视频vid
* @returns {{start:string,end:string}} start开始集数end结束集数
*/
async function getDownEp(vid){
2023-08-08 20:47:46 +08:00
let sql = `select * from download where vid=? and (state=3 OR state=0)`
2023-08-08 20:16:09 +08:00
let list = await getAll(sql,vid)
2023-08-08 20:47:46 +08:00
console.log(vid,list)
2023-08-08 20:16:09 +08:00
if(list.length == 0){
let sql = `select * from download where vid=? and state=1`
let list = await getAll(sql,vid)
let ep = []
for(let i of list){
ep.push(parseInt(i.title))
}
ep.sort((a,b)=>{
return a - b
})
return {
start: ep[0],
end:ep[ep.length - 1]
}
}else{
return false
}
}
/**
* 通过vid设置下载状态
* @param {string} vid 视频vid
* @param {number} state 状态
*/
async function setDownStateVid(vid,state){
let sql = `update download set state = ? where vid = ?`
await run(sql,state,vid)
}
2023-06-28 21:11:21 +08:00
module.exports = {
addDownList,
getDownList,
2023-07-23 01:03:29 +08:00
setDownState,
2023-08-08 20:16:09 +08:00
getMediaState,
getDownEp,
setDownStateVid
2023-06-20 22:34:27 +08:00
}