import sqlite3
import os
import time

# Remplace ce chemin par le chemin réel de ton profil Firefox
profile_path = r"/root/.mozilla/firefox/8kpkeewl.youtube"
cookies_db = os.path.join(profile_path, "cookies.sqlite")

if not os.path.exists(cookies_db):
    raise Exception(f"Le fichier cookies.sqlite n'existe pas à ce chemin : {cookies_db}")

# Connexion à la base SQLite
conn = sqlite3.connect(cookies_db)
cursor = conn.cursor()

# Requête pour récupérer tous les cookies
cursor.execute("SELECT host, path, isSecure, expiry, name, value FROM moz_cookies")

with open("cookies.txt", "w", encoding="utf-8", newline="\n") as f:
    f.write("# Netscape HTTP Cookie File\n")
    f.write("# Exported manually from Firefox profile DB\n\n")

    for row in cursor.fetchall():
        domain, path, is_secure, expiry, name, value = row
        include_subdomain = "TRUE" if domain.startswith(".") else "FALSE"
        secure = "TRUE" if is_secure else "FALSE"
        expires = str(int(expiry))
        f.write("\t".join([domain, include_subdomain, path, secure, expires, name, value]) + "\n")

conn.close()
