Skip to content

Commit

Permalink
Improve web
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudotensor committed Oct 29, 2024
1 parent bcf68d8 commit f1ad18c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions openai_server/agent_tools/download_web_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def selenium(base_url, video_url):
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
# options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")

driver = webdriver.Chrome(options=options)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

google_username = os.getenv('GOOGLE_USERNAME')
google_password = os.getenv('GOOGLE_PASSWORD')
Expand All @@ -30,13 +34,13 @@ def selenium(base_url, video_url):
email_field = driver.find_element(By.ID, "identifierId")
email_field.send_keys(google_username)
email_field.send_keys(Keys.RETURN)
time.sleep(2)
time.sleep(random.uniform(2, 5))

# Enter password
password_field = driver.find_element(By.CSS_SELECTOR, "input[type='password']")
password_field.send_keys(google_password)
password_field.send_keys(Keys.RETURN)
time.sleep(2)
time.sleep(random.uniform(2, 5))

# Visit site
driver.get(base_url)
Expand All @@ -47,15 +51,15 @@ def selenium(base_url, video_url):
search_bar.send_keys(Keys.RETURN)

# Wait for the page to load
time.sleep(3)
time.sleep(random.uniform(3, 6))

# Click on the first video result
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/3);")
first_video = driver.find_element(By.CSS_SELECTOR, "a#video-title")
first_video.click()

# Let the video play for a few seconds (mimic human behavior)
tsleep = random.randint(5, 15)
time.sleep(tsleep)
time.sleep(random.randint(5, 15))

# Get video URL
video_url_new = driver.current_url
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "c59ca3591240dcbaf9ee378d72fc2c7420f719a4"
__version__ = "bcf68d855511f1a081d3e2d06fbecf157e111e87"

0 comments on commit f1ad18c

Please sign in to comment.