Skip to content

Commit

Permalink
removed ffprobe
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Oct 13, 2024
1 parent 73df344 commit 8de328e
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { State } from './state.js';
import { sqlite3 } from './database.js';
import {trackEvent} from './tracking.js';

const DEBUG = false;
const DEBUG = true;

// Function to join Buffers and not use Buffer.concat() which leads to detached ArrayBuffers
function joinBuffers(buffer1, buffer2) {
Expand Down Expand Up @@ -1149,8 +1149,8 @@ const setMetadata = async ({ file, source_file = file }) => {
if (! savedMeta?.duration) {
try {
METADATA[file].duration = await getDuration(file)
} catch {
return probeFile(file)
} catch (e) {
throw new Error('Unable to determine file duration ', e);
}
if (file.toLowerCase().endsWith('wav')){
const {extractGuanoMetadata} = await import('./guano.js').catch(error => {
Expand Down Expand Up @@ -1207,35 +1207,6 @@ const setMetadata = async ({ file, source_file = file }) => {
return METADATA[file];
}

function probeFile(file){
// Use ffprobe to get file information
ffmpeg.ffprobe('file:'+file, (err, metadata) => {
if (err) {
console.error('getDuration error: Error retrieving file info:', err);
} else {
//Log the file name
console.warn('getDuration error', file);
const formats = metadata.format.format_name.split(',')
.filter(format => SUPPORTED_FILES.includes(`.${format}`));

const codec = metadata.streams[0].codec_name;
const ext = p.extname(file).replace('.', '');
if (!formats.includes(ext)){
UI.postMessage({
event: 'generate-alert',
type: 'warning',
message: `The file ${p.basename(file)} seems to have an incorrect extension.
Chirpity supports the following extensions for this file type:
<b>${formats.join(',')}</b><br/>
<p> Try renaming it to ${p.basename(file, ext)}${formats[0]}.</p>`});
}
// Log the metadata to the console
console.warn('File metadata:', `Format: ${formats}, Codec: ${codec}`);
}
return false;
});
}

function setupCtx(audio, rate, destination, file) {
rate ??= sampleRate;
// Deal with detached arraybuffer issue
Expand Down

0 comments on commit 8de328e

Please sign in to comment.