tronclass-auto 1.5.3 → 1.5.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/video.js +21 -7
package/package.json
CHANGED
package/src/video.js
CHANGED
|
@@ -71,23 +71,37 @@ async function watchYouTube(page, stats) {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
log(chalk.blue(' Starting video...'));
|
|
74
|
-
|
|
74
|
+
|
|
75
|
+
let playerReady = false;
|
|
76
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
77
|
+
const ready = await evalYT("() => { const p = document.querySelector('#movie_player'); return p && typeof p.playVideo === 'function'; }");
|
|
78
|
+
if (ready) { playerReady = true; break; }
|
|
79
|
+
log(chalk.gray(` Waiting for player... (${attempt + 1}/10)`));
|
|
80
|
+
await page.waitForTimeout(3000);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!playerReady) {
|
|
84
|
+
log(chalk.yellow(' YouTube player not loaded'));
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await evalYT("() => { const p = document.querySelector('#movie_player'); p.playVideo(); }");
|
|
75
89
|
await page.waitForTimeout(3000);
|
|
76
90
|
|
|
77
|
-
const state1 = await evalYT("() =>
|
|
91
|
+
const state1 = await evalYT("() => document.querySelector('#movie_player').getPlayerState()");
|
|
78
92
|
if (state1 !== 1) {
|
|
79
93
|
log(chalk.yellow(' Retrying play...'));
|
|
80
|
-
await evalYT("() => { const p = document.querySelector('#movie_player');
|
|
81
|
-
await page.waitForTimeout(
|
|
94
|
+
await evalYT("() => { const p = document.querySelector('#movie_player'); p.playVideo(); }");
|
|
95
|
+
await page.waitForTimeout(5000);
|
|
82
96
|
}
|
|
83
97
|
|
|
84
|
-
await evalYT("() => { const p = document.querySelector('#movie_player');
|
|
98
|
+
await evalYT("() => { const p = document.querySelector('#movie_player'); p.mute(); p.setPlaybackRate(2); }");
|
|
85
99
|
await page.waitForTimeout(2000);
|
|
86
100
|
|
|
87
|
-
rate = await evalYT("() =>
|
|
101
|
+
rate = await evalYT("() => document.querySelector('#movie_player').getPlaybackRate()") || 1;
|
|
88
102
|
log(chalk.blue(` Speed: ${rate}x`));
|
|
89
103
|
|
|
90
|
-
const state2 = await evalYT("() =>
|
|
104
|
+
const state2 = await evalYT("() => document.querySelector('#movie_player').getPlayerState()");
|
|
91
105
|
if (state2 === 1) {
|
|
92
106
|
log(chalk.green(' Playing ✓'));
|
|
93
107
|
} else {
|