#!/bin/sh # AdCut CLI — same JSON as POST https://adcutapp.com/v1/cut # Install: curl -sL https://adcutapp.com/adcut -o adcut && chmod +x adcut # Usage: ./adcut file.txt # ./adcut --json file.txt # cat file.txt | ./adcut set -e API="https://adcutapp.com/v1/cut" if [ -n "$ADCUT_URL" ]; then API="$ADCUT_URL" fi JSON=0 FILE="" for arg in "$@"; do case "$arg" in --json) JSON=1 ;; -h|--help) printf '%s\n' "AdCut — cut a script into 6s / 15s / 30s (hook / proof / CTA)" printf '%s\n' "Usage: adcut [--json] [file]" printf '%s\n' " file or stdin → pretty-print cuts; --json prints the API body" printf '%s\n' "Install: curl -sL https://adcutapp.com/adcut -o adcut && chmod +x adcut" exit 0 ;; -*) printf '%s\n' "unknown option: $arg" >&2 exit 2 ;; *) FILE="$arg" ;; esac done if [ -n "$FILE" ]; then SCRIPT=$(cat "$FILE") else SCRIPT=$(cat) fi if [ -z "$SCRIPT" ]; then printf '%s\n' "adcut: empty script (pass a file or pipe stdin)" >&2 exit 1 fi escape_json() { if command -v python3 >/dev/null 2>&1; then python3 -c 'import json,sys; sys.stdout.write(json.dumps(sys.stdin.read()))' elif command -v python >/dev/null 2>&1; then python -c 'import json,sys; sys.stdout.write(json.dumps(sys.stdin.read()))' elif command -v jq >/dev/null 2>&1; then jq -Rs . else printf '"' printf '%s' "$SCRIPT" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/ /\\t/g' printf '"' fi } PAYLOAD=$(printf '%s' "$SCRIPT" | escape_json) RESP=$(printf '{"script":%s}' "$PAYLOAD" | curl -sS -X POST "$API" -H 'content-type: application/json' --data-binary @-) if [ "$JSON" -eq 1 ]; then printf '%s\n' "$RESP" exit 0 fi if command -v python3 >/dev/null 2>&1; then printf '%s' "$RESP" | python3 -c ' import json,sys d=json.load(sys.stdin) if not d.get("ok"): sys.stderr.write((d.get("error") or json.dumps(d))+"\n") sys.exit(1) if d.get("engine") or d.get("ms") is not None: print("engine %s %sms" % (d.get("engine") or "?", d.get("ms"))) for key in ("6s","15s","30s"): c=d["cuts"][key] print("== %s (~%ss, %s words) ==" % (key, c.get("est_seconds"), c.get("words"))) print("HOOK "+(c.get("hook") or "")) print("PROOF "+(c.get("proof") or "")) print("CTA "+(c.get("cta") or "")) print("") ' elif command -v jq >/dev/null 2>&1; then printf '%s' "$RESP" | jq -r ' if .ok != true then ("error: "+(.error // "cut failed")) | halt_error(1) else empty end, (.cuts | to_entries[] | "== \(.key) (~\(.value.est_seconds)s, \(.value.words) words) ==\nHOOK \(.value.hook // "")\nPROOF \(.value.proof // "")\nCTA \(.value.cta // "")\n") ' else printf '%s\n' "$RESP" fi