82 lines
1.8 KiB
JavaScript
82 lines
1.8 KiB
JavaScript
const Router = require("koa-router")
|
|
const { serach, gen_douban } = require("../util/ptgen")
|
|
const axios = require("axios")
|
|
const cheerio = require("cheerio");
|
|
const {addSub, getSub, delSub} = require("../util/sql/video"); // HTML页面解析
|
|
|
|
const router = new Router({
|
|
prefix: "/videoInfo"
|
|
})
|
|
|
|
|
|
router.get("/search", async (ctx) => {
|
|
let name = ctx.query.name
|
|
ctx.body = await serach(name)
|
|
})
|
|
|
|
// router.get("/getinfo",async (ctx)=>{
|
|
// let url = ctx.query.url
|
|
// let info = await getinfo(url)
|
|
// ctx.body = info
|
|
// })
|
|
|
|
router.get("/searchVideo", async (ctx) => {
|
|
let name = ctx.query.name
|
|
ctx.body = await serach(name)
|
|
|
|
})
|
|
|
|
router.get("/getVideoInfo", async (ctx) => {
|
|
let id = ctx.query.id
|
|
if (!id) {
|
|
ctx.body = "请传递id"
|
|
return
|
|
}
|
|
ctx.body = await gen_douban(id)
|
|
|
|
})
|
|
|
|
router.post("/addSubscribe", async (ctx) => {
|
|
// console.log(ctx.request.body)
|
|
let data = ctx.request.body
|
|
try {
|
|
let r = await addSub(data)
|
|
if(r){
|
|
ctx.body = "订阅已存在"
|
|
}else{
|
|
ctx.body = "添加成功"
|
|
}
|
|
}catch {
|
|
ctx.body = "添加失败"
|
|
}
|
|
|
|
})
|
|
|
|
router.get("/getSubscribe",async (ctx)=>{
|
|
let list = await getSub()
|
|
ctx.body = list
|
|
})
|
|
|
|
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()
|
|
})
|
|
|
|
router.get("/delSubscribe",async (ctx)=>{
|
|
try {
|
|
await delSub(ctx.query.id)
|
|
ctx.body = "删除成功"
|
|
}catch {
|
|
ctx.body = "删除失败"
|
|
}
|
|
})
|
|
|
|
module.exports = router |