tronclass-auto 1.3.9 → 1.4.1
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 +30 -3
- package/src/video.js +53 -24
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -157,9 +157,36 @@ async function processCourse(page, courseId, stats) {
|
|
|
157
157
|
}
|
|
158
158
|
const success = await watchVideo(page, stats);
|
|
159
159
|
if (success) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
await page.waitForTimeout(5000);
|
|
161
|
+
await page.goto(`${BASE_URL}/course/${courseId}/content#/`, {
|
|
162
|
+
waitUntil: 'domcontentloaded', timeout: 15000
|
|
163
|
+
}).catch(() => {});
|
|
164
|
+
await page.waitForTimeout(3000);
|
|
165
|
+
|
|
166
|
+
const serverComplete = await page.evaluate((actId) => {
|
|
167
|
+
const el = document.querySelector('.learning-activities');
|
|
168
|
+
if (!el) return false;
|
|
169
|
+
const scope = angular.element(el).scope();
|
|
170
|
+
if (!scope) return false;
|
|
171
|
+
const activities = document.querySelectorAll('.learning-activity.sortable');
|
|
172
|
+
for (const actEl of activities) {
|
|
173
|
+
const actScope = angular.element(actEl).scope();
|
|
174
|
+
if (!actScope || !actScope.activity) continue;
|
|
175
|
+
if (actScope.activity.id == actId) {
|
|
176
|
+
try { return scope.getActivityCompleteness(actScope.activity) === 'full'; } catch (e) {}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}, act.id);
|
|
181
|
+
|
|
182
|
+
if (serverComplete) {
|
|
183
|
+
markDone(courseId, act.id);
|
|
184
|
+
done++;
|
|
185
|
+
console.log(chalk.green(' ✓ Saved (server confirmed)'));
|
|
186
|
+
} else {
|
|
187
|
+
console.log(chalk.yellow(' Server not confirmed yet, will retry next run'));
|
|
188
|
+
fail++;
|
|
189
|
+
}
|
|
163
190
|
} else {
|
|
164
191
|
fail++;
|
|
165
192
|
}
|
package/src/video.js
CHANGED
|
@@ -61,33 +61,57 @@ async function watchYouTube(page, stats) {
|
|
|
61
61
|
try {
|
|
62
62
|
const ytFrame = page.locator('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
63
63
|
await ytFrame.click({ timeout: 5000 }).catch(() => {});
|
|
64
|
-
await page.waitForTimeout(
|
|
64
|
+
await page.waitForTimeout(3000);
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
await page.evaluate(() => {
|
|
67
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
68
|
+
if (!f) return;
|
|
69
|
+
f.contentWindow.postMessage('{"event":"listening"}', '*');
|
|
70
|
+
});
|
|
69
71
|
await page.waitForTimeout(2000);
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
await page.evaluate(() => {
|
|
74
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
75
|
+
if (!f) return;
|
|
76
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'playVideo', args: [] }), '*');
|
|
77
|
+
});
|
|
78
|
+
await page.waitForTimeout(1000);
|
|
79
|
+
|
|
80
|
+
await page.evaluate(() => {
|
|
81
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
82
|
+
if (!f) return;
|
|
83
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'mute', args: [] }), '*');
|
|
84
|
+
});
|
|
85
|
+
await page.waitForTimeout(1000);
|
|
86
|
+
|
|
87
|
+
await page.evaluate(() => {
|
|
88
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
89
|
+
if (!f) return;
|
|
90
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'setPlaybackRate', args: [2] }), '*');
|
|
91
|
+
});
|
|
92
|
+
await page.waitForTimeout(2000);
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
const rate = await page.evaluate(() => {
|
|
95
|
+
return new Promise((resolve) => {
|
|
96
|
+
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
97
|
+
if (!f) { resolve(1); return; }
|
|
98
|
+
const handler = (e) => {
|
|
99
|
+
let rate = 1;
|
|
100
|
+
try {
|
|
101
|
+
const d = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
|
|
102
|
+
if (d.event === 'infoDelivery' && d.info && d.info.playbackRate) {
|
|
103
|
+
resolve(d.info.playbackRate);
|
|
104
|
+
}
|
|
105
|
+
} catch(e) {}
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener('message', handler);
|
|
108
|
+
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'getPlaybackRate', args: [] }), '*');
|
|
109
|
+
setTimeout(() => { window.removeEventListener('message', handler); resolve(1); }, 3000);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
log(chalk.blue(` Speed: ${rate}x ✓`));
|
|
89
113
|
} catch (e) {
|
|
90
|
-
log(chalk.yellow(
|
|
114
|
+
log(chalk.yellow(` YouTube setup error: ${e.message}`));
|
|
91
115
|
}
|
|
92
116
|
|
|
93
117
|
await page.waitForTimeout(2000);
|
|
@@ -101,8 +125,13 @@ async function watchYouTube(page, stats) {
|
|
|
101
125
|
return 180;
|
|
102
126
|
});
|
|
103
127
|
|
|
104
|
-
const waitTime = Math.ceil(ytDuration / 2) + 30;
|
|
105
|
-
log(chalk.blue(` ~${formatTime(ytDuration)} video → ~${formatTime(waitTime)} (
|
|
128
|
+
const waitTime = (rate >= 2 ? Math.ceil(ytDuration / 2) : ytDuration) + 30;
|
|
129
|
+
log(chalk.blue(` ~${formatTime(ytDuration)} video → ~${formatTime(waitTime)} (${rate}x)`));
|
|
130
|
+
|
|
131
|
+
if (stats) {
|
|
132
|
+
stats.currentVideoDuration = ytDuration;
|
|
133
|
+
stats.currentVideoElapsed = 0;
|
|
134
|
+
}
|
|
106
135
|
|
|
107
136
|
let elapsed = 0;
|
|
108
137
|
let lastPct = -1;
|