#!/usr/bin/env python3 """acemusic.ai — авторегистрация одного/нескольких аккаунтов по HTTP. Капчи нет, браузер не нужен: POST /auth/signup -> код на почту -> POST /auth/verify. Переменные окружения: ACE_IMAP_HOST imap-сервер (default imap.gmail.com) ACE_IMAP_USER ящик, куда приходят письма (например you+ace1@gmail.com) ACE_IMAP_PASS пароль приложения ACE_TAG метка для плюс-алиасов (default ace) ACE_BANK файл банка (default bank.jsonl) Использование: python reg.py 1 5 # зарегистрировать ace1..ace5 """ import email as emaillib import imaplib import json import os import random import re import string import sys import time import requests IMAP_HOST = os.environ.get("ACE_IMAP_HOST", "imap.gmail.com") IMAP_USER = os.environ.get("ACE_IMAP_USER", "") IMAP_PASS = os.environ.get("ACE_IMAP_PASS", "") TAG = os.environ.get("ACE_TAG", "ace") BANK = os.environ.get("ACE_BANK", "bank.jsonl") BASE = "https://acemusic.ai" UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36") H = {"User-Agent": UA, "Origin": BASE, "Referer": BASE + "/signup/", "Content-Type": "application/json"} def imap_conn(): if not (IMAP_USER and IMAP_PASS): raise SystemExit("нужны ACE_IMAP_USER и ACE_IMAP_PASS") m = imaplib.IMAP4_SSL(IMAP_HOST, 993) m.login(IMAP_USER, IMAP_PASS) m.select("INBOX", readonly=True) return m def baseline_uid(): """ВАЖНО: вызывать ДО signup — письмо приходит за секунды и иначе отфильтруется.""" m = imap_conn() typ, d = m.uid("SEARCH", None, '(FROM "acestudio")') uids = [int(x) for x in d[0].split()] if d[0] else [] m.logout() return max(uids) if uids else 0 def fetch_code(min_uid, timeout=180): t0 = time.time() while time.time() - t0 < timeout: try: m = imap_conn() typ, d = m.uid("SEARCH", None, f'(FROM "acestudio" UID {min_uid + 1}:*)') uids = [int(x) for x in d[0].split()] if d[0] else [] if uids: uid = max(uids) typ, dd = m.uid("FETCH", str(uid), "(RFC822)") m.logout() msg = emaillib.message_from_bytes(dd[0][1]) body = "" for part in msg.walk(): if part.get_content_type() == "text/html": body = part.get_payload(decode=True).decode("utf-8", "replace") break m1 = re.search(r"letter-spacing:\s*8px[^>]*>\s*(\d{6})\s*<", body) m2 = re.search(r"font-size:\s*32px[^>]*>\s*(\d{6})", body) code = (m1 or m2) if code: return uid, code.group(1) else: m.logout() except Exception as e: # сеть/IMAP флапают — просто пробуем снова print("imap:", e, flush=True) time.sleep(4) return None, None def gen_password(): body = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(9)) return body + "!" + "".join(random.choice(string.digits) for _ in range(3)) def register(idx, tag=TAG): login, _, domain = IMAP_USER.partition("@") email = "%s+%s%d@%s" % (login, tag, idx, domain) pw = gen_password() s = requests.Session() base = baseline_uid() r = s.post(BASE + "/auth/signup", headers=H, json={"email": email, "password": pw}, timeout=30) if r.status_code != 200: print("signup fail", email, r.status_code, r.text[:150]) return None uid, code = fetch_code(base) if not code: print("no code", email) return None r = s.post(BASE + "/auth/verify", headers=H, json={"email": email, "code": code, "next": "/create/", "plan": None, "cycle": None}, timeout=30) if r.status_code != 200: print("verify fail", email, r.status_code, r.text[:150]) return None st = s.get(BASE + "/api/status", headers=H, timeout=30).json() user = st["user"] ck = s.cookies.get_dict() rec = {"email": email, "password": pw, "uid": user["id"], "credits": user["credits"], "plan": user["plan"], "cookies": {k: ck.get(k) for k in ("ace_at", "ace_rt", "ace_flow")}, "ts": int(time.time())} with open(BANK, "a") as f: f.write(json.dumps(rec) + "\n") print("OK", email, "uid", user["id"], "credits", user["credits"], flush=True) return rec if __name__ == "__main__": start = int(sys.argv[1]) if len(sys.argv) > 1 else 1 n = int(sys.argv[2]) if len(sys.argv) > 2 else 1 for i in range(start, start + n): register(i) time.sleep(1.2)