Spaces:
Sleeping
Sleeping
Update main.py
#6
by kajalan - opened
129 unmodified lines13013113213313413521 unmodified lines157158159160161162163164165166167168169170171129 unmodified lines)@app.post("/api/probe",tags=["Media"],21 unmodified linesdetail=f"Failed to download Google Drive file: {str(e)}")data = await run_ffprobe(probe_target)return dataexcept HTTPException:raiseexcept RuntimeError as e:raise HTTPException(status_code=422, detail=str(e))finally:# Clean up temp file if we created oneif tmp_path:try:Path(tmp_path).unlink(missing_ok=True)129 unmodified lines13013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116221 unmodified lines184185186187188189190191192193194195196197198199200201202129 unmodified lines)def _run_ffprobe_direct(target: str) -> dict:"""Run ffprobe directly on a local path or URL, return parsed JSON."""import jsonimport subprocesscmd = ["ffprobe","-v", "quiet","-print_format", "json","-show_streams","-show_format","-show_error",target,]result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)stdout = result.stdout.strip()stderr = result.stderr.strip()if result.returncode != 0 or not stdout:raise RuntimeError(f"ffprobe failed (code {result.returncode}): {stderr or 'no output'}")try:return json.loads(stdout)except Exception:raise RuntimeError(f"ffprobe returned invalid JSON. stderr: {stderr}")@app.post("/api/probe",tags=["Media"],21 unmodified linesdetail=f"Failed to download Google Drive file: {str(e)}")# Run ffprobe directly (bypasses ffmpeg_runner to get full error detail)data = await asyncio.get_event_loop().run_in_executor(None, _run_ffprobe_direct, probe_target)return dataexcept HTTPException:raiseexcept RuntimeError as e:raise HTTPException(status_code=422, detail=str(e))except Exception as e:raise HTTPException(status_code=422, detail=f"Unexpected error: {str(e)}")finally:if tmp_path:try:Path(tmp_path).unlink(missing_ok=True)
main.py+33-2