watch_live.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from setup import *
  2. programname = 'WATCHLIVE'
  3. userdatadir, userlist, config, minimize, approval = setup(programname)
  4. def execute():
  5. try:
  6. liveurl = config[programname]['liveurl']
  7. watchtime = int(config[programname]['watchtime'])
  8. print("Live URL is "+ liveurl)
  9. print("Watching video for "+ str(watchtime) + " seconds")
  10. except:
  11. print("Invalid settings. Please check settings and try again.")
  12. tsleep(5)
  13. return 0
  14. if 'facebook.com' in liveurl:
  15. tsleep(5)
  16. driver, selecteduser=restart_browser(userdatadir, userlist)
  17. # ANY RETURN 0 AFTER THIS POINT WILL REQUIRE DRIVER.QUIT TO BE CALLED FIRST BEFORE PROCEEDING, TO PREVENT POSSIBLE MEMORY LEAK
  18. if minimize == 1:
  19. driver.minimize_window()
  20. print(selecteduser)
  21. try:
  22. driver.get(liveurl)
  23. except:
  24. #traceback.print_exc()
  25. print("Can't get URL or invalid URL. Please check the URL and try again.")
  26. tsleep(5)
  27. driver.quit()
  28. return 0
  29. # CHECK IF YOU ARE LOGGED IN
  30. if "login" in driver.current_url:
  31. print("Not logged in. Please make sure you are logged in.")
  32. tsleep(5)
  33. driver.quit()
  34. return 0
  35. # YOU HAVE LOGGED IN AT THIS POINT -- MAIN PROGRAM EXECUTION STARTS HERE
  36. elmt = driver.find_element(By.XPATH, "//*[contains(@class,'xl56j7k x5yr21d x78zum5 x6s0dn4')]")
  37. tsleep(5)
  38. if elmt:
  39. try:
  40. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  41. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  42. print("Watching live video")
  43. tsleep(watchtime)
  44. print("Completed")
  45. except KeyboardInterrupt:
  46. print("Interrupted")
  47. except:
  48. print("Video error. Please try another video.")
  49. print("Program has completed execution")
  50. else:
  51. print("Can't get URL or invalid URL. Please check the URL and try again.")
  52. tsleep(5)
  53. driver.quit()
  54. if approval == 1:
  55. execute()