add 优化代码,新增获取腾讯视频播放列表

This commit is contained in:
SummerTail 2023-07-03 12:04:52 +08:00
parent 0c010beb54
commit b48ccbf84d
5 changed files with 45 additions and 26 deletions

Binary file not shown.

View File

@ -18,6 +18,7 @@
"koa-sse-stream": "^0.2.0", "koa-sse-stream": "^0.2.0",
"koa-static": "^5.0.0", "koa-static": "^5.0.0",
"koa-websocket": "^7.0.0", "koa-websocket": "^7.0.0",
"process": "^0.11.10",
"puppeteer": "^20.7.1", "puppeteer": "^20.7.1",
"sqlite3": "^5.1.6" "sqlite3": "^5.1.6"
}, },
@ -41,4 +42,4 @@
"output": "./dist" "output": "./dist"
} }
} }
} }

View File

@ -4,10 +4,9 @@ const utils = require("../util/utils")
const KoaSSEStream = require('koa-sse-stream'); const KoaSSEStream = require('koa-sse-stream');
const {dowload} = require("../util/download"); const {dowload} = require("../util/download");
const {addDownList, getDownList, setDownState} = require("../util/sql/download"); const {addDownList, getDownList, setDownState} = require("../util/sql/download");
const dayjs = require("dayjs")
const {getMediaInfo} = require("../util/utils"); const {getMediaInfo} = require("../util/utils");
const router = new Router() const router = new Router()
// const dowloadlist = [] // const download = []
router.get("/getMediaInfo", async (ctx) => { router.get("/getMediaInfo", async (ctx) => {
let url = ctx.query.filePath let url = ctx.query.filePath
@ -26,22 +25,21 @@ router.get("/getMediaInfo", async (ctx) => {
router.get("/getQqList", async (ctx) => { router.get("/getQqList", async (ctx) => {
let url = ctx.query.url let url = ctx.query.url
let videoid = url.split("/") let video_id = url.split("/")
for (let i in videoid) { for (let i in video_id) {
if (videoid[i] == "cover") { if (video_id[i] === "cover") {
videoid = videoid[i + 1].replace(".html") video_id = video_id[i + 1].replace(".html")
break break
} }
} }
let list = await getQqListData(url) ctx.body = await getQqListData(url)
ctx.body = list
}) })
router.get("/startDown", async (ctx) => { router.get("/startDown", async (ctx) => {
let title = ctx.query.title let title = ctx.query.title
let url = ctx.query.url let url = ctx.query.url
let save = ctx.query.save let save = ctx.query.save
// dowloadlist.push({ // download.push({
// title,url,save // title,url,save
// }) // })
// startDown() // startDown()
@ -53,7 +51,12 @@ router.get("/startDown", async (ctx) => {
}) })
router.get("/test", async (ctx) => { router.get("/test", async (ctx) => {
utils.getVideoSpecifyTimeImage("D:/aaa/梦中的那片海/梦中的那片海 第01集.mp4", 46, "D:/aaa/梦中的那片海/aaa.jpg") let rep = await utils.getTencentVideoPlayList('mzc00200t7i1qwp')
ctx.body = {
code: 0,
msg: "test",
data: rep
}
}) })
@ -92,9 +95,9 @@ function startDown(data) {
setInterval(async () => { setInterval(async () => {
let dowloadlist = await getDownList() let dowloadlist = await getDownList()
if (dowloadlist.length != 0 && !start) { if (dowloadlist.length !== 0 && !start) {
startDown(dowloadlist[0]) startDown(dowloadlist[0])
} else if (dowloadlist.length == 0) { } else if (dowloadlist.length === 0) {
start = false start = false
} }
}, 1000) }, 1000)

View File

@ -22,7 +22,7 @@ async function getQqListData(url) {
console.log(list) console.log(list)
for (let i of list) { for (let i of list) {
if (i && i.innerText) { if (i && i.innerText) {
if ("全部" == i.innerText.trim()) { if ("全部" === i.innerText.trim()) {
i.click() i.click()
} }
} }

View File

@ -1,6 +1,6 @@
const {spawn} = require('child_process'); const {spawn} = require('child_process');
const path = require('path'); const path = require('path');
const { cwd } = require('process'); const {cwd} = require('process');
function seep(time) { function seep(time) {
@ -11,19 +11,33 @@ function seep(time) {
}) })
} }
/**
* 获取腾讯视频播放列表
* @param {String}cid 视频id
* @returns {JSON} 播放列表等参数
*/
function getTencentVideoPlayList(cid) {
return new Promise((resolve) => {
const lux = spawn("./bin/getTencentVideoPlayList.exe", [cid, 'vversion_name=8.2.95;', 1])
lux.stdout.on('data', (data) => {
resolve(JSON.parse(String(data)))
});
})
}
/** /**
* 获取视频截图 (目前不可用,不好使) * 获取视频截图
* @param {String} filePath 文件绝对路径 * @param {String} filePath 文件绝对路径
* @param {number} seconds 时间 * @param {number} seconds 时间
* @param {Promise<String>} save 保存绝对路径(含文件名) * @param {string} save 保存绝对路径(含文件名)
* @returns {Promise<String>} 文件位置(待定) * @returns {Promise<String>} 文件位置(待定)
*/ */
function getVideoSpecifyTimeImage(filePath, seconds, save) { function getVideoSpecifyTimeImage(filePath, seconds, save) {
return new Promise((resolve) => { return new Promise((resolve) => {
const lux = spawn("ffmpeg", ['-ss',`${formatSeconds(seconds)}`,'-i',filePath,'-vframes','1',save],{ const lux = spawn("ffmpeg", ['-ss', `${formatSeconds(seconds)}`, '-i', filePath, '-vframes', '1', save], {
env:{ env: {
path:path.join(cwd(),'./bin/') path: path.join(cwd(), './bin/')
} }
}) })
lux.stdout.on('data', (data) => { lux.stdout.on('data', (data) => {
@ -34,7 +48,7 @@ function getVideoSpecifyTimeImage(filePath, seconds, save) {
console.log(code.toString()) console.log(code.toString())
resolve(save) resolve(save)
}); });
lux.stderr.on("data",(err)=>{ lux.stderr.on("data", (err) => {
console.log(String(err)) console.log(String(err))
}) })
console.log(lux) console.log(lux)
@ -68,7 +82,7 @@ function createTorrent(filePath, save) {
lux.stdout.on('data', (data) => { lux.stdout.on('data', (data) => {
response += data response += data
}); });
lux.stdout.on('close', (code) => { lux.stdout.on('close', () => {
resolve(response) resolve(response)
}) })
}) })
@ -76,9 +90,9 @@ function createTorrent(filePath, save) {
function dow(info, callback) { function dow(info, callback) {
const lux = spawn("yt-dlp", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url],{ const lux = spawn("yt-dlp", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url], {
env:{ env: {
path:path.join(cwd(),'./bin/') path: path.join(cwd(), './bin/')
} }
}) })
lux.stdout.on('data', (data) => { lux.stdout.on('data', (data) => {
@ -133,5 +147,6 @@ module.exports = {
dow, dow,
getVideoSpecifyTimeImage, getVideoSpecifyTimeImage,
getMediaInfo, getMediaInfo,
createTorrent createTorrent,
getTencentVideoPlayList
} }