ptSend/router/videoInfo.js
2023-07-11 20:52:30 +08:00

56 lines
1.3 KiB
JavaScript

const Router = require("koa-router")
const { serach, gen_douban } = require("../util/ptgen")
const axios = require("axios")
const cheerio = require("cheerio"); // 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
})
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()
})
module.exports = router