ptSend/util/sql/download.js
2023-08-09 12:28:28 +08:00

94 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { run, getAll } = require("./base");
// 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(){
let sql = `select * from download where state == 0`
try{
let list = await getAll(sql)
return list
}catch(err){
console.error(err)
return []
}
}
async function setDownState(id,state){
let sql = `update download set state = ? where id = ?`
await run(sql,state,id)
}
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){
}
// 获取当前剧集是否下载完成
// todo 多集连发
async function getMediaState(vid){
let sql = `select * from download where vid=? and (state=0 or state=3)`
let list = await getAll(sql,vid)
return !list.length
// return true
}
/**
* 获取下载的ep开始与结束
* @param {string} vid 视频vid
* @returns {{start:string,end:string}} start开始集数end结束集数
*/
async function getDownEp(vid){
let sql = `select * from download where vid=? and (state=3 OR state=0)`
let list = await getAll(sql,vid)
console.log(vid,list)
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)
}
module.exports = {
addDownList,
getDownList,
setDownState,
getMediaState,
getDownEp,
setDownStateVid
}