Files
tdarr-plugs/tests/reproduce_issue.js
2026-01-30 05:55:22 -08:00

101 lines
2.9 KiB
JavaScript

const assert = require('assert');
// Mock data based on the issue description
const mockFile = {
container: 'mkv',
fileMedium: 'video',
ffProbeData: {
streams: [
{ // Stream 0: Video
index: 0,
codec_type: 'video',
codec_name: 'hevc',
channels: 0,
tags: { language: 'eng' }
},
{ // Stream 1: 5.1 Audio (eng)
index: 1,
codec_type: 'audio',
codec_name: 'ac3',
channels: 6,
tags: { language: 'eng' }
},
{ // Stream 2: 2.0 Audio (en) -- Existing stereo track with 'en' code
index: 2,
codec_type: 'audio',
codec_name: 'aac',
channels: 2,
tags: { language: 'en' }
}
]
}
};
const mockInputs = {
codec: 'opus',
create_downmix: 'true',
downmix_single_track: 'true', // Only create one downmix per channel count
channel_mode: 'preserve',
// ... other defaults
aac_profile: 'aac_low',
opus_vbr: 'on',
bitrate_per_channel: 'auto',
target_sample_rate: 'original',
skip_if_compatible: 'true',
force_transcode: 'false',
preserve_metadata: 'true',
set_default_by_channels: 'true'
};
// Simplified logic extraction from the plugin
function simulatePlugin(file, inputs) {
let audioStreams = [];
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
const stream = file.ffProbeData.streams[i];
if (stream.codec_type === 'audio') {
audioStreams.push({ index: i, ...stream });
}
}
let createdDownmixes = [];
if (inputs.create_downmix === 'true') {
for (const stream of audioStreams) {
if (stream.channels > 2) {
const lang = stream.tags ? stream.tags.language : 'und';
// The problematic check
const hasStereo = audioStreams.some(s =>
s.channels <= 2 && s.tags && s.tags.language === lang
);
if (!hasStereo || inputs.downmix_single_track === 'false') {
createdDownmixes.push({
sourceIndex: stream.index,
sourceLang: lang,
reason: hasStereo ? 'forced' : 'missing_stereo'
});
}
}
}
}
return createdDownmixes;
}
// Run Test
console.log('Running reproduction test...');
const results = simulatePlugin(mockFile, mockInputs);
console.log('Results:', results);
if (results.length > 0) {
console.log('FAIL: Plugin created a downmix despite existing stereo track mismatch (eng vs en)');
console.log('Expected: 0 downmixes');
console.log('Actual: ' + results.length + ' downmixes');
} else {
console.log('PASS: Plugin correctly identified existing stereo track.');
}