Neurolingua commited on
Commit
2f02b6a
1 Parent(s): b55829b

Update student_functions.py

Browse files
Files changed (1) hide show
  1. student_functions.py +20 -19
student_functions.py CHANGED
@@ -13,7 +13,14 @@ from urllib.parse import urlparse, parse_qs
13
  from pypdf import PdfReader
14
  from ai71 import AI71
15
  import os
16
-
 
 
 
 
 
 
 
17
  AI71_API_KEY = "api71-api-652e5c6c-8edf-41d0-9c34-28522b07bef9"
18
 
19
 
@@ -197,27 +204,21 @@ def spk_msg(user_input, memory):
197
 
198
 
199
  def get_first_youtube_video_link(query):
200
- chrome_options = webdriver.ChromeOptions()
201
- chrome_options.add_argument("--headless")
202
- chrome_options.add_argument("--disable-gpu")
203
- chrome_options.add_argument("--disable-extensions")
204
- chrome_options.add_argument("--no-sandbox")
205
- chrome_options.add_argument("--disable-dev-shm-usage")
206
- driver = webdriver.Chrome(options=chrome_options)
207
  try:
208
- driver.get('https://www.youtube.com')
209
- search_box = driver.find_element(By.NAME, 'search_query')
210
- search_box.send_keys(query)
211
- search_box.send_keys(Keys.RETURN)
212
- WebDriverWait(driver, 10).until(
213
- EC.presence_of_element_located((By.CSS_SELECTOR, 'a#video-title')))
214
- first_video = driver.find_element(By.CSS_SELECTOR, 'a#video-title')
215
- first_video_link = first_video.get_attribute('href')
216
- video_title = first_video.get_attribute('title')
217
- return first_video_link, video_title
218
  finally:
 
219
  driver.quit()
220
- return
221
 
222
 
223
  def content_translate(text):
 
13
  from pypdf import PdfReader
14
  from ai71 import AI71
15
  import os
16
+ chrome_options = webdriver.ChromeOptions()
17
+ chrome_options.add_argument("--headless")
18
+ chrome_options.add_argument("--disable-gpu")
19
+ chrome_options.add_argument("--disable-extensions")
20
+ chrome_options.add_argument("--no-sandbox")
21
+ chrome_options.add_argument("--disable-dev-shm-usage")
22
+
23
+ driver = webdriver.Chrome(options=chrome_options)
24
  AI71_API_KEY = "api71-api-652e5c6c-8edf-41d0-9c34-28522b07bef9"
25
 
26
 
 
204
 
205
 
206
  def get_first_youtube_video_link(query):
207
+ url = f'https://www.youtube.com/results?search_query={query}'
208
+
209
+ # Navigate to the URL
210
+ driver.get(url)
211
+
212
+ # Find the first video link
 
213
  try:
214
+ # Find the first video element
215
+ first_video_element = driver.find_element(By.XPATH, '//a[@id="video-title"]')
216
+ video_link = first_video_element.get_attribute('href')
217
+ print(video_link)
 
 
 
 
 
 
218
  finally:
219
+ # Close the WebDriver
220
  driver.quit()
221
+
222
 
223
 
224
  def content_translate(text):