{"record":{"id":"e7c824067632624d","repo":"affaan-m/ECC","slug":"invalid-media-duration-path-name","errorCode":null,"errorMessage":"Invalid media duration: {path.name}","messagePattern":"Invalid media duration: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/media/capcut.py","lineNumber":69,"sourceCode":"    overwrite=False,\n    cc=None,\n    probe=duration_of,\n):\n    geometry(width, height, fps)\n    if overwrite:\n        raise ValueError(\"CapCut draft replacement is unsafe; choose a new name\")\n    if not re.fullmatch(r\"[A-Za-z0-9][A-Za-z0-9_. -]{0,99}\", name) or name.endswith(\n        \".\"\n    ):\n        raise ValueError(\"Draft name must be a plain file name\")\n    if not files:\n        raise ValueError(\"At least one video is required\")\n    prepared = []\n    for filename in files:\n        path = Path(filename).resolve(strict=True)\n        duration = probe(path)\n        if not math.isfinite(duration) or duration <= 0:\n            raise ValueError(f\"Invalid media duration: {path.name}\")\n        prepared.append((str(path), duration))\n    if cc is None:\n        import pycapcut as cc\n    folder = cc.DraftFolder(str(drafts))\n    script = folder.create_draft(name, width, height, fps=fps, allow_replace=False)\n    script.add_track(cc.TrackType.video)\n    elapsed = 0\n    for filename, duration in prepared:\n        script.add_segment(\n            cc.VideoSegment(filename, cc.trange(f\"{elapsed:.6f}s\", f\"{duration:.6f}s\"))\n        )\n        elapsed += duration\n    script.save()\n    return {\"name\": name, \"segments\": len(prepared), \"duration\": elapsed, \"saved\": True}\n\n\ndef main(argv=None):\n    parser = argparse.ArgumentParser(description=__doc__)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/media/capcut.py#L51-L87","documentation":"For each input video, export_draft calls probe(path) to get its duration and rejects any duration that is not a finite positive number. Non-finite (NaN/inf), zero, or negative durations indicate unreadable or corrupt media, or a broken probe backend.","triggerScenarios":"A video file that ffprobe cannot read (corrupt file, unsupported codec), a custom probe callable returning None/NaN/0/negative, or files that resolve but are not actual media.","commonSituations":"Zero-byte or partially downloaded video files; image files passed instead of videos; a stubbed probe in tests/CI where ffprobe is missing and returns garbage; media with missing duration metadata in unusual containers.","solutions":["Verify the file plays and ffprobe reports a duration: ffprobe -v error -show_entries format=duration <file>","Remove or re-download the corrupt/offending file (the message includes its name)","If passing a custom probe, ensure it returns a finite float > 0 and raises on unreadable media","Confirm the input is a video, not an image or audio-only file without duration"],"exampleFix":"// before\ndef probe(path): return None  # stub\nexport_draft(files, name='edit', probe=probe)\n\n// after\ndef probe(path):\n    out = subprocess.run(['ffprobe','-v','error','-show_entries','format=duration',\n                          '-of','csv=p=0',str(path)], capture_output=True, text=True, check=True)\n    return float(out.stdout.strip())","handlingStrategy":"validation","validationCode":"def duration_ok(d):\n    return isinstance(d, (int, float)) and math.isfinite(d) and d > 0\nfor f in files:\n    d = probe(Path(f).resolve(strict=True))\n    if not duration_ok(d):\n        raise ValueError(f'{f}: probe returned invalid duration {d!r}')","typeGuard":"def has_valid_duration(d):\n    return isinstance(d, (int, float)) and not isinstance(d, bool) and math.isfinite(d) and d > 0","tryCatchPattern":"try:\n    export_draft(files, name=name)\nexcept ValueError as e:\n    if 'Invalid media duration' in str(e):\n        bad = str(e).split(': ')[-1]\n        sys.exit(f're-encode or remove corrupt media: {bad}')","preventionTips":["Pre-flight every input with ffprobe before export","Check for zero-byte or partially downloaded files","If injecting a custom probe, test it against corrupt and non-media files","Re-encode problem files: ffmpeg -i in.mp4 -c copy fixed.mp4"],"tags":["python","ffprobe","media","duration"],"backgroundTag":"invalid-duration-format","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}