799967501@qq.com

完善版本

{
"GETCLASSURL":"http://139.196.126.156:8081/getLogs/recordClassList",
"GETCLASSURLPARAMETER":{
"siteId":["beidatest","funexenglish"],
"key":"xdymp4record20191225",
"page":1,
"maxMedia":1
},
"PROJECTWINCATALOG":"F:/project/web_capture_release/win-x64",
"PROJECTCATALOG":"F:/project/web_capture_release",
"BACKMEDIACONFIG":{
"url" : "https://pclive.xuedianyun.com/pcBase/pclive2/dev/index.html",
"recordMp4":true,
"classId":"",
"userId":0,
"userName":"",
"userRole":"normal",
"portalIP":"saas.xuedianyun.com",
"portalPort":80,
"channels":2,
"playRecord":1,
"d":21600000,
"s":3000,
"fa":15,
"k":0,
"w":1280,
"h":720
}
}
\ No newline at end of file
"GETCLASSURL": "http://139.196.126.156:8081/getLogs/recordClassList",
"GETCLASSURLPARAMETER": {
"siteId": [],
"key": "xdymp4record20191225",
"page": 1,
"maxMedia": 1
},
"PROJECTWINCATALOG": "F:/project/web_capture_release/win-x64",
"PROJECTCATALOG": "F:/project/web_capture_release",
"BACKMEDIACONFIG": {
"url": "https://pclive.xuedianyun.com/pcBase/pclive2/dev/index.html",
"recordMp4": true,
"classId": "",
"userId": 0,
"userName": "",
"userRole": "normal",
"portalIP": "saas.xuedianyun.com",
"portalPort": 80,
"channels": 2,
"playRecord": 1,
"d": 21600000,
"s": 3000,
"fa": 15,
"k": 0,
"w": 1280,
"h": 720
}
}
... ...
var express = require('express');
var router = express.Router();
const {spawn, exec} = require('child_process');
const { spawn, exec } = require('child_process');
const fs = require("fs");
var path = require('path')
... ... @@ -8,7 +8,7 @@ const method = require("../config/method")
const config = require("../config/config")
// const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config
const {YesterdayTime, getRequestClassIds, dayTimeYMD} = method
const { YesterdayTime, getRequestClassIds, dayTimeYMD } = method
let siteIds = []
... ... @@ -29,11 +29,11 @@ class MediaCreat {
// 取出所有数据
async allData() {
const {startTime, endTime} = YesterdayTime()
const { startTime, endTime } = YesterdayTime()
let fileConfig = new MediaCreat().getConfigFileJson()
if (!fileConfig) return false
className = siteIds.shift()
const {GETCLASSURL, GETCLASSURLPARAMETER} = JSON.parse(fileConfig)
const { GETCLASSURL, GETCLASSURLPARAMETER } = JSON.parse(fileConfig)
let page = 1
if (className) {
let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page)
... ... @@ -42,7 +42,7 @@ class MediaCreat {
classid.push(result.data.data.list[j])
parentData[result.data.data.siteId].add(result.data.data.list[j]['classId'])
}
const {siteId, list, totalPage} = result.data.data
const { siteId, list, totalPage } = result.data.data
for (let i = page += 1; i <= totalPage; i++) {
let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i)
for (let j = 0; j < result.data.data.list.length; j++) {
... ... @@ -123,7 +123,7 @@ class MediaCreat {
this.wrieLog(" 课堂录制开始:------>" + id)
let fileConfig = this.getConfigFileJson()
if (!fileConfig) return false
const {BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG} = JSON.parse(fileConfig)
const { BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG } = JSON.parse(fileConfig)
let mediaDir = PROJECTCATALOG + "/media/"
let classDir = PROJECTCATALOG + "/media/" + siteId
let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd
... ... @@ -140,73 +140,73 @@ class MediaCreat {
// export DISPLAY=:7
// let url = `${path.resolve(__dirname, PROJECTWINCATALOG+"/web_capture_c")} -o=${ymdDir}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa} -k=${BACKMEDIACONFIG.k} -w=${BACKMEDIACONFIG.w} -h=${BACKMEDIACONFIG.h}`
// console.log("url", url)
let url = `${PROJECTWINCATALOG}/web_capture_c -o=${ymdDir}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa} -k=${BACKMEDIACONFIG.k} -w=${BACKMEDIACONFIG.w} -h=${BACKMEDIACONFIG.h} -k=0`
let url = `${PROJECTWINCATALOG}/web_capture_c -o=${ymdDir}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}&language=zh-cn" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa} -k=${BACKMEDIACONFIG.k} -w=${BACKMEDIACONFIG.w} -h=${BACKMEDIACONFIG.h}`
// console.log("url", url)
// console.log("PROJECTWINCATALOG", PROJECTWINCATALOG)
exec(url, {maxBuffer:1073741824},(err, stdout, stderr) => {
exec(url, { maxBuffer: 1073741824 }, (err, stdout, stderr) => {
// setTimeout(()=>{
if (err != null) {
this.wrieLog(" 错误" + id +":" + err)
this.wrieLog(" 错误 stdout" + id +":" + stdout)
this.wrieLog(" 错误 stderr" + id +":" + stderr)
// if (files.indexOf(id + ".mp4") == -1) {
// // //当前课堂没有写入到文件夹,进入重录
// this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
// this.recordingCreat(id, siteId)
// // return false
// }
// if (classid.length) {
// setTimeout(()=>{
// let shiftData = classid.shift()
// this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
// this.recordingCreat(shiftData['classId'], shiftData['siteId'])
// },20000)
// // clearInterval(interValGetFile)
// }
return
}
let files = fs.readdirSync(ymdDir);
// let interValGetFile = setInterval(()=>{
if (files.indexOf(id + ".mp4") == -1) {
this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
}else{
if (classid.length) {
setTimeout(()=>{
let shiftData = classid.shift()
this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
this.recordingCreat(shiftData['classId'], shiftData['siteId'])
},60*1000*5)
// clearInterval(interValGetFile)
}else{
this.wrieLog("录制结束:------>")
fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
if (err) {
console.log(err);
}
});
// clearInterval(interValGetFile)
}
}
// },3000)
if (err != null) {
this.wrieLog(" 错误" + id + ":" + err)
this.wrieLog(" 错误 stdout" + id + ":" + stdout)
this.wrieLog(" 错误 stderr" + id + ":" + stderr)
// if (files.indexOf(id + ".mp4") == -1) {
// // //当前课堂没有写入到文件夹,进入重录
// this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
// this.recordingCreat(id, siteId)
// // return false
// } else {
// if (classid.length) {
// }
// if (classid.length) {
// setTimeout(()=>{
// let shiftData = classid.shift()
// this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
// this.recordingCreat(shiftData['classId'], shiftData['siteId'])
// } else {
// this.wrieLog("录制结束:------>")
// fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
// if (err) {
// console.log(err);
// }
// });
// }
// },20000)
// // clearInterval(interValGetFile)
// }
return
}
let files = fs.readdirSync(ymdDir);
// let interValGetFile = setInterval(()=>{
if (files.indexOf(id + ".mp4") == -1) {
this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
} else {
if (classid.length) {
setTimeout(() => {
let shiftData = classid.shift()
this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
this.recordingCreat(shiftData['classId'], shiftData['siteId'])
}, 60 * 1000 * 5)
// clearInterval(interValGetFile)
} else {
this.wrieLog("录制结束:------>")
fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
if (err) {
console.log(err);
}
});
// clearInterval(interValGetFile)
}
}
// },3000)
// if (files.indexOf(id + ".mp4") == -1) {
// // //当前课堂没有写入到文件夹,进入重录
// this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
// this.recordingCreat(id, siteId)
// // return false
// } else {
// if (classid.length) {
// let shiftData = classid.shift()
// this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
// this.recordingCreat(shiftData['classId'], shiftData['siteId'])
// } else {
// this.wrieLog("录制结束:------>")
// fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
// if (err) {
// console.log(err);
// }
// });
// }
// }
// },20000)
})
// console.log("/web_capture_c",path.resolve(__dirname, PROJECTWINCATALOG+"./web_capture_c"))
... ... @@ -267,18 +267,18 @@ class MediaCreat {
router.get('/', async function (req, res, next) {
if (classid.length > 0) {
// 有正在录制中的课堂,禁止重复
res.send({code: "1", message: "有正在录制中的课堂", data: classid});
res.send({ code: "1", message: "有正在录制中的课堂", data: classid });
return
}
new MediaCreat().wrieLog("脚本录制开始:------>")
let fileConfig = new MediaCreat().getConfigFileJson()
if (!fileConfig) return false
const {GETCLASSURLPARAMETER} = JSON.parse(fileConfig)
const { GETCLASSURLPARAMETER } = JSON.parse(fileConfig)
siteIds = GETCLASSURLPARAMETER.siteId
if(siteIds.length == 0){
if (siteIds.length == 0) {
new MediaCreat().wrieLog("脚本录制,未配置siteId:------>" + siteIds)
res.send({code: "1",message:"未配置siteId",data:siteIds});
res.send({ code: "1", message: "未配置siteId", data: siteIds });
return
}
let result = await new MediaCreat().allData()
... ... @@ -300,12 +300,12 @@ router.get('/', async function (req, res, next) {
return false
}
}
res.send({code: "0"});
res.send({ code: "0" });
} else {
res.send({code: "1", message: "无录制数据"});
res.send({ code: "1", message: "无录制数据" });
}
}else {
res.send({code: "1", message: "无录制数据"});
} else {
res.send({ code: "1", message: "无录制数据" });
}
});
... ... @@ -318,10 +318,10 @@ router.post('/recording', async function (req, res, next) {
new MediaCreat().wrieLog("录制启动:------>")
let fileConfig = new MediaCreat().getConfigFileJson()
if (!fileConfig) return false
let {classId, maxMedia} = req.body
let { classId, maxMedia } = req.body
if (classid.length > 0) {
// 有正在录制中的课堂,禁止重复
res.send({code: "1", message: "有正在录制中的课堂", data: classid});
res.send({ code: "1", message: "有正在录制中的课堂", data: classid });
return
}
if (classId && classId.length) {
... ... @@ -338,9 +338,9 @@ router.post('/recording', async function (req, res, next) {
return false
}
}
res.send({code: "0"});
res.send({ code: "0" });
} else {
res.send({code: "1", message: "无录制数据"});
res.send({ code: "1", message: "无录制数据" });
}
})
... ...