tronclass-auto 1.5.4 → 1.5.6
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 +26 -20
package/package.json
CHANGED
package/src/video.js
CHANGED
|
@@ -66,18 +66,19 @@ async function watchYouTube(page, stats) {
|
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
return await ytFrame.evaluate(code).catch(() => null);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
log(chalk.blue(' Starting video...'));
|
|
69
|
+
log(chalk.gray(` Frame found: ${ytFrame.url().substring(0, 60)}`));
|
|
74
70
|
|
|
75
71
|
let playerReady = false;
|
|
76
|
-
for (let attempt = 0; attempt <
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
for (let attempt = 0; attempt < 15; attempt++) {
|
|
73
|
+
try {
|
|
74
|
+
const ready = await ytFrame.evaluate(() => {
|
|
75
|
+
const p = document.querySelector('#movie_player');
|
|
76
|
+
return !!(p && typeof p.playVideo === 'function');
|
|
77
|
+
});
|
|
78
|
+
if (ready) { playerReady = true; break; }
|
|
79
|
+
} catch (e) {}
|
|
80
|
+
if (attempt % 3 === 0) log(chalk.gray(` Waiting for player... (${attempt + 1}/15)`));
|
|
81
|
+
await page.waitForTimeout(2000);
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
if (!playerReady) {
|
|
@@ -85,27 +86,32 @@ async function watchYouTube(page, stats) {
|
|
|
85
86
|
return false;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
await
|
|
89
|
+
log(chalk.blue(' Starting video...'));
|
|
90
|
+
await ytFrame.evaluate(() => document.querySelector('#movie_player').playVideo());
|
|
91
|
+
await page.waitForTimeout(5000);
|
|
90
92
|
|
|
91
|
-
const state1 = await
|
|
93
|
+
const state1 = await ytFrame.evaluate(() => document.querySelector('#movie_player').getPlayerState());
|
|
92
94
|
if (state1 !== 1) {
|
|
93
|
-
log(chalk.yellow(
|
|
94
|
-
await
|
|
95
|
+
log(chalk.yellow(` State: ${state1}, retrying...`));
|
|
96
|
+
await ytFrame.evaluate(() => document.querySelector('#movie_player').playVideo());
|
|
95
97
|
await page.waitForTimeout(5000);
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
await
|
|
99
|
-
|
|
100
|
+
await ytFrame.evaluate(() => {
|
|
101
|
+
const p = document.querySelector('#movie_player');
|
|
102
|
+
p.mute();
|
|
103
|
+
p.setPlaybackRate(2);
|
|
104
|
+
});
|
|
105
|
+
await page.waitForTimeout(3000);
|
|
100
106
|
|
|
101
|
-
rate = await
|
|
107
|
+
rate = await ytFrame.evaluate(() => document.querySelector('#movie_player').getPlaybackRate());
|
|
102
108
|
log(chalk.blue(` Speed: ${rate}x`));
|
|
103
109
|
|
|
104
|
-
const state2 = await
|
|
110
|
+
const state2 = await ytFrame.evaluate(() => document.querySelector('#movie_player').getPlayerState());
|
|
105
111
|
if (state2 === 1) {
|
|
106
112
|
log(chalk.green(' Playing ✓'));
|
|
107
113
|
} else {
|
|
108
|
-
log(chalk.yellow(`
|
|
114
|
+
log(chalk.yellow(` Final state: ${state2}`));
|
|
109
115
|
}
|
|
110
116
|
} catch (e) {
|
|
111
117
|
log(chalk.yellow(` YouTube error: ${e.message}`));
|