Reputation: 137
I want to record a Google meeting using selenium python
and upload it to the server.
After some googling, I understand that I need to create a bot, that will join the meeting. After joining the meeting, it will record the meeting (both audio and video) and upload it to the server.
So far, I created a bot that can join the meeting, but I'm unable to record the meeting. I tried sharing the browser tab. After the bot joins the meeting, it opens the tab-sharing option, but it is unable to share the tab.
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.keys import Keys
recording_script = """
var blob, mediaRecorder = null;
var chunks = [];
async function startRecording(){
let video = await navigator.mediaDevices.getDisplayMedia({video: {mediaSource: "screen"}, audio: true});
let audio = await navigator.mediaDevices.getUserMedia({audio: true, video: false })
// Assign the recorded mediastream to the src object
// video.srcObject = e;
// Combine both video/audio stream with MediaStream object
let combine = new MediaStream([...video.getTracks(), ...audio.getTracks()])
mediaRecorder = new MediaRecorder(combine, {mimeType: "video/webm"});
mediaRecorder.ondataavailable = (e) => {
if(e.data.size > 0){
chunks.push(e.data);
}
};
mediaRecorder.onstop = () => {
var filename = window.prompt("File name", "video"); // Ask the file name
blob = new Blob(chunks, {type: "video/webm"});
chunks = []; // Resetting the data chunks
var dataDownloadUrl = URL.createObjectURL(blob);
// Download it onto the user's device
let a = document.createElement('a');
a.href = dataDownloadUrl;
a.download = `${filename}.webm`;
a.click();
URL.revokeObjectURL(dataDownloadUrl);
};
mediaRecorder.start(250);
}"""
opt = uc.ChromeOptions()
opt.add_argument('--disable-blink-features=AutomationControlled')
opt.add_argument('--start-maximized')
# opt.add_argument('--headless=new')
# opt.add_argument('--no-sandbox')
opt.add_argument('--disable-gpu')
# opt.add_argument('user-agent="MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"')
opt.add_experimental_option("prefs", {
"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 1,
"profile.default_content_setting_values.geolocation": 0,
"profile.default_content_setting_values.notifications": 1
})
driver = uc.Chrome(options=opt)
driver.get("meeting_url")
driver.implicitly_wait(15)
# turning off camera
# driver.find_element(By.XPATH,"/html/body/div/c-wiz/div/div/div[27]/div[3]/div/div[2]/div[4]/div[1]/div/div[1]/div[1]/div/div[4]/div[2]/div").click()
# turning off mic
# driver.find_element(By.XPATH,"/html/body/div/c-wiz/div/div/div[27]/div[3]/div/div[2]/div[4]/div/div/div[1]/div[1]/div/div[6]/div[1]/div/div").click()
# input bot name
driver.find_element(By.XPATH,"/html/body/div/c-wiz/div/div/div[27]/div[3]/div/div[2]/div[4]/div/div/div[2]/div[1]/div[1]/div[3]/label/input").send_keys("test_bot")
# join request
driver.find_element(By.XPATH,"/html/body/div/c-wiz/div/div/div[27]/div[3]/div/div[2]/div[4]/div/div/div[2]/div[1]/div[2]/div[1]/div[1]/button").click()
time.sleep(5)
driver.execute_script(recording_script)
Can anyone tell me how my bot will record the meeting? Any kind of help will be appreciated.
Upvotes: 1
Views: 271