799967501@qq.com

修改GET录制日期写入的视频文件为上一天

判断如果有相同的视频文件,停止录制
正在显示 1 个修改的文件 包含 21 行增加147 行删除
... ... @@ -68,65 +68,21 @@ class MediaCreat {
fs.appendFileSync(logFile, new Date().toLocaleString() + " " + text + '\r\n');
}
// async mediaCreat(id, siteId) {
// const {ymd} = YesterdayTime()
// let fileConfig = await new MediaCreat().getConfigFileJson()
// if (!fileConfig) return false
// const {BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG} = JSON.parse(fileConfig)
//
// let mediaDir = PROJECTCATALOG + "/media/"
// let classDir = PROJECTCATALOG + "/media/" + siteId
// let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + ymd
// if (!fs.existsSync(mediaDir)) {
// fs.mkdirSync(mediaDir);
// }
// if (!fs.existsSync(classDir)) {
// fs.mkdirSync(classDir);
// }
// if (!fs.existsSync(ymdDir)) {
// fs.mkdirSync(ymdDir);
// }
// let url = `"${PROJECTWINCATALOG} /web_capture_c" -o=../media/${siteId}/${ymd}/${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}`
// var workerProcess = exec(url) // , {cwd: PROJECTWINCATALOG, shell: true}
// // workerProcess.stdout.on('data', async function (data) {
//
// // });
//
// workerProcess.on('close', async (code) => {
// let files = fs.readdirSync(ymdDir);
// if (files.indexOf(id + ".mp4") == -1) {
// //当前课堂没有写入到文件夹,进入重录
// new MediaCreat().mediaCreat(id, siteId)
// return false
// } else {
// if (parentData[siteId].indexOf(id.toString()) != -1) {
// parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1)
// }
// if (parentData[siteId].length == 0) {
// // //全部录制完毕
// this.wrieLog("录制结束:------>")
// fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
// if (err) {
// console.log(err);
// }
// });
// }
// if (classid.length) {
// let shiftData = classid.shift()
// new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
// }
// }
// });
// }
recordingCreat(id, siteId) {
recordingCreat(id, siteId, type) {
this.wrieLog(" 课堂录制开始:------>" + id)
let fileConfig = this.getConfigFileJson()
if (!fileConfig) return false
const { BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG } = JSON.parse(fileConfig)
let mediaDir = PROJECTCATALOG + "/media/"
let classDir = PROJECTCATALOG + "/media/" + siteId
let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd
let ymdDir = null
if (type == 'post') {
ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd
} else {
// get 的目录创建为上一天日期
ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + YesterdayTime().ymd
}
if (!fs.existsSync(mediaDir)) {
fs.mkdirSync(mediaDir);
}
... ... @@ -136,33 +92,22 @@ class MediaCreat {
if (!fs.existsSync(ymdDir)) {
fs.mkdirSync(ymdDir);
}
let files = fs.readdirSync(ymdDir);
// let interValGetFile = setInterval(()=>{
if (files.indexOf(id + ".mp4") != -1) {
this.wrieLog("已存在:" + id + "课堂号,停止继续录制")
return
}
// 目前url是linux的写法 win系统不支持
// 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}&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) => {
// 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);
... ... @@ -171,12 +116,9 @@ class MediaCreat {
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)
let shiftData = classid.shift()
this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
this.recordingCreat(shiftData['classId'], shiftData['siteId'], type)
} else {
this.wrieLog("录制结束:------>")
fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
... ... @@ -184,77 +126,9 @@ class MediaCreat {
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"))
// spawnSync(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}`
// ])
// workerProcess = spawnSync(url,{shell: true})// {cwd: PROJECTWINCATALOG, shell: true}
// console.log("workerProcess",workerProcess)
// workerProcess.stdout.on('data', function (data) {
// console.log("stdout",data)
// });
// workerProcess.stderr.on('data', (data) => {
// console.error(`stderr: ${data}`);
// });
//
// workerProcess.on('close', (code) => {
// console.log("code", code)
// if (code == 0) {
// this.wrieLog(" 课堂录制结束:------>" + id)
// let files = fs.readdirSync(ymdDir);
// if (files.indexOf(id + ".mp4") == -1) {
// // //当前课堂没有写入到文件夹,进入重录
// this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
// new MediaCreat().recordingCreat(id, siteId)
// // return false
// } else {
// if (classid.length) {
// let shiftData = classid.shift()
// this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
// new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'])
// } else {
// this.wrieLog("录制结束:------>")
// fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
// if (err) {
// console.log(err);
// }
// });
// }
// }
// }
// });
}
getConfigFileJson() {
... ... @@ -264,7 +138,7 @@ class MediaCreat {
}
router.get('/', async function (req, res, next) {
router.get('/recording', async function (req, res, next) {
if (classid.length > 0) {
// 有正在录制中的课堂,禁止重复
res.send({ code: "1", message: "有正在录制中的课堂", data: classid });
... ... @@ -295,7 +169,7 @@ router.get('/', async function (req, res, next) {
for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) {
let shiftData = classid.shift()
if (shiftData) {
new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'])
new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'], 'get')
} else {
return false
}
... ... @@ -333,7 +207,7 @@ router.post('/recording', async function (req, res, next) {
for (let i = 0; i < maxMedia; i++) {
let shiftData = classid.shift()
if (shiftData) {
new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'])
new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'], 'post')
} else {
return false
}
... ...