张艾宸

一次性获取所有录制课堂的数据 1.1

@@ -3,7 +3,7 @@ const GETCLASSURLPARAMETER = { @@ -3,7 +3,7 @@ const GETCLASSURLPARAMETER = {
3 siteId:["BuzzKID","kuaikuenglish"], 3 siteId:["BuzzKID","kuaikuenglish"],
4 key:"xdymp4record20191225", 4 key:"xdymp4record20191225",
5 page:1, 5 page:1,
6 - maxMedia:1, 6 + maxMedia:3,
7 } 7 }
8 8
9 const PROJECTWINCATALOG = "E:/project/web_capture_release/win-x64" 9 const PROJECTWINCATALOG = "E:/project/web_capture_release/win-x64"
@@ -24,29 +24,27 @@ class MediaCreat { @@ -24,29 +24,27 @@ class MediaCreat {
24 constructor() { } 24 constructor() { }
25 // 取出所有数据 25 // 取出所有数据
26 async allData() { 26 async allData() {
27 - let page = 1  
28 className = siteIds.shift() 27 className = siteIds.shift()
  28 + let page = 1
29 if (className) { 29 if (className) {
30 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page) 30 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page)
31 - parentData[result.data.data.siteId] = []  
32 - 31 + parentData[result.data.data.siteId] = new Set()
33 for (let j = 0; j < result.data.data.list.length; j++) { 32 for (let j = 0; j < result.data.data.list.length; j++) {
34 classid.push(result.data.data.list[j]) 33 classid.push(result.data.data.list[j])
  34 + parentData[result.data.data.siteId].add(result.data.data.list[j]['classId'])
35 } 35 }
36 const { siteId, list, totalPage } = result.data.data 36 const { siteId, list, totalPage } = result.data.data
37 for (let i = page += 1; i <= totalPage; i++) { 37 for (let i = page += 1; i <= totalPage; i++) {
38 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i) 38 let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i)
39 for (let j = 0; j < result.data.data.list.length; j++) { 39 for (let j = 0; j < result.data.data.list.length; j++) {
40 classid.push(result.data.data.list[j]) 40 classid.push(result.data.data.list[j])
  41 + parentData[result.data.data.siteId].add(result.data.data.list[j]['classId'])
41 } 42 }
42 } 43 }
  44 + parentData[result.data.data.siteId] = Array.from(parentData[result.data.data.siteId])
43 45
44 - classid = classid.reduce(function (item, next) {  
45 - classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next);  
46 - return item;  
47 - }, []);  
48 - for (let i = 0; i < classid.length; i++) {  
49 - parentData[result.data.data.siteId].push(classid[i].classId) 46 + if (siteIds.length) {
  47 + return await new MediaCreat().allData()
50 } 48 }
51 return true 49 return true
52 } else { 50 } else {
@@ -93,15 +91,6 @@ class MediaCreat { @@ -93,15 +91,6 @@ class MediaCreat {
93 if (classid.length) { 91 if (classid.length) {
94 let shiftData = classid.shift() 92 let shiftData = classid.shift()
95 new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) 93 new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])
96 - } else {  
97 - if (siteIds.length) {  
98 - // 如果有多家需要录制,继续录制下一家  
99 - let isAppend = await new MediaCreat().allData()  
100 - if (isAppend) {  
101 - let shiftData = classid.shift()  
102 - new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId'])  
103 - }  
104 - }  
105 } 94 }
106 } 95 }
107 }); 96 });
@@ -110,8 +99,13 @@ class MediaCreat { @@ -110,8 +99,13 @@ class MediaCreat {
110 99
111 100
112 router.get('/', async function (req, res, next) { 101 router.get('/', async function (req, res, next) {
113 - let isAppend = await new MediaCreat().allData()  
114 - if (isAppend) { 102 + let result = await new MediaCreat().allData()
  103 + if (result) {
  104 + // 去重
  105 + classid = classid.reduce(function (item, next) {
  106 + classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next);
  107 + return item;
  108 + }, []);
115 if (classid.length) { 109 if (classid.length) {
116 for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) { 110 for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) {
117 let shiftData = classid.shift() 111 let shiftData = classid.shift()
@@ -122,9 +116,8 @@ router.get('/', async function (req, res, next) { @@ -122,9 +116,8 @@ router.get('/', async function (req, res, next) {
122 } 116 }
123 } 117 }
124 } 118 }
  119 + res.send({ code: "0" });
125 } 120 }
126 -  
127 - res.render('index', { title: 'Express' });  
128 }); 121 });
129 122
130 module.exports = router; 123 module.exports = router;