Skip to content

Open-source alternative to Opus Clip, Vidyo.ai, Klap & SubMagic. Turn long-form YouTube videos into viral 9:16 shorts using LLM highlight detection, Whisper transcription, and auto vertical cropping — free, no watermarks, no per-clip credits.

Fix MuAPI integration: gpt-5-4 → gpt-5-mini, outputs key, timeouts

Anil Matcha8cf66ba90da1
diff --git a/shorts_generator/downloader.py b/shorts_generator/downloader.py
index 5037e51..cd84e11 100644
--- a/shorts_generator/downloader.py
+++ b/shorts_generator/downloader.py
@@ -11,16 +11,7 @@ def _extract_video_url(result: Dict) -> str:
if isinstance(v, str) and v.startswith("http"):
return v
- outputs = result.get("outputs")
- if isinstance(outputs, list) and outputs and isinstance(outputs[0], str) and outputs[0].startswith("http"):
- return outputs[0]
- if isinstance(outputs, dict):
- for key in ("video_url", "url", "output_url"):
- v = outputs.get(key)
- if isinstance(v, str) and v.startswith("http"):
- return v
-
- output = result.get("output") or result.get("result") or {}
+ output = result.get("outputs") or result.get("output") or result.get("result") or {}
if isinstance(output, dict):
for key in ("video_url", "url", "output_url"):
v = output.get(key)
diff --git a/shorts_generator/highlights.py b/shorts_generator/highlights.py
index 5db6ae3..8ac6977 100644
--- a/shorts_generator/highlights.py
+++ b/shorts_generator/highlights.py
@@ -60,8 +60,12 @@ CHUNK_OVERLAP_SECONDS = 60
def _call_gpt(prompt: str) -> str:
- """Send a single text prompt to MuAPI gpt-5-4 and return the raw text."""
- result = muapi.run("gpt-5-4", {"prompt": prompt}, label="gpt-5-4")
+ """Send a single text prompt to MuAPI gpt-5-mini and return the raw text."""
+ result = muapi.run("gpt-5-mini", {"prompt": prompt}, label="gpt-5-mini")
+
+ outputs = result.get("outputs")
+ if isinstance(outputs, list) and outputs and isinstance(outputs[0], str) and outputs[0].strip():
+ return outputs[0]
for key in ("output", "text", "response", "result", "content"):
v = result.get(key)
@@ -74,7 +78,7 @@ def _call_gpt(prompt: str) -> str:
if isinstance(v, list) and v and isinstance(v[0], str):
return v[0]
- raise RuntimeError(f"Could not extract gpt-5-4 text from response: {result}")
+ raise RuntimeError(f"Could not extract gpt-5-mini text from response: {result}")
def _parse_json_loose(raw: str) -> Dict:
diff --git a/shorts_generator/muapi.py b/shorts_generator/muapi.py
index d7a8e7a..095400a 100644
--- a/shorts_generator/muapi.py
+++ b/shorts_generator/muapi.py
@@ -23,26 +23,40 @@ def _headers() -> Dict[str, str]:
}
-def submit(endpoint: str, payload: Dict[str, Any]) -> str:
- """POST to /api/v1/{endpoint} and return the request_id."""
+def submit(endpoint: str, payload: Dict[str, Any], retries: int = 3) -> str:
+ """POST to /api/v1/{endpoint} and return the request_id; retry transient errors."""
url = f"{MUAPI_BASE_URL}/{endpoint.lstrip('/')}"
- resp = requests.post(url, json=payload, headers=_headers(), timeout=60)
- if resp.status_code >= 400:
- raise MuAPIError(f"{endpoint} submit failed [{resp.status_code}]: {resp.text}")
- data = resp.json()
- request_id = data.get("request_id") or data.get("id")
- if not request_id:
- raise MuAPIError(f"{endpoint} response had no request_id: {data}")
- return str(request_id)
-
-
-def fetch_result(request_id: str) -> Dict[str, Any]:
- """GET the latest result for a request_id."""
+ last_err: Optional[Exception] = None
+ for _ in range(retries):
+ try:
+ resp = requests.post(url, json=payload, headers=_headers(), timeout=120)
+ if resp.status_code >= 400:
+ raise MuAPIError(f"{endpoint} submit failed [{resp.status_code}]: {resp.text}")
+ data = resp.json()
+ request_id = data.get("request_id") or data.get("id")
+ if not request_id:
+ raise MuAPIError(f"{endpoint} response had no request_id: {data}")
+ return str(request_id)
+ except (requests.Timeout, requests.ConnectionError) as e:
+ last_err = e
+ time.sleep(2)
+ raise MuAPIError(f"{endpoint} submit failed after {retries} retries: {last_err}")
+
+
+def fetch_result(request_id: str, retries: int = 3) -> Dict[str, Any]:
+ """GET the latest result for a request_id; retry on transient timeouts."""
url = f"{MUAPI_BASE_URL}/predictions/{request_id}/result"
- resp = requests.get(url, headers=_headers(), timeout=30)
- if resp.status_code >= 400:
- raise MuAPIError(f"poll failed [{resp.status_code}]: {resp.text}")
- return resp.json()
+ last_err: Optional[Exception] = None
+ for _ in range(retries):
+ try:
+ resp = requests.get(url, headers=_headers(), timeout=90)
+ if resp.status_code >= 400:
+ raise MuAPIError(f"poll failed [{resp.status_code}]: {resp.text}")
+ return resp.json()
+ except (requests.Timeout, requests.ConnectionError) as e:
+ last_err = e
+ time.sleep(2)
+ raise MuAPIError(f"poll failed after {retries} retries: {last_err}")
def poll(