import json
import os
import random
import shutil
if os.name == "posix":
folder_path = "cookies"
else:
while True:
import tkinter
from tkinter import filedialog
print("\n<<< Select Netscape cookies folder >>>\n\n")
tkinter.Tk().withdraw()
folder_path = filedialog.askdirectory()
if folder_path == "":
print("Trying to use default folder 'cookies'\n")
folder_path = "cookies"
break
else:
break
rand_number = random.randint(1, 99999)
def convert_netscape_cookie_to_json(cookie_file_content):
cookies = []
for line in cookie_file_content.splitlines():
fields = line.strip().split("\t")
if len(fields) >= 7:
cookie = {
"domain": fields[0].replace("www", ""),
"flag": fields[1],
"path": fields[2],
"secure": fields[3] == "TRUE",
"expiration": fields[4],
"name": fields[5],
"value": fields[6],
}
cookies.append(cookie)
json_content = json.dumps(cookies, indent=4)
return json_content
path = "json_cookies"
try:
os.mkdir(path)
print(f"Folder {path} created!\n")
try:
for filename in os.listdir(folder_path):
filepath = os.path.join(folder_path, filename)
if os.path.isfile(filepath):
with open(filepath, "r", encoding="utf-8") as file:
content = file.read()
json_data = convert_netscape_cookie_to_json(content)
with open(f"json_cookies/{filename}", "w", encoding="utf-8") as f:
f.write(json_data)
print(f"{filename} - DONE!")
except FileNotFoundError:
print(
"Error Occurred :Default 'cookies' folder not found, please select a valid folder"
)
os.rmdir(path)
except FileExistsError:
if (
input(
"Do you want to remove old cookies folder? (y/n)\n [y] Recommended \n > : "
)
== "y"
):
shutil.rmtree(path)
os.mkdir(path)
for filename in os.listdir(folder_path):
filepath = os.path.join(folder_path, filename)
if os.path.isfile(filepath):
with open(filepath, "r", encoding="utf-8") as file:
content = file.read()
json_data = convert_netscape_cookie_to_json(content)
with open(f"json_cookies/{filename}", "w", encoding="utf-8") as f:
f.write(json_data)
print(f"{filename} - DONE!")
else:
os.mkdir(str(f"temp {rand_number}"))
for filename in os.listdir(folder_path):
filepath = os.path.join(folder_path, filename)
if os.path.isfile(filepath):
with open(filepath, "r") as file:
content = file.read()
json_data = convert_netscape_cookie_to_json(content)
with open(f"temp {rand_number}/{filename}", "w", encoding="utf-8") as f:
f.write(json_data)
print(f"{filename} - DONE!")
print(f"\n\nsaved cookies to the temp folder - temp {rand_number}")
# main.py start here
import json
import os
import sys
import config
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
working_cookies_path = "working_cookies"
if os.name == "posix":
folder_path = "json_cookies"
if not os.path.isdir(folder_path):
print(
"Error Occurred :Default 'json_cookies' folder not found, please run cookie_converter.py first"
)
sys.exit()
else:
import tkinter
from tkinter import filedialog
if config.use_folder_selector:
tkinter.Tk().withdraw()
folder_path = filedialog.askdirectory()
if folder_path == "":
folder_path = "json_cookies"
print("Using default path")
else:
print(f"Using path: {folder_path}")
def load_cookies_from_json(json_cookies_path):
with open(json_cookies_path, "r", encoding="utf-8") as cookie_file:
cookie = json.load(cookie_file)
return cookie
def open_webpage_with_cookies(link, json_cookies):
firefox_options = Options()
firefox_options.add_argument("--headless")
driver = webdriver.Firefox(options=firefox_options)
driver.get(link)
for cookie in json_cookies:
driver.add_cookie(cookie)
driver.refresh()
if driver.find_elements(By.CSS_SELECTOR, ".btn"):
print(f"Cookie Not working - {filename}")
driver.quit()
else:
print(f"Working cookie found! - {filename}")
try:
os.mkdir(working_cookies_path)
with open(f"working_cookies/{filename})", "w", encoding="utf-8") as a:
a.write(content)
driver.quit()
except FileExistsError:
with open(f"working_cookies/{filename}", "w", encoding="utf-8") as a:
a.write(content)
driver.quit()
for filename in os.listdir("json_cookies"):
filepath = os.path.join("json_cookies", filename)
if os.path.isfile(filepath):
with open(filepath, "r", encoding="utf-8") as file:
content = file.read()
url = "https://www.netflix.com/login"
try:
cookies = load_cookies_from_json(filepath)
open_webpage_with_cookies(url, cookies)
except json.decoder.JSONDecodeError:
print(
"Please use cookie_converter.py to convert your cookies to json format\n"
)
break
except Exception as e:
print(f"Error occurred: {str(e)} - {filename}\n")
Stay updated with our most recent articles and insights.
Just a few years ago, the idea of fully immersive virtual environments seemed like something out ...
In recent years, we’ve witnessed leaps in AI technology, with tools like ChatGPT simplifyin...
So, what exactly is Character AI, and why is everyone talking about it? In this article, we&rsquo...
If you're a gamer, content creator, or someone who relies on powerful graphics for work, you ...
Imagine teaching a child about the world using a mix of real-life experiences and highly detailed...
Have you noticed how fast technology is changing these days? It feels like every time you turn ar...
The world of business is changing at an astonishing pace, and one of the biggest drivers of this ...
Imagine a computer so powerful that it can solve problems in seconds that would take today’...
As we stand on the cusp of 2025, the Information Technology (IT) landscape is undergoing transfor...
Artificial Intelligence tools like GPT (Generative Pre-trained Transformers) have transformed the...
Join our community of informed individuals who benefit from curated content and stay ahead in the ever-evolving landscape. Subscribe now for a tailored experience.