#!/usr/bin/env python3 """Claim mixroute (new-api fork) $5 welcome credit by solving its slide-puzzle captcha. Usage: python mixr_claim.py cookie_file: one line `session=...; _ga=...` harvested from a logged-in Chrome profile (ctx.cookies() joined as name=value). Only the `session` cookie actually matters. Idempotent: if the credit is already claimed it prints status and exits 0. """ import base64 import io as _io import json import sys from collections import deque import numpy as np import requests from PIL import Image BASE = "https://console.mixroute.ai" QUOTA_PER_USD = 500000 # read it from /api/status: data.quota_per_unit def session_from(uid: str, cookie_file: str) -> requests.Session: s = requests.Session() s.headers.update( { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36", "New-Api-User": str(uid), # without it every /api/user/self* is 401 "Accept": "application/json", "Origin": BASE, "Referer": BASE + "/dashboard", } ) raw = open(cookie_file, encoding="utf-8").read().strip() for kv in raw.split("; "): if "=" in kv: k, v = kv.split("=", 1) s.cookies.set(k, v, domain="console.mixroute.ai") return s def solve_slide(bg_bytes: bytes, piece_bytes: bytes): """Return slide offset in CHALLENGE-image pixels, or None. slide units are image px, not CSS px: the frontend sends Math.round(translateX / (clientWidth / challenge.width)). """ gray = np.array(Image.open(_io.BytesIO(bg_bytes)).convert("RGB")).astype(float).mean(axis=2) pa = np.array(Image.open(_io.BytesIO(piece_bytes)).convert("RGBA")) opaque = pa[:, :, 3] > 60 ys, xs = np.nonzero(opaque) piece_x0, piece_y0 = int(xs.min()), int(ys.min()) ph, pw = int(ys.max() - ys.min() + 1), int(xs.max() - xs.min() + 1) h, w = gray.shape for thr in (100, 80, 120, 60): mask = gray > thr seen = np.zeros_like(mask, bool) for y in range(h): for x in range(w): if not mask[y, x] or seen[y, x]: continue q, pts = deque([(y, x)]), [] seen[y, x] = True while q: cy, cx = q.popleft() pts.append((cy, cx)) for dy in (-1, 0, 1): for dx in (-1, 0, 1): ny, nx = cy + dy, cx + dx if 0 <= ny < h and 0 <= nx < w and mask[ny, nx] and not seen[ny, nx]: seen[ny, nx] = True q.append((ny, nx)) if len(pts) < 60: continue yy = [p[0] for p in pts] xx = [p[1] for p in pts] x0, x1, y0, y1 = min(xx), max(xx), min(yy), max(yy) # the hole outline is the component whose bbox equals the piece bbox if abs((x1 - x0 + 1) - pw) <= 3 and abs((y1 - y0 + 1) - ph) <= 3 and y0 >= ph * 0.5 - 20: return {"slide": x0 - piece_x0, "hole_x0": x0, "thr": thr, "piece_off": piece_x0, "size": [pw, ph]} return None def main() -> int: uid, cookie_file = sys.argv[1], sys.argv[2] s = session_from(uid, cookie_file) st = s.get(BASE + "/api/user/self/welcome-credit", timeout=30).json().get("data") or {} print("welcome:", json.dumps({k: st.get(k) for k in ("claimed", "eligible", "quota", "reviewing", "risk")})) if st.get("claimed"): print("already claimed") return 0 for attempt in range(1, 5): d = s.get(BASE + "/api/user/self/welcome-credit/challenge", timeout=30).json().get("data") or {} cid = d.get("challenge_id") if not cid: print("no challenge") return 1 solved = solve_slide(base64.b64decode(d["background"].split(",", 1)[1]), base64.b64decode(d["piece"].split(",", 1)[1])) print("attempt", attempt, "solved", solved) if not solved: return 1 r = s.post(BASE + "/api/user/self/welcome-credit/claim", json={"challenge_id": cid, "slide": int(solved["slide"])}, timeout=90) print("claim", r.status_code, r.text[:300]) if r.status_code == 200 and r.json().get("success"): break me = s.get(BASE + "/api/user/self", timeout=30).json().get("data") or {} quota = me.get("quota", 0) print("quota", quota, "= $%.4f" % (quota / QUOTA_PER_USD)) return 0 if quota > 0 else 1 if __name__ == "__main__": raise SystemExit(main())