tronclass-auto 1.4.1 → 1.4.3
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/index.js +10 -2
- package/src/video.js +27 -5
package/package.json
CHANGED
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 serverRejects = {};
|
|
84
85
|
let consecutiveLocked = 0;
|
|
85
86
|
|
|
86
87
|
console.log(chalk.cyan(` [fetching course activities...]`));
|
|
@@ -184,8 +185,15 @@ async function processCourse(page, courseId, stats) {
|
|
|
184
185
|
done++;
|
|
185
186
|
console.log(chalk.green(' ✓ Saved (server confirmed)'));
|
|
186
187
|
} else {
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
serverRejects[act.id] = (serverRejects[act.id] || 0) + 1;
|
|
189
|
+
if (serverRejects[act.id] >= 2) {
|
|
190
|
+
console.log(chalk.yellow(' Server rejected twice, marking done locally'));
|
|
191
|
+
markDone(courseId, act.id);
|
|
192
|
+
done++;
|
|
193
|
+
} else {
|
|
194
|
+
console.log(chalk.yellow(' Server not confirmed, will retry...'));
|
|
195
|
+
fail++;
|
|
196
|
+
}
|
|
189
197
|
}
|
|
190
198
|
} else {
|
|
191
199
|
fail++;
|
package/src/video.js
CHANGED
|
@@ -57,6 +57,7 @@ async function watchVideo(page, stats) {
|
|
|
57
57
|
|
|
58
58
|
async function watchYouTube(page, stats) {
|
|
59
59
|
log(chalk.blue(' YouTube embed'));
|
|
60
|
+
let rate = 1;
|
|
60
61
|
|
|
61
62
|
try {
|
|
62
63
|
const ytFrame = page.locator('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
@@ -91,15 +92,15 @@ async function watchYouTube(page, stats) {
|
|
|
91
92
|
});
|
|
92
93
|
await page.waitForTimeout(2000);
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
rate = await page.evaluate(() => {
|
|
95
96
|
return new Promise((resolve) => {
|
|
96
97
|
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
97
98
|
if (!f) { resolve(1); return; }
|
|
98
99
|
const handler = (e) => {
|
|
99
|
-
|
|
100
|
-
try {
|
|
100
|
+
try {
|
|
101
101
|
const d = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
|
|
102
102
|
if (d.event === 'infoDelivery' && d.info && d.info.playbackRate) {
|
|
103
|
+
window.removeEventListener('message', handler);
|
|
103
104
|
resolve(d.info.playbackRate);
|
|
104
105
|
}
|
|
105
106
|
} catch(e) {}
|
|
@@ -109,7 +110,7 @@ async function watchYouTube(page, stats) {
|
|
|
109
110
|
setTimeout(() => { window.removeEventListener('message', handler); resolve(1); }, 3000);
|
|
110
111
|
});
|
|
111
112
|
});
|
|
112
|
-
log(chalk.blue(` Speed: ${rate}x
|
|
113
|
+
log(chalk.blue(` Speed: ${rate}x`));
|
|
113
114
|
} catch (e) {
|
|
114
115
|
log(chalk.yellow(` YouTube setup error: ${e.message}`));
|
|
115
116
|
}
|
|
@@ -159,7 +160,28 @@ async function watchYouTube(page, stats) {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
log(chalk.green(' Done ✓'));
|
|
162
|
-
|
|
163
|
+
log(chalk.gray(' Syncing with platform...'));
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < 5; i++) {
|
|
166
|
+
await page.evaluate(() => {
|
|
167
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
168
|
+
if (!f) return;
|
|
169
|
+
try {
|
|
170
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'seekTo', args: [670, true] }), '*');
|
|
171
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'playVideo', args: [] }), '*');
|
|
172
|
+
} catch(e) {}
|
|
173
|
+
});
|
|
174
|
+
await page.waitForTimeout(3000);
|
|
175
|
+
await page.evaluate(() => {
|
|
176
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
177
|
+
if (!f) return;
|
|
178
|
+
try {
|
|
179
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'pauseVideo', args: [] }), '*');
|
|
180
|
+
} catch(e) {}
|
|
181
|
+
});
|
|
182
|
+
await page.waitForTimeout(2000);
|
|
183
|
+
}
|
|
184
|
+
|
|
163
185
|
if (stats) stats.videosWatched++;
|
|
164
186
|
return true;
|
|
165
187
|
}
|