tronclass-auto 1.3.3 → 1.3.4
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 +24 -5
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
|
|
|
@@ -112,11 +113,29 @@ async function processCourse(page, courseId, stats) {
|
|
|
112
113
|
await page.waitForTimeout(5000);
|
|
113
114
|
|
|
114
115
|
if (!page.url().includes('learning-activity')) {
|
|
115
|
-
console.log(chalk.yellow('
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
console.log(chalk.yellow(' Locked (page redirect), skipping rest'));
|
|
117
|
+
markLocked(courseId, act.id);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const hasVideo = await page.evaluate(() => document.querySelector('video') !== null);
|
|
122
|
+
if (!hasVideo) {
|
|
123
|
+
consecutiveLocked++;
|
|
124
|
+
if (consecutiveLocked >= 2) {
|
|
125
|
+
console.log(chalk.yellow(' Locked (no video), stopping this course'));
|
|
126
|
+
markLocked(courseId, act.id);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
console.log(chalk.yellow(' No video, might be loading... waiting'));
|
|
130
|
+
await page.waitForTimeout(5000);
|
|
131
|
+
const hasVideoNow = await page.evaluate(() => document.querySelector('video') !== null);
|
|
132
|
+
if (!hasVideoNow) {
|
|
133
|
+
console.log(chalk.yellow(' Still no video, locked'));
|
|
134
|
+
markLocked(courseId, act.id);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
consecutiveLocked = 0;
|
|
120
139
|
}
|
|
121
140
|
|
|
122
141
|
try {
|