tronclass-auto 1.2.3 → 1.2.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/index.js +1 -1
- package/src/video.js +16 -12
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/video.js
CHANGED
|
@@ -15,11 +15,11 @@ function formatTime(seconds) {
|
|
|
15
15
|
async function watchVideo(page, stats) {
|
|
16
16
|
const hasVideo = await page.evaluate(() => document.querySelector('video') !== null);
|
|
17
17
|
if (!hasVideo) {
|
|
18
|
-
log(chalk.yellow('
|
|
18
|
+
log(chalk.yellow(' No video element'));
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
log(chalk.blue('
|
|
22
|
+
log(chalk.blue(' Muted + 2x'));
|
|
23
23
|
|
|
24
24
|
await page.evaluate(() => {
|
|
25
25
|
document.querySelectorAll('video').forEach(v => {
|
|
@@ -38,7 +38,7 @@ async function watchVideo(page, stats) {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
if (!isPlaying) {
|
|
41
|
-
log(chalk.yellow('
|
|
41
|
+
log(chalk.yellow(' Clicking play...'));
|
|
42
42
|
await page.evaluate(() => {
|
|
43
43
|
document.querySelectorAll('[class*="play"], .vjs-big-play-button, button').forEach(btn => {
|
|
44
44
|
if (btn.offsetParent && (btn.className.includes('play') || btn.className.includes('Play'))) {
|
|
@@ -56,14 +56,14 @@ async function watchVideo(page, stats) {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
if (!duration || duration <= 0) {
|
|
59
|
-
log(chalk.yellow('
|
|
59
|
+
log(chalk.yellow(' Cannot get duration, waiting 30s...'));
|
|
60
60
|
await page.waitForTimeout(30000);
|
|
61
61
|
if (stats) stats.videosWatched++;
|
|
62
62
|
return true;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const waitTime = (duration / 2) + 15;
|
|
66
|
-
log(chalk.blue(`
|
|
66
|
+
log(chalk.blue(` ${formatTime(duration)} video → ~${formatTime(waitTime)} (2x)`));
|
|
67
67
|
|
|
68
68
|
if (stats) {
|
|
69
69
|
stats.currentVideoDuration = duration / 2;
|
|
@@ -93,26 +93,30 @@ async function watchVideo(page, stats) {
|
|
|
93
93
|
|
|
94
94
|
if (state.p > lastPct) {
|
|
95
95
|
const pct = state.p;
|
|
96
|
+
const barWidth = 20;
|
|
97
|
+
const filled = Math.floor(barWidth * pct / 100);
|
|
98
|
+
const empty = barWidth - filled;
|
|
99
|
+
const bar = chalk.green('█'.repeat(filled)) + chalk.gray('░'.repeat(empty));
|
|
96
100
|
const remaining = Math.max(0, waitTime - elapsed);
|
|
97
101
|
let etaStr = '';
|
|
98
102
|
if (stats && stats.remainingVideos > 0) {
|
|
99
103
|
const totalRemaining = remaining + stats.estimatedTimeForRemaining;
|
|
100
|
-
etaStr = chalk.gray(` | ETA
|
|
104
|
+
etaStr = chalk.gray(` | ETA ${formatTime(totalRemaining)}`);
|
|
101
105
|
} else {
|
|
102
|
-
etaStr = chalk.gray(` |
|
|
106
|
+
etaStr = chalk.gray(` | ${formatTime(remaining)} left`);
|
|
103
107
|
}
|
|
104
|
-
log(chalk.blue(`
|
|
108
|
+
log(chalk.blue(` ${bar} ${String(pct).padStart(3)}% (${formatTime(elapsed)})${etaStr}`));
|
|
105
109
|
lastPct = pct;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
if (state.e) {
|
|
109
|
-
log(chalk.green('
|
|
113
|
+
log(chalk.green(' Done ✓'));
|
|
110
114
|
break;
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
if (state.stalled) {
|
|
114
118
|
if (elapsed % 15 === 0) {
|
|
115
|
-
log(chalk.gray(`
|
|
119
|
+
log(chalk.gray(` Buffering... (${formatTime(elapsed)})`));
|
|
116
120
|
}
|
|
117
121
|
continue;
|
|
118
122
|
}
|
|
@@ -127,10 +131,10 @@ async function watchVideo(page, stats) {
|
|
|
127
131
|
|
|
128
132
|
restartCount++;
|
|
129
133
|
if (restartCount > 10) {
|
|
130
|
-
log(chalk.red('
|
|
134
|
+
log(chalk.red(' Too many restarts, giving up'));
|
|
131
135
|
return false;
|
|
132
136
|
}
|
|
133
|
-
log(chalk.yellow(`
|
|
137
|
+
log(chalk.yellow(` Paused, restarting (#${restartCount})...`));
|
|
134
138
|
await page.evaluate(() => document.querySelector('video').play());
|
|
135
139
|
await page.waitForTimeout(1000);
|
|
136
140
|
}
|