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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tronclass-auto",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
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}`] = true;
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(' [WARN] Failed to load, locked or skipped'));
116
- skip++;
117
- markDone(courseId, act.id);
118
- totalProcessed++;
119
- continue;
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 {