From a764c9723ef5cb5a12d1882e9cea4ce29679aa94 Mon Sep 17 00:00:00 2001 From: Vladimir Buzalka Date: Tue, 18 Nov 2025 06:57:52 +0100 Subject: [PATCH] vbnotebook --- .idea/.gitignore | 3 + .idea/Torrents.iml | 10 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + 10 LoginOnce.py | 56 ++++++ 20 Loginwithsavedcookies.py | 36 ++++ 30 OpenTextListing.py | 171 ++++++++++++++++++ 8 files changed, 296 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Torrents.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 10 LoginOnce.py create mode 100644 20 Loginwithsavedcookies.py create mode 100644 30 OpenTextListing.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Torrents.iml b/.idea/Torrents.iml new file mode 100644 index 0000000..0745f13 --- /dev/null +++ b/.idea/Torrents.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..625e039 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/10 LoginOnce.py b/10 LoginOnce.py new file mode 100644 index 0000000..01b1dc4 --- /dev/null +++ b/10 LoginOnce.py @@ -0,0 +1,56 @@ +#!/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) diff --git a/20 Loginwithsavedcookies.py b/20 Loginwithsavedcookies.py new file mode 100644 index 0000000..db36db3 --- /dev/null +++ b/20 Loginwithsavedcookies.py @@ -0,0 +1,36 @@ +#!/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" + +with sync_playwright() as p: + browser = p.chromium.launch(headless=False) + context = browser.new_context() + + # Load saved cookies + if COOKIE_FILE.exists(): + with open(COOKIE_FILE, "r") as f: + cookies = json.load(f) + context.add_cookies(cookies) + print("šŸ”„ Loaded cookies.") + else: + print("āŒ Cookie file not found. Run the manual login script first.") + exit() + + page = context.new_page() + page.goto(LOGIN_URL) + + page.wait_for_load_state("networkidle") + + # Check if login form is visible + if page.locator('input[name="uid"]').count() == 0: + print("āœ… Already logged in using cookies!") + else: + print("āŒ Cookies invalid or expired. Please re-login manually to refresh cookies.") + + page.wait_for_timeout(3000) diff --git a/30 OpenTextListing.py b/30 OpenTextListing.py new file mode 100644 index 0000000..828a295 --- /dev/null +++ b/30 OpenTextListing.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import json +from pathlib import Path +from playwright.sync_api import sync_playwright + +# ============================================================= +# CONFIGURATION +# ============================================================= + +COOKIE_FILE = Path("sktorrent_cookies.json") +URL = "https://sktorrent.eu/torrent/torrents.php?active=0" + + +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 login cookies.") + return True + print("āŒ Cookie file not found. Run manual login first.") + return False + + +# ============================================================= +# MAIN CODE +# ============================================================= + +with sync_playwright() as p: + + # 1ļøāƒ£ Launch browser + browser = p.chromium.launch( + headless=False, + args=[ + "--disable-popup-blocking", + "--disable-background-networking", + "--disable-notifications", + "--no-default-browser-check", + "--no-first-run", + "--noerrdialogs", + "--disable-dev-shm-usage", + "--disable-features=IsolateOrigins,site-per-process", + "--no-sandbox", + ] + ) + + # 2ļøāƒ£ Create context before any pages exist + context = browser.new_context() + + # 3ļøāƒ£ Block ALL third-party requests (ads, JS, popups, tracking) + def block_third_party(route, request): + url = request.url.lower() + if "sktorrent.eu" in url: + route.continue_() + else: + print(f"🚫 Blocked third-party request: {url}") + route.abort() + + context.route("**/*", block_third_party) + + # 4ļøāƒ£ Block ANY popup windows except the first page + pages = [] + + def on_new_page(new_page): + pages.append(new_page) + if len(pages) == 1: + print("āž”ļø Main page created.") + else: + print("āš ļø Popup blocked (auto-closed).") + new_page.close() + + context.on("page", on_new_page) + + # 5ļøāƒ£ Disable all popup JS functions (window.open, window.close, opener.close) + context.add_init_script(""" + window.open = () => { console.log("Blocked window.open"); return null; }; + window.close = () => { console.log("Blocked window.close"); }; + + try { + if (window.opener) { + window.opener.close = () => { console.log("Blocked opener.close"); }; + } + } catch (e) {} + + // Block + document.addEventListener('click', function(e) { + const el = e.target.closest('a[target="_blank"]'); + if (el) { + e.preventDefault(); + console.log("Blocked target=_blank"); + } + }, true); + + // Block middle-click opening a new tab + document.addEventListener('auxclick', function(e) { + e.preventDefault(); + }, true); + """) + + # 6ļøāƒ£ Create the FIRST page (main page) + page = context.new_page() + pages.append(page) + + # 7ļøāƒ£ Load cookies (login) + load_cookies(context) + + # 8ļøāƒ£ Navigate + print("šŸŒ Opening page...") + page.goto(URL) + + # Do NOT use networkidle on ad-heavy sites + page.wait_for_load_state("domcontentloaded") + page.wait_for_selector("table tr", timeout=15000) + # Remove popup/overlay elements created by SKTorrent + page.evaluate(""" + const selectors = [ + '#lightbox', '.lightbox', '#popup', '.popup', + '.overlay', '#overlay', '.modal', '#modal', + 'div[style*="fixed"]', 'div[style*="position: fixed"]', + 'table[style*="position: fixed"]', + 'iframe', 'frame' + ]; + + selectors.forEach(sel => { + document.querySelectorAll(sel).forEach(el => { + console.log("Removing popup element:", sel); + el.remove(); + }); + }); + + // Remove onclick handlers that trigger popups + document.querySelectorAll('*').forEach(el => { + el.onclick = null; + el.onauxclick = null; + el.oncontextmenu = null; + }); + + // Remove timers that trigger delayed popups + window.setTimeout = () => {}; + window.setInterval = () => {}; + """) + + print("āœ” Page loaded, extracting table rows...") + + # 9ļøāƒ£ Extract all rows + rows = page.locator("table tr").all() + print(f"šŸ“„ Total rows found (including header): {len(rows)}") + + # šŸ”Ÿ Extract SECOND ROW only (your request) + if len(rows) > 1: + row = rows[1] # 0 = header, 1 = first data row + tds = row.locator("td") + + name = tds.nth(1).inner_text().strip() + size = tds.nth(2).inner_text().strip() + seeders = tds.nth(3).inner_text().strip() + leechers = tds.nth(4).inner_text().strip() + + print("\n========= SECOND ROW =========") + print(f"Name: {name}") + print(f"Size: {size}") + print(f"Seeders: {seeders}") + print(f"Leechers: {leechers}") + print("==============================\n") + else: + print("āŒ No data rows found!") + + page.wait_for_timeout(5000)