import os import sys from selenium import webdriver from selenium.webdriver.chrome.options import Options def main(): extension_path = os.path.abspath("scratch/internet_archive_downloader/isrc") if not os.path.isdir(extension_path): print(f"Error: Extension path {extension_path} does not exist.") sys.exit(1) print("Setting up Chrome Options...") options = Options() # We must run in headful mode so the user can interact and log in options.add_argument(f"--load-extension={extension_path}") options.add_argument("--window-size=1200,900") # Configure download preferences to save directly to the scratch folder download_dir = os.path.abspath("scratch") prefs = { "download.default_directory": download_dir, "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True } options.add_experimental_option("prefs", prefs) print("Launching Chrome...") driver = webdriver.Chrome(options=options) try: url = "https://archive.org/details/numerologydivine00fait" print(f"Navigating to {url}...") driver.get(url) print("\n" + "="*75) print("INSTRUCTIONS:") print("1. Log in to your Internet Archive account in the opened Chrome window.") print("2. Click 'Borrow for 1 hour' to borrow the book.") print("3. Under the book reader, click the new 'Download' button added by the extension.") print("4. Save the PDF when prompted by the browser.") print("5. Once the download is complete, return to this terminal and press Enter to exit.") print("="*75 + "\n") input("Press Enter here when the download has completed to close the browser...") except Exception as e: print("An error occurred during execution:", e) finally: print("Closing browser...") driver.quit() if __name__ == "__main__": main()