Skip to content

Commit

Permalink
Merge pull request #50 from OpenMined/madhava/netflix_data_fetcher
Browse files Browse the repository at this point in the history
Added netflix data fetcher
  • Loading branch information
madhavajay authored Oct 10, 2024
2 parents 42f5618 + 21a7d12 commit 8f3c85b
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fetchers/netflix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inputs/*
output
22 changes: 22 additions & 0 deletions fetchers/netflix/README.md
Original file line number Diff line number Diff line change
@@ -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=
70 changes: 70 additions & 0 deletions fetchers/netflix/main.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions fetchers/netflix/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
selenium
24 changes: 24 additions & 0 deletions fetchers/netflix/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f3c85b

Please sign in to comment.