2023-06-20 22:34:27 +08:00
|
|
|
const Router = require("koa-router")
|
2023-07-05 20:36:42 +08:00
|
|
|
const { serach, gen_douban } = require("../util/ptgen")
|
2023-07-11 20:52:30 +08:00
|
|
|
const axios = require("axios")
|
2023-07-12 20:41:05 +08:00
|
|
|
const cheerio = require("cheerio");
|
2023-07-13 10:05:32 +08:00
|
|
|
const {addSub, getSub, delSub} = require("../util/sql/video"); // HTML页面解析
|
2023-06-20 22:34:27 +08:00
|
|
|
|
|
|
|
const router = new Router({
|
2023-07-11 20:52:30 +08:00
|
|
|
prefix: "/videoInfo"
|
2023-06-20 22:34:27 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
router.get("/search", async (ctx) => {
|
2023-06-20 22:34:27 +08:00
|
|
|
let name = ctx.query.name
|
2023-07-07 15:54:38 +08:00
|
|
|
ctx.body = await serach(name)
|
2023-06-20 22:34:27 +08:00
|
|
|
})
|
|
|
|
|
2023-07-05 20:36:42 +08:00
|
|
|
// router.get("/getinfo",async (ctx)=>{
|
|
|
|
// let url = ctx.query.url
|
|
|
|
// let info = await getinfo(url)
|
|
|
|
// ctx.body = info
|
|
|
|
// })
|
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
router.get("/searchVideo", async (ctx) => {
|
2023-07-05 20:36:42 +08:00
|
|
|
let name = ctx.query.name
|
2023-07-07 15:54:38 +08:00
|
|
|
ctx.body = await serach(name)
|
2023-07-05 20:36:42 +08:00
|
|
|
|
|
|
|
})
|
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
router.get("/getVideoInfo", async (ctx) => {
|
2023-07-05 20:36:42 +08:00
|
|
|
let id = ctx.query.id
|
2023-07-11 20:52:30 +08:00
|
|
|
if (!id) {
|
2023-07-05 20:36:42 +08:00
|
|
|
ctx.body = "请传递id"
|
|
|
|
return
|
|
|
|
}
|
2023-07-07 15:54:38 +08:00
|
|
|
ctx.body = await gen_douban(id)
|
2023-07-05 20:36:42 +08:00
|
|
|
|
2023-06-20 22:34:27 +08:00
|
|
|
})
|
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
router.post("/addSubscribe", async (ctx) => {
|
|
|
|
// console.log(ctx.request.body)
|
|
|
|
let data = ctx.request.body
|
2023-07-12 20:41:05 +08:00
|
|
|
try {
|
|
|
|
let r = await addSub(data)
|
|
|
|
if(r){
|
|
|
|
ctx.body = "订阅已存在"
|
|
|
|
}else{
|
|
|
|
ctx.body = "添加成功"
|
|
|
|
}
|
|
|
|
}catch {
|
|
|
|
ctx.body = "添加失败"
|
|
|
|
}
|
2023-07-12 16:21:57 +08:00
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
})
|
|
|
|
|
2023-07-13 09:44:47 +08:00
|
|
|
router.get("/getSubscribe",async (ctx)=>{
|
|
|
|
let list = await getSub()
|
|
|
|
ctx.body = list
|
|
|
|
})
|
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
router.get("/getImdbName", async (ctx) => {
|
|
|
|
let res = await axios.get(ctx.query.url, {
|
|
|
|
proxy: false,
|
|
|
|
headers:{
|
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// console.log(res.data)
|
|
|
|
let $ = cheerio.load(res.data)
|
|
|
|
ctx.body = $("h1").text()
|
|
|
|
})
|
|
|
|
|
2023-07-13 10:05:32 +08:00
|
|
|
router.get("/delSubscribe",async (ctx)=>{
|
|
|
|
try {
|
|
|
|
await delSub(ctx.query.id)
|
|
|
|
ctx.body = "删除成功"
|
|
|
|
}catch {
|
|
|
|
ctx.body = "删除失败"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-06-20 22:34:27 +08:00
|
|
|
module.exports = router
|