pages/projects/googlemeetbot.html

88 lines
7.7 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/styles.css">
<link rel="icon" type="image/png" href="/favicon.png">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Google Meet Bot attends online lessons for me</title>
</head>
<body>
<header><center>
<a href="/index.html">Home</a>
|
<a href="/projects/index.html">Projects</a>
|
<a href="/notes/index.html">Notes</a>
|
<a href="https://git.emamaker.com/EmaMaker">Gitea</a>
|
<a href="https://github.com/EmaMaker">Github</a>
|
<a href="https://instagram.com/EmaMaker">Instagram</a>
</center>
</header>
<article>
<h2 id="before-reading">Before Reading</h2>
<p>As always, the source code for this Google Meet Bot is available on my <a href="https://github.com/EmaMaker/GoogleMeetBot">github</a> profile. You can even download it and set it up for your own use following the instructions! If you want to see the bot in action take a look here</p>
<h1 id="video-demo-youtubeinvidious">Video Demo <a href="https://www.youtube.com/watch?v=ZaBPLZkqqas">(YouTube)</a><a href="https://invidious.snopyta.org/watch?v=ZaBPLZkqqas">(Invidious)</a></h1>
<h2 id="the-problem">The Problem</h2>
<p>Ill be honest, Ive never been the kind of person that wakes up early in the morning and its super energetic right off the bat. Even if i wake up at 7am, getting out of the bed takes me ages. Now, since the COVID-19 outbreak in my country, schools have moved to online lessons countrywide. Even if by now we go physically to school for 75% of the week, we still have to attend online classes for the other 25%. This whole time, knowing I had to stay at home to follow my lessons made waking up early even harder for me. And apparently keeping note of who arrives to a lesson late is apparently a huge problem, which neither me nor my teachers want to deal with. </p>
<h2 id="what-do-do">What do do?</h2>
<p>I had to do something for this situation, and getting up in time was simply not an option. I needed something that could join lessons on time for me, which allowed me to sleep more. So i needed something to automate my computer, but how? I could write some program that simulated the mouse moving and clicking, but I had to do it in the past and I knew it was terrible idea, so I ditched it. Yet, i needed something to simulate a person using the browser.</p>
<h2 id="looking-at-old-projects">Looking at old projects</h2>
<p>as I said, using some kind of program to virtually move the mouse and click stuff was totally not a good idea. At least not writing my own. Then i remembered that some time ago I worked on an <a href="https://github.com/EmaMaker/AccountChecker">Account Checker script</a> for a friend. It was basically a program which, given a list of usernames and passwords, would try to login into websites. This was a nice and quick project that you can find here. I might do a post on it some day.</p>
<p>The Account Checker was based on the <a href="https://github.com/nsgodshall/Hatch">nsgodshalls fork</a> of <a href="https://github.com/zshell/Hatch">zshells Hatch</a>, it was written in Python and used a module called <a href="https://www.selenium.dev/">Selenium</a>, which was exactly what i needed.</p>
<h2 id="selenium">Selenium</h2>
<p>Its a simple yet extremely powerful website automation tool. Selenium can open an automated Firefox window, and it can simulate the click of buttons or typing of keys like if a person was using it.
To do this, the browser has to be ready for automation. For Chrome, this means installing the chromedriver and giving the right path to it to the script. For Firefox, it means doing the same thing with the geckodriver.
I decided to settle with Firefox because Chrome was giving me some strange problems with login in the early tests. While I was thinking of this, and had already made a somewhat working example, a classmate of mine, to which I had spoken about this project before, sent me <a href="https://www.youtube.com/watch?v=7neSueHsyY0">this video by TechRaj</a>. TechRaj made a bot to automatically join Microsoft Teams meetings, the same concept could be applied to Google Meet, but it had some serious problems to be solved.</p>
<h2 id="the-bot">The Bot</h2>
<p>The most important problem in this case, is that Google, unlike Microsoft, doesnt allow google accounts to be joined from automated browser sessions. Second problem, is that, unlike TechRaj does, CSS Selectors cannot be used to select the components, since the selector of a component changes on a per-meeting basis on GMeets. This second problem is quite easy to resolve by using XPATHs instead of CSS Selectors. An XPATH just a string that describes the position of a component in an HTML structure. XPATH are static, unless someone changes the HTML structure of the page, which shouldnt happen really often on a service like GMeet.</p>
<p>The account problem is a little trickier to workaround, but I managed to find a way. FireFox has profiles, which retains information about the browsing history, cookies and, most importantly, accounts that are logged in. So we could create a new FireFox profile, manually login into the needed Google Account via GMail and let the profile store the account. Since this step has been done manually, without an automated browser, Google will let it login into the google account with no problems.</p>
<p>Then, using Selenium, we can open a new FireFox window that uses the profile we just created, and it will be automatically logged in into Google, struggle free.</p>
<p>from this point on is just a matter of using <strong>WebDriver.get</strong>, <strong>WebDriver.click</strong> and <strong>WebDriver.send_keys</strong> to click redirect the browser to the given Meet link, click the buttons to mute camera and microphone, join the call and eventually type something in the chat. At this point theres only a scheduling system missing.Scheduling</p>
<p>It wouldnt be a real bot if it wasnt able to automatically join classes at the right time, every day. Searching around i found the <strong>schedule</strong> module for python. Basically, as long as script runs, it will execute the given action at the right time of the right day. I did another bit of manual work and programmed the bot with my current lessons schedule.</p>
<p>Of course, a teacher could be late, so the bot is programmed to retry joining a meeting every minute if a failure of any type should occur.</p>
<p>Running in the background is the only thing left: my computer runs ArchLinux with KDE Plasma as Desktop Environment. KDE Plasma allows the user to create multiple Activities, which are basically virtual desktop isolated from each other. I created an activity for my school stuff, and let the bot run there.</p>
<h2 id="conclusion-and-final-considerations">Conclusion and Final Considerations</h2>
<p>The bot is lightweight and easy to set up and use. Ive been running this Google Meet bot for the past couples of months and hasnt failed on me since, and I still havent got busted by my teachers.</p>
<h1 id="video-demo-youtubeinvidious-1">Video Demo <a href="https://www.youtube.com/watch?v=ZaBPLZkqqas">(YouTube)</a><a href="https://invidious.snopyta.org/watch?v=ZaBPLZkqqas">(Invidious)</a></h1>
</article>
<footer><p>
Author: EmaMaker
<a href="mailto:emamaker@tutanota.com">emamaker@tutanota.com</a>
<br>
This website is statically generated from markdown using <a href="https://git.alemauri.eu/alema/rivet">rivet</a>,
a static website generator written in POSIX compliant sh by my dear friend <a href="https://alemauri.eu">Alessandro Mauri. Check him out!</a>
<br>
This website is hosted on Codeberg Pages. <a href="https://codeberg.org/EmaMaker/pages>Feel free to check out the sources</a>
</p>
</footer>
</body>
</html>