Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file names with special chars #12205

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/yafw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# YAFW Changelog

## [Support file names with special chars] - 2024-05-06

Files containing `'` would not work. That's fixed now.

## [Fix custom paths and add error logging] - 2024-04-30

Now custom paths should work properly. Also, added error logging to debug production issues.
Expand Down
6 changes: 5 additions & 1 deletion extensions/yafw/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const getFFmpegCommand = (args: string) => {
}
};

function sanitizeFileName(file: string): string {
return file.replace(/ /g, "\\ ").replace(/'/g, `\\'\\''`).replace(/\(/g, "\\(").replace(/\)/g, "\\)");
}

export async function compressVideoFiles(files: string[], compression: CompressionOptionKey): Promise<string[]> {
const one = files.length === 1;
await showToast(Toast.Style.Animated, one ? "Compressing video..." : "Compressing videos...");
Expand All @@ -69,7 +73,7 @@ export async function compressVideoFiles(files: string[], compression: Compressi
const output = file.replace(/\.\w+$/, ` (yafw ${compression}).mp4`);
const { crf, bitrate, bufsize } = COMPRESSION_OPTIONS[compression];
const command = getFFmpegCommand(
`-y -i "${file}" -vcodec libx264 -crf ${crf} -b:v ${bitrate} -bufsize ${bufsize} "${output}"`,
`-y -i ${sanitizeFileName(file)} -vcodec libx264 -crf ${crf} -b:v ${bitrate} -bufsize ${bufsize} ${sanitizeFileName(output)}`,
);

if (!command) {
Expand Down