ptSend/router/videoInfo.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

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")
const cheerio = require("cheerio"); // 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
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
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
}
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
})
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-06-20 22:34:27 +08:00
module.exports = router