Skip to content

Instantly share code, notes, and snippets.

@ali-em
Last active October 16, 2021 20:43
Show Gist options
  • Save ali-em/091cfe675889ae9a2d9c312ed6ae2c10 to your computer and use it in GitHub Desktop.
Save ali-em/091cfe675889ae9a2d9c312ed6ae2c10 to your computer and use it in GitHub Desktop.
Recording Adobe Connect showable videos using puppeteer-stream
/* Handling arguments from user */
args = process.argv.slice(2);
if (args.length != 3) {
console.log(
` Usage: node AdobeConnectRecorder.js chromiumExecutableLocation AdobeConnectURL(in double quotations) timeInSeconds`
);
process.exit(1);
}
const chromeExecutablePath = args[0];
const url = args[1];
const timeInSeconds = args[2];
videoRecorder(chromeExecutablePath, url, timeInSeconds);
/* The Actual function */
async function videoRecorder(chromeExecutablePath, url) {
const { launch, getStream } = require("puppeteer-stream");
const fs = require("fs");
const filename = `./recordings/${Date.now()}.webm`;
const file = fs.createWriteStream(filename);
const browser = await launch({
executablePath: chromeExecutablePath,
defaultViewport: null,
devtools: false,
args: [
"--window-size=1920,1080",
"--window-position=1921,0",
"--autoplay-policy=no-user-gesture-required",
],
});
const page = await browser.newPage();
try {
await page.goto(url, {
waitUntil: "domcontentloaded",
});
} catch (error) {}
const openButton = await page.$x("//a[contains(text(), 'Open in browser')]");
await openButton[0].click();
let frame,
frames = [];
console.log(page.frames());
while (1) {
while (frames.length != 2) {
await page.waitForTimeout(2000);
frames = page.frames();
frame = frames.find((f) => f.url().includes("index.html"));
}
try {
await frame.waitForFunction(
'document.querySelector("body").innerHTML.includes("Play Recording")'
);
break;
} catch (error) {
console.log("Not found, trying again");
continue;
}
}
console.log("Found Play Button");
await frame.$x("//span[contains(text(), 'Play Recording')]");
const playButton = await frame.$x(
"//span[contains(text(), 'Play Recording')]"
);
await playButton[0].click();
const stream = await getStream(page, {
audio: true,
audioBitsPerSecond: 128,
video: true,
});
stream.pipe(file);
setTimeout(async () => {
await stream.destroy();
file.close();
console.log("finished");
}, (parseInt(timeInSeconds) + 10) * 1000);
}
@RyanNorooz
Copy link

noice...👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment