-
Notifications
You must be signed in to change notification settings - Fork 116
/
file.js
50 lines (41 loc) · 991 Bytes
/
file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { launch, getStream } = require("../");
const fs = require("fs");
const utils = require("../tests/_utils");
async function youtube(browser, i = 0) {
const file = fs.createWriteStream(__dirname + "/test" + i + ".webm", {
highWaterMark: 1024
});
const page = await browser.newPage();
await page.goto("https://www.youtube.com/embed/9bZkp7q19f0?autoplay=1&vq=hd1080&start=30");
await page.setViewport({
width: 1920,
height: 1080,
});
const stream = await getStream(page, {
audio: true,
video: true,
videoConstraints: {
mandatory: {
maxWidth: 1920,
maxHeight: 1080,
},
},
});
console.log("recording");
stream.pipe(file);
setTimeout(async () => {
stream.destroy();
file.close();
console.log("finished");
await page.close();
}, 1000 * 30);
}
async function main() {
const browser = await launch({
executablePath: utils.getExecutablePath(),
});
for (let i = 0; i < 2; i++) {
youtube(browser, i).catch(console.error);
}
}
main()