diff --git a/fetchers/netflix/.gitignore b/fetchers/netflix/.gitignore new file mode 100644 index 00000000..04bd1fda --- /dev/null +++ b/fetchers/netflix/.gitignore @@ -0,0 +1,2 @@ +inputs/* +output \ No newline at end of file diff --git a/fetchers/netflix/README.md b/fetchers/netflix/README.md new file mode 100644 index 00000000..9687c67c --- /dev/null +++ b/fetchers/netflix/README.md @@ -0,0 +1,22 @@ +# Netflix Fetcher + +This will run periodically and download your netflix data so you can keep your stats up to date. + +## Instructions + +Add email, password and profile to text files in ./inputs + +``` +├── inputs +│   ├── NETFLIX_EMAIL.txt +│   ├── NETFLIX_PASSWORD.txt +│   └── NETFLIX_PROFILE.txt +``` + +## Profile ID + +To get your profile ID go to the Profile Gate: +https://www.netflix.com/ProfilesGate + +Right click and copy the url for your profile and get the part after: +https://www.netflix.com/SwitchProfile?tkn= diff --git a/fetchers/netflix/main.py b/fetchers/netflix/main.py new file mode 100644 index 00000000..4e8c892e --- /dev/null +++ b/fetchers/netflix/main.py @@ -0,0 +1,70 @@ +import os +import time + +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +chrome_driver_path = os.environ["CHROMEDRIVER_PATH"] +email = os.environ["NETFLIX_EMAIL"] +password = os.environ["NETFLIX_PASSWORD"] +profile = os.environ["NETFLIX_PROFILE"] +output_dir = os.environ["OUTPUT_DIR"] + +print(f"🍿 Downloading Netflix Activity for: {email} Profile {profile}") + +# Set up WebDriver (for Chrome) +chrome_options = Options() +prefs = { + "download.default_directory": output_dir, + "download.prompt_for_download": False, +} +chrome_options.add_experimental_option("prefs", prefs) +chrome_options.add_argument( + "--headless" +) # Run in headless mode, comment this if you want to see the browser window +chrome_service = Service(chrome_driver_path) # Set the path to your ChromeDriver + +driver = webdriver.Chrome(service=chrome_service, options=chrome_options) + +# get login page +driver.get("https://www.netflix.com/login") + + +# Find the email and password input fields +email_input = driver.find_element(By.NAME, "userLoginId") +password_input = driver.find_element(By.NAME, "password") +# Enter email and password +email_input.send_keys(email) +password_input.send_keys(password) + +# Submit the login form +print("Logging In") +password_input.send_keys(Keys.ENTER) + +# Wait for the login to complete +time.sleep(3) + +print("Switching Profiles") +# Navigate to Viewing Activity page +driver.get(f"https://www.netflix.com/SwitchProfile?tkn={profile}") + +# Wait for the login to complete +time.sleep(3) + +print("Getting Viewing Activity") +# Navigate to Viewing Activity page +driver.get("https://www.netflix.com/viewingactivity") + +time.sleep(3) + +print("Clicking Download all") +# Navigate to a page and download a file +element = driver.find_element(By.LINK_TEXT, "Download all").click() + +print("Sleeping just in case") +time.sleep(10) + +driver.quit() diff --git a/fetchers/netflix/requirements.txt b/fetchers/netflix/requirements.txt new file mode 100644 index 00000000..7cb6656b --- /dev/null +++ b/fetchers/netflix/requirements.txt @@ -0,0 +1 @@ +selenium diff --git a/fetchers/netflix/run.sh b/fetchers/netflix/run.sh new file mode 100755 index 00000000..466a1510 --- /dev/null +++ b/fetchers/netflix/run.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Check if chromedriver is in the PATH +if ! command -v chromedriver &> /dev/null +then + echo "chromedriver is not installed. Installing with brew..." + brew install chromedriver +else + echo "chromedriver is already installed." +fi + +export CHROMEDRIVER_PATH=$(which chromedriver) +echo $CHROMEDRIVER_PATH + +mkdir -p inputs +mkdir -p output + +export NETFLIX_EMAIL=$(cat inputs/NETFLIX_EMAIL.txt) +export NETFLIX_PASSWORD=$(cat inputs/NETFLIX_PASSWORD.txt) +export NETFLIX_PROFILE=$(cat inputs/NETFLIX_PROFILE.txt) +export OUTPUT_DIR=$(realpath ./output) + +uv pip install -r requirements.txt +uv run main.py