799967501@qq.com

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

判断如果有相同的视频文件,停止录制
正在显示 1 个修改的文件 包含 19 行增加145 行删除
@@ -68,65 +68,21 @@ class MediaCreat { @@ -68,65 +68,21 @@ class MediaCreat {
68 fs.appendFileSync(logFile, new Date().toLocaleString() + " " + text + '\r\n'); 68 fs.appendFileSync(logFile, new Date().toLocaleString() + " " + text + '\r\n');
69 } 69 }
70 70
71 - // async mediaCreat(id, siteId) {  
72 - // const {ymd} = YesterdayTime()  
73 - // let fileConfig = await new MediaCreat().getConfigFileJson()  
74 - // if (!fileConfig) return false  
75 - // const {BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG} = JSON.parse(fileConfig)  
76 - //  
77 - // let mediaDir = PROJECTCATALOG + "/media/"  
78 - // let classDir = PROJECTCATALOG + "/media/" + siteId  
79 - // let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + ymd  
80 - // if (!fs.existsSync(mediaDir)) {  
81 - // fs.mkdirSync(mediaDir);  
82 - // }  
83 - // if (!fs.existsSync(classDir)) {  
84 - // fs.mkdirSync(classDir);  
85 - // }  
86 - // if (!fs.existsSync(ymdDir)) {  
87 - // fs.mkdirSync(ymdDir);  
88 - // }  
89 - // 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}`  
90 - // var workerProcess = exec(url) // , {cwd: PROJECTWINCATALOG, shell: true}  
91 - // // workerProcess.stdout.on('data', async function (data) {  
92 - //  
93 - // // });  
94 - //  
95 - // workerProcess.on('close', async (code) => {  
96 - // let files = fs.readdirSync(ymdDir);  
97 - // if (files.indexOf(id + ".mp4") == -1) {  
98 - // //当前课堂没有写入到文件夹,进入重录  
99 - // new MediaCreat().mediaCreat(id, siteId)  
100 - // return false  
101 - // } else {  
102 - // if (parentData[siteId].indexOf(id.toString()) != -1) {  
103 - // parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1)  
104 - // }  
105 - // if (parentData[siteId].length == 0) {  
106 - // // //全部录制完毕  
107 - // this.wrieLog("录制结束:------>")  
108 - // fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {  
109 - // if (err) {  
110 - // console.log(err);  
111 - // }  
112 - // });  
113 - // }  
114 - // if (classid.length) {  
115 - // let shiftData = classid.shift()  
116 - // new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])  
117 - // }  
118 - // }  
119 - // });  
120 - // }  
121 -  
122 - recordingCreat(id, siteId) { 71 + recordingCreat(id, siteId, type) {
123 this.wrieLog(" 课堂录制开始:------>" + id) 72 this.wrieLog(" 课堂录制开始:------>" + id)
124 let fileConfig = this.getConfigFileJson() 73 let fileConfig = this.getConfigFileJson()
125 if (!fileConfig) return false 74 if (!fileConfig) return false
126 const { BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG } = JSON.parse(fileConfig) 75 const { BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG } = JSON.parse(fileConfig)
127 let mediaDir = PROJECTCATALOG + "/media/" 76 let mediaDir = PROJECTCATALOG + "/media/"
128 let classDir = PROJECTCATALOG + "/media/" + siteId 77 let classDir = PROJECTCATALOG + "/media/" + siteId
129 - let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd 78 + let ymdDir = null
  79 + if (type == 'post') {
  80 + ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd
  81 + } else {
  82 + // get 的目录创建为上一天日期
  83 + ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + YesterdayTime().ymd
  84 + }
  85 +
130 if (!fs.existsSync(mediaDir)) { 86 if (!fs.existsSync(mediaDir)) {
131 fs.mkdirSync(mediaDir); 87 fs.mkdirSync(mediaDir);
132 } 88 }
@@ -136,33 +92,22 @@ class MediaCreat { @@ -136,33 +92,22 @@ class MediaCreat {
136 if (!fs.existsSync(ymdDir)) { 92 if (!fs.existsSync(ymdDir)) {
137 fs.mkdirSync(ymdDir); 93 fs.mkdirSync(ymdDir);
138 } 94 }
  95 + let files = fs.readdirSync(ymdDir);
  96 + // let interValGetFile = setInterval(()=>{
  97 + if (files.indexOf(id + ".mp4") != -1) {
  98 + this.wrieLog("已存在:" + id + "课堂号,停止继续录制")
  99 + return
  100 + }
139 // 目前url是linux的写法 win系统不支持 101 // 目前url是linux的写法 win系统不支持
140 // export DISPLAY=:7 102 // 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}` 103 // 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) 104 // 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}&language=zh-cn" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa} -k=${BACKMEDIACONFIG.k} -w=${BACKMEDIACONFIG.w} -h=${BACKMEDIACONFIG.h}` 105 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)  
145 - // console.log("PROJECTWINCATALOG", PROJECTWINCATALOG)  
146 exec(url, { maxBuffer: 1073741824 }, (err, stdout, stderr) => { 106 exec(url, { maxBuffer: 1073741824 }, (err, stdout, stderr) => {
147 - // setTimeout(()=>{  
148 if (err != null) { 107 if (err != null) {
149 this.wrieLog(" 错误" + id + ":" + err) 108 this.wrieLog(" 错误" + id + ":" + err)
150 this.wrieLog(" 错误 stdout" + id + ":" + stdout) 109 this.wrieLog(" 错误 stdout" + id + ":" + stdout)
151 this.wrieLog(" 错误 stderr" + id + ":" + stderr) 110 this.wrieLog(" 错误 stderr" + id + ":" + stderr)
152 - // if (files.indexOf(id + ".mp4") == -1) {  
153 - // // //当前课堂没有写入到文件夹,进入重录  
154 - // this.wrieLog(" 课堂录制未发现该" + id + "课堂号")  
155 - // this.recordingCreat(id, siteId)  
156 - // // return false  
157 - // }  
158 - // if (classid.length) {  
159 - // setTimeout(()=>{  
160 - // let shiftData = classid.shift()  
161 - // this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])  
162 - // this.recordingCreat(shiftData['classId'], shiftData['siteId'])  
163 - // },20000)  
164 - // // clearInterval(interValGetFile)  
165 - // }  
166 return 111 return
167 } 112 }
168 let files = fs.readdirSync(ymdDir); 113 let files = fs.readdirSync(ymdDir);
@@ -171,12 +116,9 @@ class MediaCreat { @@ -171,12 +116,9 @@ class MediaCreat {
171 this.wrieLog(" 课堂录制未发现该" + id + "课堂号") 116 this.wrieLog(" 课堂录制未发现该" + id + "课堂号")
172 } else { 117 } else {
173 if (classid.length) { 118 if (classid.length) {
174 - setTimeout(() => {  
175 let shiftData = classid.shift() 119 let shiftData = classid.shift()
176 this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId']) 120 this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])
177 - this.recordingCreat(shiftData['classId'], shiftData['siteId'])  
178 - }, 60 * 1000 * 5)  
179 - // clearInterval(interValGetFile) 121 + this.recordingCreat(shiftData['classId'], shiftData['siteId'], type)
180 } else { 122 } else {
181 this.wrieLog("录制结束:------>") 123 this.wrieLog("录制结束:------>")
182 fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { 124 fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
@@ -184,77 +126,9 @@ class MediaCreat { @@ -184,77 +126,9 @@ class MediaCreat {
184 console.log(err); 126 console.log(err);
185 } 127 }
186 }); 128 });
187 - // clearInterval(interValGetFile)  
188 } 129 }
189 } 130 }
190 - // },3000)  
191 - // if (files.indexOf(id + ".mp4") == -1) {  
192 - // // //当前课堂没有写入到文件夹,进入重录  
193 - // this.wrieLog(" 课堂录制未发现该" + id + "课堂号")  
194 - // this.recordingCreat(id, siteId)  
195 - // // return false  
196 - // } else {  
197 - // if (classid.length) {  
198 - // let shiftData = classid.shift()  
199 - // this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])  
200 - // this.recordingCreat(shiftData['classId'], shiftData['siteId'])  
201 - // } else {  
202 - // this.wrieLog("录制结束:------>")  
203 - // fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {  
204 - // if (err) {  
205 - // console.log(err);  
206 - // }  
207 - // });  
208 - // }  
209 - // }  
210 - // },20000)  
211 }) 131 })
212 - // console.log("/web_capture_c",path.resolve(__dirname, PROJECTWINCATALOG+"./web_capture_c"))  
213 - // spawnSync(path.resolve(__dirname, PROJECTWINCATALOG+"./web_capture_c"),[  
214 - // "-o",`${ymdDir}/${id}.mp4`,  
215 - // "-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}`,  
216 - // "-d",`${BACKMEDIACONFIG.d}`,  
217 - // "-s",`${BACKMEDIACONFIG.s}`,  
218 - // "-fa",`${BACKMEDIACONFIG.fa}`,  
219 - // "-k",`${BACKMEDIACONFIG.k}`,  
220 - // "-w",`${BACKMEDIACONFIG.w}`,  
221 - // "-h",`${BACKMEDIACONFIG.h}`  
222 - // ])  
223 - // workerProcess = spawnSync(url,{shell: true})// {cwd: PROJECTWINCATALOG, shell: true}  
224 - // console.log("workerProcess",workerProcess)  
225 - // workerProcess.stdout.on('data', function (data) {  
226 - // console.log("stdout",data)  
227 - // });  
228 - // workerProcess.stderr.on('data', (data) => {  
229 - // console.error(`stderr: ${data}`);  
230 - // });  
231 - //  
232 - // workerProcess.on('close', (code) => {  
233 - // console.log("code", code)  
234 - // if (code == 0) {  
235 - // this.wrieLog(" 课堂录制结束:------>" + id)  
236 - // let files = fs.readdirSync(ymdDir);  
237 - // if (files.indexOf(id + ".mp4") == -1) {  
238 - // // //当前课堂没有写入到文件夹,进入重录  
239 - // this.wrieLog(" 课堂录制未发现该" + id + "课堂号")  
240 - // new MediaCreat().recordingCreat(id, siteId)  
241 - // // return false  
242 - // } else {  
243 - // if (classid.length) {  
244 - // let shiftData = classid.shift()  
245 - // this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId'])  
246 - // new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'])  
247 - // } else {  
248 - // this.wrieLog("录制结束:------>")  
249 - // fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {  
250 - // if (err) {  
251 - // console.log(err);  
252 - // }  
253 - // });  
254 - // }  
255 - // }  
256 - // }  
257 - // });  
258 } 132 }
259 133
260 getConfigFileJson() { 134 getConfigFileJson() {
@@ -264,7 +138,7 @@ class MediaCreat { @@ -264,7 +138,7 @@ class MediaCreat {
264 } 138 }
265 139
266 140
267 -router.get('/', async function (req, res, next) { 141 +router.get('/recording', async function (req, res, next) {
268 if (classid.length > 0) { 142 if (classid.length > 0) {
269 // 有正在录制中的课堂,禁止重复 143 // 有正在录制中的课堂,禁止重复
270 res.send({ code: "1", message: "有正在录制中的课堂", data: classid }); 144 res.send({ code: "1", message: "有正在录制中的课堂", data: classid });
@@ -295,7 +169,7 @@ router.get('/', async function (req, res, next) { @@ -295,7 +169,7 @@ router.get('/', async function (req, res, next) {
295 for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) { 169 for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) {
296 let shiftData = classid.shift() 170 let shiftData = classid.shift()
297 if (shiftData) { 171 if (shiftData) {
298 - new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) 172 + new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'], 'get')
299 } else { 173 } else {
300 return false 174 return false
301 } 175 }
@@ -333,7 +207,7 @@ router.post('/recording', async function (req, res, next) { @@ -333,7 +207,7 @@ router.post('/recording', async function (req, res, next) {
333 for (let i = 0; i < maxMedia; i++) { 207 for (let i = 0; i < maxMedia; i++) {
334 let shiftData = classid.shift() 208 let shiftData = classid.shift()
335 if (shiftData) { 209 if (shiftData) {
336 - new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) 210 + new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'], 'post')
337 } else { 211 } else {
338 return false 212 return false
339 } 213 }