"""Extract the top-of-file double-base64 magic from a fresh star.py."""
import base64, re, sys

src = open(sys.argv[1], encoding='utf-8').read()[:4000]
for cand in re.findall(r'["\']([A-Za-z0-9+/=]{24,})["\']', src):
    try:
        out = base64.b64decode(base64.b64decode(cand, validate=True), validate=True).decode()
    except Exception:
        continue
    if not out.isprintable():
        continue
    print(out.split(':', 1)[1].strip() if out.upper().startswith('MAGIC') else out.strip())
    sys.exit(0)
sys.exit('no magic found')
