Skip to content

Commit

Permalink
Found a more robust way to pass filesnames to ffmpeg, after some goog…
Browse files Browse the repository at this point in the history
…ling. Now files can have a '?' character in them
  • Loading branch information
Mattk70 committed Oct 9, 2024
1 parent b14d583 commit 4532f4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
8 changes: 1 addition & 7 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,15 +983,9 @@ function filterFilePaths(filePaths) {
const filteredPaths = [];
filePaths.forEach(filePath => {
const baseName = p.basename(filePath);
const hasQuestionMark = filePath.includes('?');
const isHiddenFile = baseName.startsWith('.');

if (hasQuestionMark) {
generateToast({type: 'warning', message:`<b>${filePath}</b><br> contains an invalid '?' character. It will not be opened`})
}

// Only add the path if it’s not hidden and doesn’t contain '?'
if (!isHiddenFile && !hasQuestionMark) {
if (!isHiddenFile) {
filteredPaths.push(filePath);
}
});
Expand Down
12 changes: 6 additions & 6 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ const getFiles = async (files, image) => {
file_list = [...file_list,...dirFiles]
} else {
const filename = p.basename(path)
filename.startsWith('.') || file_list.push(path) // Exclude hidden files
filename.startsWith('.') || file_list.push(path) // Exclude hidden files (in subfolders)
}
}
// filter out unsupported files
Expand Down Expand Up @@ -940,7 +940,7 @@ const getDuration = async (src) => {
let audio;
return new Promise(function (resolve, reject) {
audio = new Audio();
audio.src = src.replace(/#/g, '%23'); // allow hash in the path (https://github.com/Mattk70/Chirpity-Electron/issues/98)
audio.src = src.replaceAll('#', '%23').replaceAll('?', '%3F'); // allow hash in the path (https://github.com/Mattk70/Chirpity-Electron/issues/98)
audio.addEventListener("loadedmetadata", function () {
const duration = audio.duration;
audio = undefined;
Expand Down Expand Up @@ -1382,7 +1382,7 @@ const getPredictBuffers = async ({
let chunkStart = start * sampleRate;
return new Promise((resolve, reject) => {
let concatenatedBuffer = Buffer.alloc(0);
const command = ffmpeg(file)
const command = ffmpeg('file:' + file)
.seekInput(start)
.duration(end - start)
.format('wav')
Expand Down Expand Up @@ -1505,7 +1505,7 @@ const fetchAudioBuffer = async ({
end = Math.min(end, METADATA[file].duration);
// Use ffmpeg to extract the specified audio segment
return new Promise((resolve, reject) => {
let command = ffmpeg(file)
let command = ffmpeg('file:' + file)
.seekInput(start)
.duration(end - start)
.format('wav')
Expand Down Expand Up @@ -1843,7 +1843,7 @@ const bufferToAudio = async ({

return new Promise(function (resolve, reject) {
const bufferStream = new PassThrough();
let ffmpgCommand = ffmpeg(file)
let ffmpgCommand = ffmpeg('file:' + file)
.toFormat(soundFormat)
.seekInput(start)
.duration(end - start)
Expand Down Expand Up @@ -3654,7 +3654,7 @@ async function convertFile(inputFilePath, fullFilePath, row, db, dbArchiveName,
const boundaries = await setStartEnd(inputFilePath);

return new Promise((resolve, reject) => {
let command = ffmpeg(inputFilePath);
let command = ffmpeg('file:' + inputFilePath)

if (STATE.archive.format === 'ogg') {
command.audioBitrate('128k')
Expand Down

0 comments on commit 4532f4c

Please sign in to comment.