diff --git a/.gitignore b/.gitignore index a979f16..c659f30 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,6 @@ target/ # appp specific folders bin/ default_out_path/ + +# +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 6b830d3..ced70a3 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,18 @@ Note: sometime it works better than phantomjs in some system --chrome ``` +### Use headless mode in echo360.org + +Simply by supplying a username and password, your chromedriver session will be headless. +This means there will be no log in window and you can run this on a server for example. + +```shell +>>> ./run.sh \ + https://echo360.org.uk/section/534de63e-ecab-1a93-1ea8-e8225825dce/home \ + -u username@university.edu + -p password +``` + # FAQ ### Is my university supported? diff --git a/echo360/downloader.py b/echo360/downloader.py index 016857d..457ae00 100644 --- a/echo360/downloader.py +++ b/echo360/downloader.py @@ -72,7 +72,7 @@ def __init__(self, if webdriver_to_use == 'chrome': from selenium.webdriver.chrome.options import Options opts = Options() - if not setup_credential: + if self._username!=None and self._password!=None: opts.add_argument("--headless") opts.add_argument("--window-size=1920x1080") opts.add_argument("user-agent={}".format(self._useragent)) diff --git a/echo360/main.py b/echo360/main.py index c1dd23e..1273e43 100644 --- a/echo360/main.py +++ b/echo360/main.py @@ -254,7 +254,7 @@ def cmd_exists(x): binary_type, 'LOCAL' if use_local_binary else 'GLOBAL')) if setup_credential: - run_setup_credential(downloader._driver, course_hostname, echo360_cloud=True) + run_setup_credential(downloader._driver, course_hostname, username, password, echo360_cloud=True) downloader._driver.set_window_size(0, 0) downloader.download_all() @@ -268,7 +268,7 @@ def start_download_binary(binary_downloader, binary_type, manual=False): print('Done!') print('=' * 65) -def run_setup_credential(webdriver, url, echo360_cloud=False): +def run_setup_credential(webdriver, url, username, password, echo360_cloud=False): webdriver.get(url) try: # for making it compatiable with Python 2 & 3 @@ -277,9 +277,16 @@ def run_setup_credential(webdriver, url, echo360_cloud=False): pass try: if echo360_cloud: - print(" >> After you finished logging into echo360 cloud, the window " - "should be automatically redirected and continued. If it got stuck, " - "please contact the author :)") + if username==None and password==None: + print(" >> After you finished logging into echo360 cloud, the window " + "should be automatically redirected and continued. If it got stuck, " + "please contact the author :)") + else: + webdriver.find_element_by_xpath('//*[@id="email"]').send_keys(username) + webdriver.find_element_by_xpath('//*[@id="submitBtn"]').click() + + webdriver.find_element_by_xpath('//*[@id="password"]').send_keys(password) + webdriver.find_element_by_xpath('//*[@id="submitBtn"]').click() while True: if echo360_cloud: # automatically wait for the Auth Token from webdriver