57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
COOKIE_FILE = Path("sktorrent_cookies.json")
|
|
LOGIN_URL = "https://sktorrent.eu/torrent/torrents_v2.php?active=0"
|
|
|
|
|
|
def save_login_cookies(context):
|
|
"""Save only uid + pass cookies."""
|
|
cookies = context.cookies()
|
|
login_cookies = [
|
|
c for c in cookies
|
|
if c["domain"] == "sktorrent.eu" and c["name"] in ("uid", "pass")
|
|
]
|
|
|
|
with open(COOKIE_FILE, "w") as f:
|
|
json.dump(login_cookies, f, indent=2)
|
|
|
|
print("✅ Login cookies saved to", COOKIE_FILE)
|
|
|
|
|
|
def load_cookies(context):
|
|
"""Load saved cookies if available."""
|
|
if COOKIE_FILE.exists():
|
|
with open(COOKIE_FILE, "r") as f:
|
|
cookies = json.load(f)
|
|
context.add_cookies(cookies)
|
|
print("🔄 Loaded saved cookies.")
|
|
return True
|
|
return False
|
|
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=False)
|
|
context = browser.new_context()
|
|
cookies_loaded = load_cookies(context)
|
|
|
|
page = context.new_page()
|
|
page.goto(LOGIN_URL)
|
|
|
|
# Check if we are already logged in
|
|
if page.locator('input[name="uid"]').count() == 0:
|
|
print("✅ Already logged in using cookies!")
|
|
else:
|
|
print("\n➡️ Please log in manually in the opened browser.")
|
|
print("➡️ Once logged in and you see your account page, press ENTER here.\n")
|
|
input("Press ENTER when finished... ")
|
|
|
|
save_login_cookies(context)
|
|
|
|
print("🎉 Done!")
|
|
page.wait_for_timeout(3000)
|