Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Studio: find quoted and escaped custom draft folders (#168)

kwiver619c163d2632
diff --git a/.changeset/custom-draft-paths.md b/.changeset/custom-draft-paths.md
new file mode 100644
index 0000000..dd7edf2
--- /dev/null
+++ b/.changeset/custom-draft-paths.md
@@ -0,0 +1,5 @@
+---
+"openfilm": patch
+---
+
+Find custom Jianying and CapCut draft folders when their settings quote paths containing commas or semicolons, so exports go to the folder the app uses. Also read escaped paths from older Qt settings.
diff --git a/packages/openfilm/studio/server/jianying.mjs b/packages/openfilm/studio/server/jianying.mjs
index 20f9e58..3d17b02 100644
--- a/packages/openfilm/studio/server/jianying.mjs
+++ b/packages/openfilm/studio/server/jianying.mjs
@@ -40,6 +40,24 @@ import { join } from 'node:path';
/** Each app's folder, in Movies on a Mac and in the local app data on Windows. */
const APP_FOLDER = /** @type {Record<DraftApp, string>} */ ({ jianying: 'JianyingPro', capcut: 'CapCut' });
+/** The custom folder in Qt's INI: quotes and escapes are storage syntax, not part of the path. @param {string} settings */
+function customDraftPath(settings) {
+ let section = 'General';
+ for (const row of settings.split(/\r?\n/)) {
+ const line = row.trim();
+ const heading = /^\[(.*)\]$/.exec(line);
+ if (heading) { section = heading[1]; continue; }
+ if (section !== 'General') continue;
+ const entry = /^currentCustomDraftPath\s*=\s*(.*)$/.exec(line);
+ if (!entry) continue;
+ const value = entry[1].startsWith('"') && entry[1].endsWith('"') ? entry[1].slice(1, -1) : entry[1];
+ const escapes = /** @type {Record<string, string>} */ ({ '0': '\0', a: '\x07', b: '\b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v' });
+ return value.replace(/\\(?:x([0-9a-fA-F]{1,4})|(.))/g,
+ (_match, hex, char) => hex ? String.fromCharCode(parseInt(hex, 16)) : escapes[char] ?? char) || null;
+ }
+ return null;
+}
+
/**
* Where 剪映 or CapCut keeps its drafts: the folder its Settings › Drafts location names (`currentCustomDraftPath` in
* its `User Data/Config/globalSetting`, the same in both apps), else its default one, when that folder is there; else
@@ -53,7 +71,7 @@ export function draftsRoot(app, { platform = process.platform, home, localAppDat
const user = join(base, APP_FOLDER[app], 'User Data');
let chosen = null;
try {
- chosen = /^currentCustomDraftPath=(.+)$/m.exec(read(join(user, 'Config', 'globalSetting')))?.[1].trim() || null;
+ chosen = customDraftPath(read(join(user, 'Config', 'globalSetting')));
} catch { /* the app has saved no settings yet */ }
for (const dir of [chosen, join(user, 'Projects', 'com.lveditor.draft')]) if (dir && exists(dir)) return dir;
return null;
diff --git a/packages/openfilm/studio/server/jianying.test.mjs b/packages/openfilm/studio/server/jianying.test.mjs
index 4b53595..e2813a4 100644
--- a/packages/openfilm/studio/server/jianying.test.mjs
+++ b/packages/openfilm/studio/server/jianying.test.mjs
@@ -104,6 +104,47 @@ test('the drafts folders: 剪映\'s and CapCut\'s, on a Mac and on Windows, when
assert.equal(draftsRoot('jianying', { platform: 'darwin', home: '/mac-home', read, exists: (p) => p === mac('JianyingPro') }), mac('JianyingPro'));
});
+test('custom drafts folders: Qt quotes and escapes are decoded for both apps on Mac and Windows', async (t) => {
+ const cases = [
+ { name: 'quoted punctuation', value: '"/drafts/Film, cut; take=2"', path: '/drafts/Film, cut; take=2' },
+ { name: 'escaped backslashes', value: String.raw`D:\\Film Cuts\\Drafts`, path: String.raw`D:\Film Cuts\Drafts` },
+ { name: 'escaped Unicode', value: String.raw`/drafts/\x8349\x7a3f\xd83c\xdfac`, path: '/drafts/草稿🎬' },
+ { name: 'escaped quotes', value: String.raw`"/drafts/Film \"One\""`, path: '/drafts/Film "One"' },
+ ];
+ for (const app of ['jianying', 'capcut']) {
+ for (const platform of ['darwin', 'win32']) {
+ for (const { name, value, path } of cases) {
+ await t.test(`${app} on ${platform}: ${name}`, () => {
+ const got = draftsRoot(app, {
+ platform, home: '/draft-home', localAppData: '/local-app-data',
+ read: () => `[General]\ncurrentCustomDraftPath=${value}\n`,
+ exists: (p) => p === path || p.endsWith('com.lveditor.draft'),
+ });
+ assert.equal(got, path, 'the custom folder takes precedence over the default');
+ });
+ }
+ }
+ }
+});
+
+test('custom drafts folders: read the General section, allowing whitespace and CRLF', () => {
+ const read = () => '\ufeff[Other]\r\ncurrentCustomDraftPath=/wrong\r\n[General]\r\n; currentCustomDraftPath=/comment\r\n currentCustomDraftPath = "/drafts/Film Cuts" \r\n[Later]\r\ncurrentCustomDraftPath=/later\r\n';
+ assert.equal(draftsRoot('jianying', { platform: 'darwin', home: '/draft-home', read, exists: () => true }), '/drafts/Film Cuts');
+ assert.equal(draftsRoot('capcut', {
+ platform: 'darwin', home: '/draft-home', read: () => '[Other]\ncurrentCustomDraftPath=/wrong\n',
+ exists: () => true,
+ }), join('/draft-home', 'Movies', 'CapCut', 'User Data', 'Projects', 'com.lveditor.draft'));
+});
+
+test('custom drafts folders: empty or missing decoded paths fall back to an existing default', () => {
+ const fallback = join('/draft-home', 'Movies', 'JianyingPro', 'User Data', 'Projects', 'com.lveditor.draft');
+ for (const value of ['', '""', '"/disconnected/Drafts"']) {
+ const where = { platform: 'darwin', home: '/draft-home', read: () => `[General]\ncurrentCustomDraftPath=${value}\n` };
+ assert.equal(draftsRoot('jianying', { ...where, exists: (p) => p === fallback }), fallback);
+ assert.equal(draftsRoot('jianying', { ...where, exists: () => false }), null);
+ }
+});
+
test('a draft says which app wrote it: 剪映 or CapCut', () => {
const jy = jianyingDraft(plan(), { name: 'Film', folder: '/d/Film', root: '/d' }).info;
const cc = jianyingDraft(plan(), { app: 'capcut', name: 'Film', folder: '/d/Film', root: '/d' }).info;