84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
|
|
// Mock Tdarr lib
|
|
const lib = {
|
|
loadDefaultValues: (inputs, details) => {
|
|
const d = details();
|
|
const result = { ...inputs };
|
|
d.Inputs.forEach(i => {
|
|
if (result[i.name] === undefined) result[i.name] = i.defaultValue;
|
|
});
|
|
return result;
|
|
}
|
|
};
|
|
|
|
const moduleAlias = require('module');
|
|
const originalRequire = moduleAlias.prototype.require;
|
|
moduleAlias.prototype.require = function (path) {
|
|
if (path === '../methods/lib') {
|
|
return () => lib;
|
|
}
|
|
return originalRequire.apply(this, arguments);
|
|
};
|
|
|
|
const { plugin } = require('../Local/Tdarr_Plugin_combined_audio_standardizer');
|
|
|
|
const mockFile = {
|
|
container: 'mkv',
|
|
fileMedium: 'video',
|
|
ffProbeData: {
|
|
streams: [
|
|
{ index: 0, codec_type: 'video', codec_name: 'h264' },
|
|
{
|
|
index: 1,
|
|
codec_type: 'audio',
|
|
codec_name: 'dts',
|
|
channels: 6,
|
|
bit_rate: 1536000,
|
|
tags: { title: '"Original Title"', language: '"eng"' }
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
const inputs = {
|
|
codec: 'aac',
|
|
bitrate_per_channel: '64',
|
|
channel_mode: 'preserve',
|
|
create_downmix: 'true',
|
|
preserve_metadata: 'true',
|
|
quality_preset: 'custom',
|
|
set_default_by_channels: 'true'
|
|
};
|
|
|
|
const result = plugin(mockFile, {}, inputs, {});
|
|
|
|
console.log('--- Info Log ---');
|
|
console.log(result.infoLog);
|
|
console.log('--- Preset ---');
|
|
console.log(result.preset);
|
|
|
|
// Verify metadata arguments
|
|
const hasDoubleQuotes = result.preset.includes('""');
|
|
const hasQuotedTitle = result.preset.includes('title=Original Title');
|
|
const hasQuotedLang = result.preset.includes('language=eng');
|
|
|
|
if (hasDoubleQuotes) {
|
|
console.error('FAIL: Found double-double quotes in preset!');
|
|
} else {
|
|
console.log('PASS: No double-double quotes found.');
|
|
}
|
|
|
|
if (hasQuotedTitle && hasQuotedLang) {
|
|
console.log('PASS: Metadata sanitized and correctly formatted.');
|
|
} else {
|
|
console.error('FAIL: Metadata formatting incorrect.');
|
|
}
|
|
|
|
// Verify title for downmix
|
|
const hasDownmixTitle = result.preset.includes('title=2.0 Downmix (Original Title)');
|
|
if (hasDownmixTitle) {
|
|
console.log('PASS: Downmix title includes source title.');
|
|
} else {
|
|
console.error('FAIL: Downmix title generic or incorrect.');
|
|
}
|