正在显示
3 个修改的文件
包含
93 行增加
和
2 行删除
| @@ -15,6 +15,15 @@ const methods = { | @@ -15,6 +15,15 @@ const methods = { | ||
| 15 | ymd:year + "-" + month + "-" + date | 15 | ymd:year + "-" + month + "-" + date |
| 16 | } | 16 | } |
| 17 | }, | 17 | }, |
| 18 | + dayTimeYMD() { | ||
| 19 | + let dayTimeDate = new Date() | ||
| 20 | + let year = dayTimeDate.getFullYear() | ||
| 21 | + let month = dayTimeDate.getMonth() + 1 | ||
| 22 | + let date = dayTimeDate.getDate() | ||
| 23 | + return { | ||
| 24 | + ymd:year + "-" + month + "-" + date | ||
| 25 | + } | ||
| 26 | + }, | ||
| 18 | async getRequestClassIds(url, siteId, key, startTime, endTime,page) { | 27 | async getRequestClassIds(url, siteId, key, startTime, endTime,page) { |
| 19 | let axiosUrl = `${url}?siteId=${siteId}&key=${key}&from=${startTime}&to=${endTime}&page=${page}` | 28 | let axiosUrl = `${url}?siteId=${siteId}&key=${key}&from=${startTime}&to=${endTime}&page=${page}` |
| 20 | let result = await axios.get(axiosUrl) | 29 | let result = await axios.get(axiosUrl) |
| @@ -7,7 +7,7 @@ const method = require("../config/method") | @@ -7,7 +7,7 @@ const method = require("../config/method") | ||
| 7 | const config = require("../config/config") | 7 | const config = require("../config/config") |
| 8 | 8 | ||
| 9 | // const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config | 9 | // const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config |
| 10 | -const { YesterdayTime, getRequestClassIds } = method | 10 | +const { YesterdayTime, getRequestClassIds,dayTimeYMD } = method |
| 11 | 11 | ||
| 12 | const { startTime, endTime, ymd } = YesterdayTime() | 12 | const { startTime, endTime, ymd } = YesterdayTime() |
| 13 | let siteIds = [] | 13 | let siteIds = [] |
| @@ -101,6 +101,57 @@ class MediaCreat { | @@ -101,6 +101,57 @@ class MediaCreat { | ||
| 101 | } | 101 | } |
| 102 | }); | 102 | }); |
| 103 | } | 103 | } |
| 104 | + async recordingCreat(id, siteId) { | ||
| 105 | + let fileConfig = await new MediaCreat().getConfigFileJson() | ||
| 106 | + if(!fileConfig) return false | ||
| 107 | + const { BACKMEDIACONFIG,PROJECTWINCATALOG,PROJECTCATALOG } = JSON.parse(fileConfig) | ||
| 108 | + let mediaDir = PROJECTCATALOG + "/media/" | ||
| 109 | + let recordingDir = mediaDir + "recording/" | ||
| 110 | + let classDir = recordingDir + siteId +"/" | ||
| 111 | + let dateDir = classDir + dayTimeYMD().ymd | ||
| 112 | + if (!fs.existsSync(mediaDir)) { | ||
| 113 | + fs.mkdirSync(mediaDir); | ||
| 114 | + } | ||
| 115 | + if (!fs.existsSync(recordingDir)) { | ||
| 116 | + fs.mkdirSync(recordingDir); | ||
| 117 | + } | ||
| 118 | + if (!fs.existsSync(classDir)) { | ||
| 119 | + fs.mkdirSync(classDir); | ||
| 120 | + } | ||
| 121 | + if (!fs.existsSync(dateDir)) { | ||
| 122 | + fs.mkdirSync(dateDir); | ||
| 123 | + } | ||
| 124 | + let url = `web_capture_c -o=../media/recording/${siteId}/${dayTimeYMD().ymd}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&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}` | ||
| 125 | + var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true }) | ||
| 126 | + // workerProcess.stdout.on('data', async function (data) { | ||
| 127 | + | ||
| 128 | + // }); | ||
| 129 | + | ||
| 130 | + workerProcess.on('close', async function (code) { | ||
| 131 | + let files = fs.readdirSync(dateDir); | ||
| 132 | + if (files.indexOf(id + ".mp4") == -1) { | ||
| 133 | + //当前课堂没有写入到文件夹,进入重录 | ||
| 134 | + new MediaCreat().recordingCreat(id, siteId) | ||
| 135 | + return false | ||
| 136 | + } else { | ||
| 137 | + if (parentData[siteId].indexOf(id.toString()) != -1) { | ||
| 138 | + parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1) | ||
| 139 | + } | ||
| 140 | + if (parentData[siteId].length == 0) { | ||
| 141 | + // //全部录制完毕 | ||
| 142 | + fs.writeFile(dateDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
| 143 | + if (err) { | ||
| 144 | + console.log(err); | ||
| 145 | + } | ||
| 146 | + }); | ||
| 147 | + } | ||
| 148 | + if (classid.length) { | ||
| 149 | + let shiftData = classid.shift() | ||
| 150 | + new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + }); | ||
| 154 | + } | ||
| 104 | 155 | ||
| 105 | async getConfigFileJson(){ | 156 | async getConfigFileJson(){ |
| 106 | const buffer= fs.readFileSync(process.cwd()+"/config/config.json") | 157 | const buffer= fs.readFileSync(process.cwd()+"/config/config.json") |
| @@ -137,4 +188,35 @@ router.get('/', async function (req, res, next) { | @@ -137,4 +188,35 @@ router.get('/', async function (req, res, next) { | ||
| 137 | } | 188 | } |
| 138 | }); | 189 | }); |
| 139 | 190 | ||
| 191 | +/** | ||
| 192 | + * { | ||
| 193 | + * "classId":[{ classId: '389675110', siteId: 'kuaikuenglish' }] | ||
| 194 | + * } | ||
| 195 | + */ | ||
| 196 | +router.post('/recording', async function (req, res, next) { | ||
| 197 | + let fileConfig = await new MediaCreat().getConfigFileJson() | ||
| 198 | + if(!fileConfig) return false | ||
| 199 | + const { classId } = req.body | ||
| 200 | + if(classId && classId.length){ | ||
| 201 | + classid = classId | ||
| 202 | + const { PROJECTCATALOG,GETCLASSURLPARAMETER } = JSON.parse(fileConfig) | ||
| 203 | + for(let i=0;i<classId.length;i++){ | ||
| 204 | + if(!Array.isArray(parentData[classId[i].siteId])){ | ||
| 205 | + parentData[classId[i].siteId] = [] | ||
| 206 | + } | ||
| 207 | + parentData[classId[i].siteId].push(classId[i].classId) | ||
| 208 | + } | ||
| 209 | + for(let i=0;i<GETCLASSURLPARAMETER.maxMedia;i++){ | ||
| 210 | + let shiftData = classid.shift() | ||
| 211 | + if (shiftData) { | ||
| 212 | + new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
| 213 | + } else { | ||
| 214 | + return false | ||
| 215 | + } | ||
| 216 | + } | ||
| 217 | + } | ||
| 218 | + res.send({ code: "0" }); | ||
| 219 | +}) | ||
| 220 | + | ||
| 221 | + | ||
| 140 | module.exports = router; | 222 | module.exports = router; |
-
请 注册 或 登录 后发表评论