-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from OpenMined/madhava/netflix_data_fetcher
Added netflix data fetcher
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
inputs/* | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |