Skip to content

add-video/add-audio: silent skip on filename collision in assets dir (no warning) #37

Closed

Description

@naoyashiga

Summary

addVideo (and likely addAudio) in src/factory.ts copies source files into
assets/video/<basename> using only the file's basename, and skips the copy
if the destination already exists:

const filename = basename(opts.path) || "media";
const destPath = resolve(assetsDir, filename);
if (!existsSync(destPath)) {
  copyFileSync(opts.path, destPath);
}

If two different source files share the same basename (e.g. en/0_00.png
and jp/0_00.png), the second one added is silently skipped — the draft
ends up pointing at the wrong file's content, with no error or warning.

Expected behavior

I understand the reasoning behind skipping the copy when the destination
already exists (avoids redundant copies). But when the skip happens because
of a different source file resolving to the same destination filename,
the CLI should print a warning to the console, e.g.:

Warning: "assets/video/0_00.png" already exists from a different source
file; skipping copy. The draft may reference stale content.

This would make the collision visible instead of silently producing a
draft with the wrong media.

Repro

  1. capcut add-video <project> path/to/jp/0_00.png 0s 7s
  2. capcut add-video <project> path/to/en/0_00.png 0s 7s
  3. The second segment's material ends up pointing at the jp image content,
    with no warning printed.

Activity

  1. renezander030 commented on Jul 2, 2026

    @renezander030
    Owner

    Thanks — great catch, and you're right that it hits addAudio too, not just addVideo.

    One nuance on the fix: the skip-on-exists is intentional (the Wikimedia fetch path pre-writes into assets/<kind> so the later copy is a deliberate no-op, and re-adding the same file mustn't re-copy). So rather than warn-only — which surfaces the collision but still leaves the draft pointing at stale content — I made it content-aware:

    • existing file is byte-identical → keep the silent no-op
    • a different source resolving to the same basename → write it under a content-hashed name (0_00.<sha1-8>.png) and warn on stderr

    That way the draft ends up referencing the correct content, not just flagged.

    Fix + tests in #38. Thanks again for the precise repro and code pointer — made this a quick one.

  2. naoyashiga commented on Jul 2, 2026

    @naoyashiga
    Author

    Thank you for the quick fix!

  3. renezander030 commented on Jul 2, 2026

    @renezander030
    Owner

    No worries. This is a team effort. Bring in patches as you spot them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions