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