2023-06-20 22:34:27 +08:00
|
|
|
const Router = require("koa-router")
|
2023-08-07 22:05:55 +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-08-03 21:41:18 +08:00
|
|
|
/**
|
|
|
|
* 豆瓣搜索
|
|
|
|
*/
|
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-08-07 22:05:55 +08:00
|
|
|
ctx.body = await serach(name)
|
2023-07-05 20:36:42 +08:00
|
|
|
|
|
|
|
})
|
|
|
|
|
2023-08-03 21:41:18 +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-08-03 21:41:18 +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)
|
2023-08-03 21:41:18 +08:00
|
|
|
if (r) {
|
2023-07-12 20:41:05 +08:00
|
|
|
ctx.body = "订阅已存在"
|
2023-08-03 21:41:18 +08:00
|
|
|
} else {
|
2023-07-12 20:41:05 +08:00
|
|
|
ctx.body = "添加成功"
|
|
|
|
}
|
2023-08-03 21:41:18 +08:00
|
|
|
} catch {
|
2023-07-12 20:41:05 +08:00
|
|
|
ctx.body = "添加失败"
|
|
|
|
}
|
2023-07-12 16:21:57 +08:00
|
|
|
|
2023-07-11 20:52:30 +08:00
|
|
|
})
|
|
|
|
|
2023-08-03 21:41:18 +08:00
|
|
|
/**
|
|
|
|
* 获取订阅列表
|
|
|
|
*/
|
|
|
|
router.get("/getSubscribe", async (ctx) => {
|
2023-09-03 21:10:55 +08:00
|
|
|
ctx.body = await getSub(ctx.query.state)
|
2023-07-13 09:44:47 +08:00
|
|
|
})
|
|
|
|
|
2023-08-03 21:41:18 +08:00
|
|
|
/**
|
|
|
|
* 从imdb获取影视英文名称
|
|
|
|
*/
|
2023-07-11 20:52:30 +08:00
|
|
|
router.get("/getImdbName", async (ctx) => {
|
|
|
|
let res = await axios.get(ctx.query.url, {
|
|
|
|
proxy: false,
|
2023-08-03 21:41:18 +08:00
|
|
|
headers: {
|
2023-07-11 20:52:30 +08:00
|
|
|
"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-08-03 21:41:18 +08:00
|
|
|
/**
|
|
|
|
* 删除订阅任务
|
|
|
|
*/
|
|
|
|
router.get("/delSubscribe", async (ctx) => {
|
2023-07-13 10:05:32 +08:00
|
|
|
try {
|
|
|
|
await delSub(ctx.query.id)
|
2023-08-03 21:41:18 +08:00
|
|
|
ctx.body = {
|
|
|
|
code: 0,
|
|
|
|
msg: "删除成功"
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
ctx.body = {
|
|
|
|
code: 0,
|
|
|
|
msg: "删除失败"
|
|
|
|
}
|
2023-07-13 10:05:32 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-08-03 21:41:18 +08:00
|
|
|
module.exports = router
|