-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteams_auto_join.py
More file actions
114 lines (107 loc) · 5.49 KB
/
Copy pathteams_auto_join.py
File metadata and controls
114 lines (107 loc) · 5.49 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import sys
import asyncio
from playwright.async_api import async_playwright
from audio_record import record_vbcable_audio
TEAMS_MEETING_URL = "https://teams.microsoft.com/l/meetup-join/" # Replace with your actual Teams meeting link
async def join_teams(meeting_url):
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False, args=[
'--use-fake-ui-for-media-stream',
'--disable-infobars',
'--disable-extensions',
'--disable-notifications',
'--no-sandbox',
])
context = await browser.new_context()
page = await context.new_page()
try:
await page.goto(meeting_url)
# 1. Wait for and click 'Continue on this browser' as soon as it is interactable (try <a> and <button>, force click)
selectors = [
'a:has-text("Continue on this browser")',
'button:has-text("Continue on this browser")'
]
clicked = False
for continue_selector in selectors:
try:
continue_button = await page.wait_for_selector(continue_selector, timeout=10000)
if continue_button:
await continue_button.click(force=True)
print(f"Clicked '{continue_selector}' as soon as it appeared and was interactable.")
clicked = True
break
except Exception as e:
print(f"Error or timeout while handling '{continue_selector}': {e}. Trying next selector.")
if not clicked:
print("[ERROR] 'Continue on this browser' button not found or not clickable after waiting. Taking screenshot for debugging.")
try:
await page.screenshot(path="continue_on_this_browser_debug.png")
print("Screenshot saved as 'continue_on_this_browser_debug.png'")
except Exception as e:
print(f"Failed to take screenshot: {e}")
# 2. Aggressively and repeatedly check for 'Continue without audio or video' button and click ASAP
continue_wo_av_selector = 'button.fui-Button.r1alrhcs:has-text("Continue without audio or video")'
import time as _time
max_wait_wo_av = 20 # seconds
start_time_wo_av = _time.time()
while _time.time() - start_time_wo_av < max_wait_wo_av:
try:
btn = await page.query_selector(continue_wo_av_selector)
if btn:
await btn.click(force=True)
print("Clicked 'Continue without audio or video' button immediately when it appeared.")
# Wait a short moment to see if it disappears
await asyncio.sleep(0.2)
# If it is still present, try again
btn = await page.query_selector(continue_wo_av_selector)
if not btn:
break
else:
break
except Exception as e:
print(f"Error while trying to click 'Continue without audio or video': {e}")
break
await asyncio.sleep(0.1)
# 3. Aggressively wait for the name input field, fill with 'Muhammad', then click 'Join now' ASAP
try:
name_input = await page.wait_for_selector('input[type="text"][aria-label][name]', timeout=20000)
if name_input:
await name_input.fill("Muhammad")
print("Filled name input with 'Muhammad'.")
# Immediately click 'Join now' after filling name
try:
join_button = await page.wait_for_selector('button:has-text("Join now")', timeout=10000)
if join_button:
await join_button.click()
print("Clicked 'Join now' button.")
else:
print("'Join now' button not found after waiting. Skipping this step.")
except Exception as e:
print(f"Error while handling 'Join now' button: {e}")
else:
print("Name input field not found after waiting. Skipping this step.")
except Exception as e:
print(f"Error while handling name input field: {e}")
print("Joined the Teams meeting. Staying connected...")
# Record and transcribe 5 seconds of audio
audio = record_vbcable_audio()
from audio_transcribe import transcribe_audio_numpy
text = transcribe_audio_numpy(audio)
print("Transcription (first 5 seconds):", text)
from audio_transcribe import append_transcript
append_transcript(text)
while True:
await asyncio.sleep(3600) # Stay connected indefinitely
except Exception as e:
import traceback
print("[ERROR] An exception occurred in join_teams:", e)
traceback.print_exc()
print("[DEBUG] Browser will remain open for manual inspection.")
while True:
await asyncio.sleep(3600)
if __name__ == "__main__":
if len(sys.argv) > 1:
meeting_url = sys.argv[1]
else:
meeting_url = TEAMS_MEETING_URL
asyncio.run(join_teams(meeting_url))