799967501@qq.com

完善版本

1 { 1 {
2 - "GETCLASSURL":"http://139.196.126.156:8081/getLogs/recordClassList",  
3 - "GETCLASSURLPARAMETER":{  
4 - "siteId":["beidatest","funexenglish"],  
5 - "key":"xdymp4record20191225",  
6 - "page":1,  
7 - "maxMedia":1 2 + "GETCLASSURL": "http://139.196.126.156:8081/getLogs/recordClassList",
  3 + "GETCLASSURLPARAMETER": {
  4 + "siteId": [],
  5 + "key": "xdymp4record20191225",
  6 + "page": 1,
  7 + "maxMedia": 1
8 }, 8 },
9 - "PROJECTWINCATALOG":"F:/project/web_capture_release/win-x64",  
10 - "PROJECTCATALOG":"F:/project/web_capture_release",  
11 - "BACKMEDIACONFIG":{  
12 - "url" : "https://pclive.xuedianyun.com/pcBase/pclive2/dev/index.html",  
13 - "recordMp4":true,  
14 - "classId":"",  
15 - "userId":0,  
16 - "userName":"",  
17 - "userRole":"normal",  
18 - "portalIP":"saas.xuedianyun.com",  
19 - "portalPort":80,  
20 - "channels":2,  
21 - "playRecord":1,  
22 - "d":21600000,  
23 - "s":3000,  
24 - "fa":15,  
25 - "k":0,  
26 - "w":1280,  
27 - "h":720 9 + "PROJECTWINCATALOG": "F:/project/web_capture_release/win-x64",
  10 + "PROJECTCATALOG": "F:/project/web_capture_release",
  11 + "BACKMEDIACONFIG": {
  12 + "url": "https://pclive.xuedianyun.com/pcBase/pclive2/dev/index.html",
  13 + "recordMp4": true,
  14 + "classId": "",
  15 + "userId": 0,
  16 + "userName": "",
  17 + "userRole": "normal",
  18 + "portalIP": "saas.xuedianyun.com",
  19 + "portalPort": 80,
  20 + "channels": 2,
  21 + "playRecord": 1,
  22 + "d": 21600000,
  23 + "s": 3000,
  24 + "fa": 15,
  25 + "k": 0,
  26 + "w": 1280,
  27 + "h": 720
28 } 28 }
29 } 29 }
1 var express = require('express'); 1 var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 -const {spawn, exec} = require('child_process'); 3 +const { spawn, exec } = require('child_process');
4 const fs = require("fs"); 4 const fs = require("fs");
5 var path = require('path') 5 var path = require('path')
6 6
@@ -8,7 +8,7 @@ const method = require("../config/method") @@ -8,7 +8,7 @@ const method = require("../config/method")
8 const config = require("../config/config") 8 const config = require("../config/config")
9 9
10 // const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config 10 // const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config
11 -const {YesterdayTime, getRequestClassIds, dayTimeYMD} = method 11 +const { YesterdayTime, getRequestClassIds, dayTimeYMD } = method
12 12
13 let siteIds = [] 13 let siteIds = []
14 14
@@ -29,11 +29,11 @@ class MediaCreat { @@ -29,11 +29,11 @@ class MediaCreat {
29 29
30 // 取出所有数据 30 // 取出所有数据
31 async allData() { 31 async allData() {
32 - const {startTime, endTime} = YesterdayTime() 32 + const { startTime, endTime } = YesterdayTime()
33 let fileConfig = new MediaCreat().getConfigFileJson() 33 let fileConfig = new MediaCreat().getConfigFileJson()
34 if (!fileConfig) return false 34 if (!fileConfig) return false
35 className = siteIds.shift() 35 className = siteIds.shift()
36 - const {GETCLASSURL, GETCLASSURLPARAMETER} = JSON.parse(fileConfig) 36 + const { GETCLASSURL, GETCLASSURLPARAMETER } = JSON.parse(fileConfig)
37 let page = 1 37 let page = 1
38 if (className) { 38 if (className) {
39 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page) 39 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page)
@@ -42,7 +42,7 @@ class MediaCreat { @@ -42,7 +42,7 @@ class MediaCreat {
42 classid.push(result.data.data.list[j]) 42 classid.push(result.data.data.list[j])
43 parentData[result.data.data.siteId].add(result.data.data.list[j]['classId']) 43 parentData[result.data.data.siteId].add(result.data.data.list[j]['classId'])
44 } 44 }
45 - const {siteId, list, totalPage} = result.data.data 45 + const { siteId, list, totalPage } = result.data.data
46 for (let i = page += 1; i <= totalPage; i++) { 46 for (let i = page += 1; i <= totalPage; i++) {
47 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i) 47 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i)
48 for (let j = 0; j < result.data.data.list.length; j++) { 48 for (let j = 0; j < result.data.data.list.length; j++) {
@@ -123,7 +123,7 @@ class MediaCreat { @@ -123,7 +123,7 @@ class MediaCreat {
123 this.wrieLog(" 课堂录制开始:------>" + id) 123 this.wrieLog(" 课堂录制开始:------>" + id)
124 let fileConfig = this.getConfigFileJson() 124 let fileConfig = this.getConfigFileJson()
125 if (!fileConfig) return false 125 if (!fileConfig) return false
126 - const {BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG} = JSON.parse(fileConfig) 126 + const { BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG } = JSON.parse(fileConfig)
127 let mediaDir = PROJECTCATALOG + "/media/" 127 let mediaDir = PROJECTCATALOG + "/media/"
128 let classDir = PROJECTCATALOG + "/media/" + siteId 128 let classDir = PROJECTCATALOG + "/media/" + siteId
129 let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd 129 let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd
@@ -140,15 +140,15 @@ class MediaCreat { @@ -140,15 +140,15 @@ class MediaCreat {
140 // export DISPLAY=:7 140 // export DISPLAY=:7
141 // 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}` 141 // 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}`
142 // console.log("url", url) 142 // console.log("url", url)
143 - 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` 143 + 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}`
144 // console.log("url", url) 144 // console.log("url", url)
145 // console.log("PROJECTWINCATALOG", PROJECTWINCATALOG) 145 // console.log("PROJECTWINCATALOG", PROJECTWINCATALOG)
146 - exec(url, {maxBuffer:1073741824},(err, stdout, stderr) => { 146 + exec(url, { maxBuffer: 1073741824 }, (err, stdout, stderr) => {
147 // setTimeout(()=>{ 147 // setTimeout(()=>{
148 if (err != null) { 148 if (err != null) {
149 - this.wrieLog(" 错误" + id +":" + err)  
150 - this.wrieLog(" 错误 stdout" + id +":" + stdout)  
151 - this.wrieLog(" 错误 stderr" + id +":" + stderr) 149 + this.wrieLog(" 错误" + id + ":" + err)
  150 + this.wrieLog(" 错误 stdout" + id + ":" + stdout)
  151 + this.wrieLog(" 错误 stderr" + id + ":" + stderr)
152 // if (files.indexOf(id + ".mp4") == -1) { 152 // if (files.indexOf(id + ".mp4") == -1) {
153 // // //当前课堂没有写入到文件夹,进入重录 153 // // //当前课堂没有写入到文件夹,进入重录
154 // this.wrieLog(" 课堂录制未发现该" + id + "课堂号") 154 // this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
@@ -169,15 +169,15 @@ class MediaCreat { @@ -169,15 +169,15 @@ class MediaCreat {
169 // let interValGetFile = setInterval(()=>{ 169 // let interValGetFile = setInterval(()=>{
170 if (files.indexOf(id + ".mp4") == -1) { 170 if (files.indexOf(id + ".mp4") == -1) {
171 this.wrieLog(" 课堂录制未发现该" + id + "课堂号") 171 this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
172 - }else{ 172 + } else {
173 if (classid.length) { 173 if (classid.length) {
174 - setTimeout(()=>{ 174 + setTimeout(() => {
175 let shiftData = classid.shift() 175 let shiftData = classid.shift()
176 this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId']) 176 this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
177 this.recordingCreat(shiftData['classId'], shiftData['siteId']) 177 this.recordingCreat(shiftData['classId'], shiftData['siteId'])
178 - },60*1000*5) 178 + }, 60 * 1000 * 5)
179 // clearInterval(interValGetFile) 179 // clearInterval(interValGetFile)
180 - }else{ 180 + } else {
181 this.wrieLog("录制结束:------>") 181 this.wrieLog("录制结束:------>")
182 fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { 182 fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
183 if (err) { 183 if (err) {
@@ -267,18 +267,18 @@ class MediaCreat { @@ -267,18 +267,18 @@ class MediaCreat {
267 router.get('/', async function (req, res, next) { 267 router.get('/', async function (req, res, next) {
268 if (classid.length > 0) { 268 if (classid.length > 0) {
269 // 有正在录制中的课堂,禁止重复 269 // 有正在录制中的课堂,禁止重复
270 - res.send({code: "1", message: "有正在录制中的课堂", data: classid}); 270 + res.send({ code: "1", message: "有正在录制中的课堂", data: classid });
271 return 271 return
272 } 272 }
273 new MediaCreat().wrieLog("脚本录制开始:------>") 273 new MediaCreat().wrieLog("脚本录制开始:------>")
274 let fileConfig = new MediaCreat().getConfigFileJson() 274 let fileConfig = new MediaCreat().getConfigFileJson()
275 if (!fileConfig) return false 275 if (!fileConfig) return false
276 276
277 - const {GETCLASSURLPARAMETER} = JSON.parse(fileConfig) 277 + const { GETCLASSURLPARAMETER } = JSON.parse(fileConfig)
278 siteIds = GETCLASSURLPARAMETER.siteId 278 siteIds = GETCLASSURLPARAMETER.siteId
279 - if(siteIds.length == 0){ 279 + if (siteIds.length == 0) {
280 new MediaCreat().wrieLog("脚本录制,未配置siteId:------>" + siteIds) 280 new MediaCreat().wrieLog("脚本录制,未配置siteId:------>" + siteIds)
281 - res.send({code: "1",message:"未配置siteId",data:siteIds}); 281 + res.send({ code: "1", message: "未配置siteId", data: siteIds });
282 return 282 return
283 } 283 }
284 let result = await new MediaCreat().allData() 284 let result = await new MediaCreat().allData()
@@ -300,12 +300,12 @@ router.get('/', async function (req, res, next) { @@ -300,12 +300,12 @@ router.get('/', async function (req, res, next) {
300 return false 300 return false
301 } 301 }
302 } 302 }
303 - res.send({code: "0"}); 303 + res.send({ code: "0" });
304 } else { 304 } else {
305 - res.send({code: "1", message: "无录制数据"}); 305 + res.send({ code: "1", message: "无录制数据" });
306 } 306 }
307 - }else {  
308 - res.send({code: "1", message: "无录制数据"}); 307 + } else {
  308 + res.send({ code: "1", message: "无录制数据" });
309 } 309 }
310 }); 310 });
311 311
@@ -318,10 +318,10 @@ router.post('/recording', async function (req, res, next) { @@ -318,10 +318,10 @@ router.post('/recording', async function (req, res, next) {
318 new MediaCreat().wrieLog("录制启动:------>") 318 new MediaCreat().wrieLog("录制启动:------>")
319 let fileConfig = new MediaCreat().getConfigFileJson() 319 let fileConfig = new MediaCreat().getConfigFileJson()
320 if (!fileConfig) return false 320 if (!fileConfig) return false
321 - let {classId, maxMedia} = req.body 321 + let { classId, maxMedia } = req.body
322 if (classid.length > 0) { 322 if (classid.length > 0) {
323 // 有正在录制中的课堂,禁止重复 323 // 有正在录制中的课堂,禁止重复
324 - res.send({code: "1", message: "有正在录制中的课堂", data: classid}); 324 + res.send({ code: "1", message: "有正在录制中的课堂", data: classid });
325 return 325 return
326 } 326 }
327 if (classId && classId.length) { 327 if (classId && classId.length) {
@@ -338,9 +338,9 @@ router.post('/recording', async function (req, res, next) { @@ -338,9 +338,9 @@ router.post('/recording', async function (req, res, next) {
338 return false 338 return false
339 } 339 }
340 } 340 }
341 - res.send({code: "0"}); 341 + res.send({ code: "0" });
342 } else { 342 } else {
343 - res.send({code: "1", message: "无录制数据"}); 343 + res.send({ code: "1", message: "无录制数据" });
344 } 344 }
345 345
346 }) 346 })