张艾宸

完善录制流程

1 node_modules 1 node_modules
  2 +.idea
1 const GETCLASSURL = "http://139.196.126.156:8081/getLogs/recordClassList" 1 const GETCLASSURL = "http://139.196.126.156:8081/getLogs/recordClassList"
2 const GETCLASSURLPARAMETER = { 2 const GETCLASSURLPARAMETER = {
3 - siteId:["talk915","kuaikuenglish"],  
4 - key:"xdymp4record20191225" 3 + siteId:["BuzzKID","kuaikuenglish"],
  4 + key:"xdymp4record20191225",
  5 + page:1
5 } 6 }
6 7
7 const PROJECTWINCATALOG = "E:/project/web_capture_release/win-x64" 8 const PROJECTWINCATALOG = "E:/project/web_capture_release/win-x64"
@@ -18,9 +19,10 @@ const BACKMEDIACONFIG = { @@ -18,9 +19,10 @@ const BACKMEDIACONFIG = {
18 portalPort:80, 19 portalPort:80,
19 channels:2, 20 channels:2,
20 playRecord:1, 21 playRecord:1,
21 - d:3000, 22 + d:0.5*60*60*1000,
22 s:0, 23 s:0,
23 - fa:15 24 + fa:15,
  25 + k:1
24 } 26 }
25 module.exports = { 27 module.exports = {
26 GETCLASSURL, 28 GETCLASSURL,
@@ -11,11 +11,12 @@ const methods = { @@ -11,11 +11,12 @@ const methods = {
11 let endTime = new Date(year + "-" + month + "-" + date + " 23:59:00").getTime() 11 let endTime = new Date(year + "-" + month + "-" + date + " 23:59:00").getTime()
12 return { 12 return {
13 startTime, 13 startTime,
14 - endTime 14 + endTime,
  15 + ymd:year + "-" + month + "-" + date
15 } 16 }
16 }, 17 },
17 - async getRequestClassIds(url, siteId, key, startTime, endTime) {  
18 - let axiosUrl = `${url}?siteId=${siteId}&key=${key}&from=${startTime}&to=${endTime}` 18 + async getRequestClassIds(url, siteId, key, startTime, endTime,page) {
  19 + let axiosUrl = `${url}?siteId=${siteId}&key=${key}&from=${startTime}&to=${endTime}&page=${page}`
19 let result = await axios.get(axiosUrl) 20 let result = await axios.get(axiosUrl)
20 return result 21 return result
21 }, 22 },
@@ -9,73 +9,121 @@ const config = require("../config/config") @@ -9,73 +9,121 @@ const config = require("../config/config")
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 } = method
11 11
12 -const { startTime, endTime } = YesterdayTime() 12 +const { startTime, endTime, ymd } = YesterdayTime()
13 let siteIds = GETCLASSURLPARAMETER.siteId 13 let siteIds = GETCLASSURLPARAMETER.siteId
14 14
15 let classid = [] 15 let classid = []
  16 +let parentData = []
  17 +var classobj = {};
16 let className = "" 18 let className = ""
17 - 19 +let maxMedia = 2
18 /** 20 /**
19 * 21 *
20 * @param {*} id 课堂id 22 * @param {*} id 课堂id
21 */ 23 */
22 -function mediaCreat(id) {  
23 - let mediaDir = PROJECTCATALOG+"/media/"  
24 - let dir = PROJECTCATALOG+"/media/"+className  
25 - if (!fs.existsSync(mediaDir)){  
26 - fs.mkdirSync(mediaDir);  
27 - }  
28 - if (!fs.existsSync(dir)){  
29 - fs.mkdirSync(dir); 24 +class MediaCreat {
  25 + constructor() { }
  26 + // 取出所有数据
  27 + async allData() {
  28 + let page = 1
  29 + className = siteIds.shift()
  30 + let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page)
  31 + for (let j = 0; j < result.data.data.list.length; j++) {
  32 + classid.push(result.data.data.list[j])
  33 + }
  34 + const { siteId, list, totalPage } = result.data.data
  35 + for (let i = page += 1; i <= totalPage; i++) {
  36 + let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i)
  37 + for (let j = 0; j < result.data.data.list.length; j++) {
  38 + classid.push(result.data.data.list[j])
  39 + }
  40 + }
  41 +
  42 + classid = classid.reduce(function (item, next) {
  43 + classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next);
  44 + return item;
  45 + }, []);
  46 + parentData = JSON.parse(JSON.stringify(classid))
  47 + return true
30 } 48 }
31 - let url = `web_capture_c -o=../media/${className}/${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}`  
32 - var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })  
33 - workerProcess.stdout.on('data', async function (data) {  
34 - if(classid.length){  
35 - let id = classid.shift()  
36 - mediaCreat(id['classId'])  
37 - }else{  
38 - if (siteIds.length) {  
39 - // 如果有多家需要录制,继续录制下一家  
40 - className = siteIds.shift()  
41 - let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime)  
42 - if (result.data && result.data.code == 0) {  
43 - // 返回成功  
44 - classid = result.data.data.list  
45 - if(classid.length){  
46 - let id = classid.shift()  
47 - mediaCreat(id['classId'])  
48 - } 49 +
  50 + // 取出不同的值
  51 + async notResult(data1, data2) {
  52 + new Promise((resolve, reject) => {
  53 + let data = []
  54 + for (let i = 0; i < data2.length; i++) {
  55 + // for(let j=0;j<data1.length;j++){
  56 + if (data1.indexOf(data2[i].classId+".mp4") == -1) {
  57 + console.log("不存在:"+data2[i])
  58 + data.push(data2[i])
49 } 59 }
50 } 60 }
  61 + console.log("data",data)
  62 + return resolve(data)
  63 + })
  64 + }
  65 + async mediaCreat(id, siteId) {
  66 + let mediaDir = PROJECTCATALOG + "/media/"
  67 + let classDir = PROJECTCATALOG + "/media/" + siteId
  68 + let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + ymd
  69 + if (!fs.existsSync(mediaDir)) {
  70 + fs.mkdirSync(mediaDir);
  71 + }
  72 + if (!fs.existsSync(classDir)) {
  73 + fs.mkdirSync(classDir);
51 } 74 }
52 - });  
53 - // workerProcess.stderr.on('data', function (data) {  
54 - // console.log('stderr: ' + data);  
55 - // }); 75 + if (!fs.existsSync(ymdDir)) {
  76 + fs.mkdirSync(ymdDir);
  77 + }
  78 + let url = `web_capture_c -o=../media/${siteId}/${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}`
  79 + var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })
  80 + // workerProcess.stdout.on('data', async function (data) {
  81 +
  82 + // });
56 83
57 - // workerProcess.on('close', function (code) {  
58 - // console.log('子进程已退出,退出码 '+code);  
59 - // }); 84 + workerProcess.on('close', async function (code) {
  85 + if (code == 0) {
  86 + if (classid.length) {
  87 + let shiftData = classid.shift()
  88 + new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
  89 + } else {
  90 + // 判断是否有缺录
  91 + // let files = fs.readdirSync(ymdDir);
  92 + // if (files.length != parentData.length) {
  93 + // let notResult = await new MediaCreat().notResult(files,parentData)
  94 + // }
  95 + if (siteIds.length) {
  96 + // 如果有多家需要录制,继续录制下一家
  97 + let isAppend = await new MediaCreat().allData()
  98 + if (isAppend) {
  99 + let shiftData = classid.shift()
  100 + new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
  101 + }
  102 + }
  103 + }
  104 + } else {
  105 + new MediaCreat().mediaCreat(id, siteId)
  106 + }
  107 + });
  108 + }
60 } 109 }
61 110
  111 +
62 router.get('/', async function (req, res, next) { 112 router.get('/', async function (req, res, next) {
63 - className = siteIds.shift()  
64 - let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime)  
65 - if (result.data && result.data.code == 0) {  
66 - // 成功  
67 - classid = result.data.data.list  
68 - if (classid.length) {  
69 - for (let i = 0; i < 10; i++) {  
70 - let id = classid.shift()  
71 - if (id) {  
72 - mediaCreat(id['classId'])  
73 - }else{  
74 - return false  
75 - } 113 + let isAppend = await new MediaCreat().allData()
  114 + if (isAppend) {
  115 + if (classid.length) {
  116 + for (let i = 0; i < maxMedia; i++) {
  117 + let shiftData = classid.shift()
  118 + if (shiftData) {
  119 + new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
  120 + } else {
  121 + return false
76 } 122 }
77 } 123 }
  124 + }
78 } 125 }
  126 +
79 res.render('index', { title: 'Express' }); 127 res.render('index', { title: 'Express' });
80 }); 128 });
81 129
webScreen @ 3ad40110
  1 +Subproject commit 3ad4011072147004f3e1cc8db37eada85d7fcc17
不能预览此文件类型