tronclass-auto 1.5.2 → 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 +31 -28
package/package.json
CHANGED
package/src/video.js
CHANGED
|
@@ -21,27 +21,22 @@ function log(msg) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async function detectPlayerType(page) {
|
|
24
|
-
|
|
24
|
+
const type = await page.evaluate(() => {
|
|
25
25
|
const v = document.querySelector('video');
|
|
26
26
|
if (v) return 'html5';
|
|
27
|
-
|
|
28
27
|
const yt = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"], iframe[src*="vimeo"]');
|
|
29
28
|
if (yt) return 'youtube';
|
|
30
|
-
|
|
31
29
|
for (const f of document.querySelectorAll('iframe')) {
|
|
32
|
-
try {
|
|
33
|
-
if (f.contentDocument && f.contentDocument.querySelector('video')) return 'html5';
|
|
34
|
-
} catch (e) {}
|
|
30
|
+
try { if (f.contentDocument && f.contentDocument.querySelector('video')) return 'html5'; } catch (e) {}
|
|
35
31
|
}
|
|
36
32
|
return 'none';
|
|
37
|
-
}).then(async (type) => {
|
|
38
|
-
if (type === 'none') {
|
|
39
|
-
for (const f of page.frames) {
|
|
40
|
-
if (f.url && (f.url.includes('youtube') || f.url.includes('youtu.be'))) return 'youtube';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return type;
|
|
44
33
|
});
|
|
34
|
+
if (type !== 'none') return type;
|
|
35
|
+
try {
|
|
36
|
+
const ytFrame = page.frame({ url: /youtube|youtu\.be/ });
|
|
37
|
+
if (ytFrame) return 'youtube';
|
|
38
|
+
} catch (e) {}
|
|
39
|
+
return 'none';
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
async function watchVideo(page, stats) {
|
|
@@ -64,13 +59,7 @@ async function watchYouTube(page, stats) {
|
|
|
64
59
|
let rate = 1;
|
|
65
60
|
|
|
66
61
|
try {
|
|
67
|
-
|
|
68
|
-
for (const f of page.frames) {
|
|
69
|
-
if (f.url && (f.url.includes('youtube') || f.url.includes('youtu.be'))) {
|
|
70
|
-
ytFrame = f;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
62
|
+
const ytFrame = page.frame({ url: /youtube|youtu\.be/ });
|
|
74
63
|
|
|
75
64
|
if (!ytFrame) {
|
|
76
65
|
log(chalk.yellow(' YouTube frame not found'));
|
|
@@ -82,27 +71,41 @@ async function watchYouTube(page, stats) {
|
|
|
82
71
|
};
|
|
83
72
|
|
|
84
73
|
log(chalk.blue(' Starting video...'));
|
|
85
|
-
|
|
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(); }");
|
|
86
89
|
await page.waitForTimeout(3000);
|
|
87
90
|
|
|
88
|
-
const state1 = await evalYT("() =>
|
|
91
|
+
const state1 = await evalYT("() => document.querySelector('#movie_player').getPlayerState()");
|
|
89
92
|
if (state1 !== 1) {
|
|
90
93
|
log(chalk.yellow(' Retrying play...'));
|
|
91
|
-
await evalYT("() => { const p = document.querySelector('#movie_player');
|
|
92
|
-
await page.waitForTimeout(
|
|
94
|
+
await evalYT("() => { const p = document.querySelector('#movie_player'); p.playVideo(); }");
|
|
95
|
+
await page.waitForTimeout(5000);
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
await evalYT("() => { const p = document.querySelector('#movie_player');
|
|
98
|
+
await evalYT("() => { const p = document.querySelector('#movie_player'); p.mute(); p.setPlaybackRate(2); }");
|
|
96
99
|
await page.waitForTimeout(2000);
|
|
97
100
|
|
|
98
|
-
rate = await evalYT("() =>
|
|
101
|
+
rate = await evalYT("() => document.querySelector('#movie_player').getPlaybackRate()") || 1;
|
|
99
102
|
log(chalk.blue(` Speed: ${rate}x`));
|
|
100
103
|
|
|
101
|
-
const state2 = await evalYT("() =>
|
|
104
|
+
const state2 = await evalYT("() => document.querySelector('#movie_player').getPlayerState()");
|
|
102
105
|
if (state2 === 1) {
|
|
103
106
|
log(chalk.green(' Playing ✓'));
|
|
104
107
|
} else {
|
|
105
|
-
log(chalk.yellow(` State: ${state2}
|
|
108
|
+
log(chalk.yellow(` State: ${state2}`));
|
|
106
109
|
}
|
|
107
110
|
} catch (e) {
|
|
108
111
|
log(chalk.yellow(` YouTube error: ${e.message}`));
|