-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
134 lines (106 loc) · 4.19 KB
/
Copy pathmain.py
File metadata and controls
134 lines (106 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import sys
import time
import traceback
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from lib.kasada import BrowserSession
from lib.tempmail import TempMail
from lib.twitch import TwitchRegistrator, TwitchError, username_taken
from lib.utils import (
random_birthday,
random_password,
random_username,
)
RESULTS_DIR = Path(__file__).resolve().parent / "results"
ACCOUNTS_FILE = RESULTS_DIR / "accounts.txt"
def env(name, default=None):
val = os.environ.get(name)
return val if val not in (None, "") else default
def log(msg):
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
def ensure_results():
RESULTS_DIR.mkdir(parents=True, exist_ok=True)
ACCOUNTS_FILE.touch(exist_ok=True)
def save_account(line):
with open(ACCOUNTS_FILE, "a", encoding="utf-8") as f:
f.write(line + "\n")
def diagnostics(mail):
log("== Diagnostics ==")
try:
import requests
r = requests.get("https://passport.twitch.tv/", timeout=15)
log(f"Twitch passport reachable: HTTP {r.status_code}")
except Exception as e:
log(f"WARN: cannot reach Twitch passport: {e}")
email, _ = mail.create_address("diag" + str(int(time.time())))
log(f"Tempmail OK: {email}")
log("=================")
def pick_username(proxy=None):
for _ in range(8):
candidate = random_username()
if not username_taken(candidate, proxy=proxy):
return candidate
return random_username()
def register_one(browser, mail, proxy=None):
username = pick_username(proxy=proxy)
password = random_password()
birthday = random_birthday()
email, mail_token = mail.create_address(username)
log(f"Target: {username} / {email}")
reg = TwitchRegistrator(browser)
log("Step 1: protected_register (integrity + register via browser) ...")
res1 = reg.register(username, password, email, birthday)
if res1.get("success"):
log("Registered without verification step (unexpected but OK).")
return username, password, email, res1["access_token"], res1["user_id"]
if not res1.get("need_verification"):
raise RuntimeError(f"Unexpected register response: {res1}")
log("Verification email triggered. Waiting for code ...")
code = mail.wait_for_code(mail_token, timeout=220, interval=4)
if not code:
raise RuntimeError("No verification code received in time")
log(f"Verification code received: {code}")
log("Step 2: protected_register with verification code ...")
res2 = reg.register(username, password, email, birthday, email_verification_code=code)
if not res2.get("success"):
raise RuntimeError(f"Final register did not succeed: {res2}")
return username, password, email, res2["access_token"], res2["user_id"]
def main():
count = int(env("COUNT", "1"))
base_url = env("TEMPMAIL_BASE_URL", "https://mail.minecraft-cn.net")
domain = env("TEMPMAIL_DOMAIN", "olsbvgq.shop")
proxy = env("PROXY")
headless = env("HEADLESS", "1") != "0"
ensure_results()
mail = TempMail(base_url=base_url, domain=domain)
diagnostics(mail)
log(f"Starting browser session (headless={headless}) ...")
browser = BrowserSession(headless=headless, proxy=proxy)
browser.start()
log("Browser ready. Beginning batch registration.")
success = 0
failed = 0
try:
for i in range(count):
log(f"===== Account {i + 1}/{count} =====")
try:
u, p, e, tok, uid = register_one(browser, mail, proxy=proxy)
line = f"{u}:{p}:{e}:{uid}:{tok}"
save_account(line)
log(f"SUCCESS: {u} (uid={uid}) token={tok[:24]}...")
success += 1
except Exception as ex:
failed += 1
log(f"FAILED: {ex}")
traceback.print_exc()
time.sleep(3)
finally:
browser.close()
log(f"Done. success={success} failed={failed}")
with open(os.environ["GITHUB_OUTPUT"], "a") if "GITHUB_OUTPUT" in os.environ else open(os.devnull, "w") as f:
f.write(f"success={success}\nfailed={failed}\n")
if success == 0:
sys.exit(1)
if __name__ == "__main__":
main()