tronclass-auto 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config.js +8 -2
- package/src/index.js +31 -6
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -54,7 +54,13 @@ function saveProgress(data) {
|
|
|
54
54
|
|
|
55
55
|
function markDone(courseId, activityId) {
|
|
56
56
|
const p = loadProgress();
|
|
57
|
-
p[`${courseId}_${activityId}`] =
|
|
57
|
+
p[`${courseId}_${activityId}`] = 'done';
|
|
58
|
+
saveProgress(p);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function markLocked(courseId, activityId) {
|
|
62
|
+
const p = loadProgress();
|
|
63
|
+
p[`${courseId}_${activityId}`] = 'locked';
|
|
58
64
|
saveProgress(p);
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -154,5 +160,5 @@ module.exports = {
|
|
|
154
160
|
CONFIG_DIR, CONFIG_FILE, PROGRESS_FILE, COOKIE_FILE, SALT_FILE,
|
|
155
161
|
BASE_URL, DEFAULT_CONFIG,
|
|
156
162
|
ensureDir, loadConfig, saveConfig,
|
|
157
|
-
loadProgress, saveProgress, markDone, isDone, showConfig, manageCourses
|
|
163
|
+
loadProgress, saveProgress, markDone, markLocked, isDone, showConfig, manageCourses
|
|
158
164
|
};
|
package/src/index.js
CHANGED
|
@@ -81,6 +81,7 @@ async function processCourse(page, courseId, stats) {
|
|
|
81
81
|
let skip = 0;
|
|
82
82
|
let fail = 0;
|
|
83
83
|
let totalProcessed = 0;
|
|
84
|
+
let consecutiveLocked = 0;
|
|
84
85
|
|
|
85
86
|
console.log(chalk.cyan(` [fetching course activities...]`));
|
|
86
87
|
|
|
@@ -109,14 +110,38 @@ async function processCourse(page, courseId, stats) {
|
|
|
109
110
|
try {
|
|
110
111
|
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 15000 });
|
|
111
112
|
} catch (e) {}
|
|
112
|
-
await page.waitForTimeout(
|
|
113
|
+
await page.waitForTimeout(8000);
|
|
113
114
|
|
|
114
115
|
if (!page.url().includes('learning-activity')) {
|
|
115
|
-
console.log(chalk.yellow('
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
console.log(chalk.yellow(' Page redirect, skipping'));
|
|
117
|
+
markLocked(courseId, act.id);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const hasVideo = await page.evaluate(() => {
|
|
122
|
+
if (document.querySelector('video')) return true;
|
|
123
|
+
for (const f of document.querySelectorAll('iframe')) {
|
|
124
|
+
try { if (f.contentDocument && f.contentDocument.querySelector('video')) return true; } catch (e) {}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
});
|
|
128
|
+
if (!hasVideo) {
|
|
129
|
+
console.log(chalk.yellow(' No video, waiting more...'));
|
|
130
|
+
await page.waitForTimeout(10000);
|
|
131
|
+
const hasVideoNow = await page.evaluate(() => {
|
|
132
|
+
if (document.querySelector('video')) return true;
|
|
133
|
+
for (const f of document.querySelectorAll('iframe')) {
|
|
134
|
+
try { if (f.contentDocument && f.contentDocument.querySelector('video')) return true; } catch (e) {}
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
});
|
|
138
|
+
if (!hasVideoNow) {
|
|
139
|
+
console.log(chalk.yellow(' Still no video, skipping (not a video activity)'));
|
|
140
|
+
markLocked(courseId, act.id);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
consecutiveLocked = 0;
|
|
120
145
|
}
|
|
121
146
|
|
|
122
147
|
try {
|