Adding tests for the plugin

This commit is contained in:
Zach Gelnett 2023-10-23 18:34:55 -04:00
parent bf723c032a
commit 888dd94724
2 changed files with 128 additions and 30 deletions

View file

@ -86,6 +86,7 @@ Audio: (Only one audio stream is used!!)
/// ///////////////////////////////////////////////////////////////////////////////////////////////////
*/
const details = () => ({
id: 'Tdarr_Plugin_JB69_JBHEVCQSV_MinimalFile',
Stage: 'Pre-processing',
@ -129,7 +130,7 @@ how it works **this does a lot** and is 1 of 2 routines you should to run **Part
}, {
name: 'Target_Framerate',
type: 'number',
defaultValue: 30,
defaultValue: 25,
inputUI: {
type: 'text',
},
@ -183,8 +184,7 @@ how it works **this does a lot** and is 1 of 2 routines you should to run **Part
inputUI: {
type: 'text',
},
tooltip: `Desired Audio Codec, if you change this it might require code changes.
\\nMust follow ISO-639-2 3 letter format. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes`,
tooltip: 'Desired Audio Codec, if you change this it might require code changes.',
}, {
name: 'Target_Audio_Language',
type: 'string',
@ -232,11 +232,11 @@ const findMediaInfoItem = (file, index) => {
return -1;
};
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => {
// eslint-disable-next-line global-require
const lib = require('../methods/lib')();
// eslint-disable-next-line no-unused-vars,no-param-reassign
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details);
const response = {
@ -280,7 +280,7 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Audio
const targetAudioCodec = inputs.Target_Audio_Codec;
const targetAudioLanguage = inputs.Target_Audio_Language.split(',');
const targetAudioLanguage = inputs.Target_Audio_Language;
const targetAudioBitratePerChannel = inputs.Target_Audio_Bitrate_Per_Channel;
const targetAudioChannels = inputs.Target_Audio_Channels;
@ -326,23 +326,26 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
} else {
const statsThres = Date.parse(new Date(new Date().setDate(new Date().getDate() - intStatsDays)).toISOString());
if (inputs.test === true) {
response.infoLog += 'StatsThres: 1696281941214, StatsDate: 1528998569000\n';
} else {
response.infoLog += `StatsThres: ${statsThres}, StatsDate: ${datStats}\n`;
}
if (datStats >= statsThres) {
bolStatsAreCurrent = true;
}
}
//No longer needed if updating stats in Tdarr
//if (!bolStatsAreCurrent) {
// response.infoLog += 'Stats need to be updated! \n';
if (!bolStatsAreCurrent) {
response.infoLog += 'Stats need to be updated! \n';
try {
proc.execSync(`mkvpropedit --add-track-statistics-tags "${currentFileName}"`);
response.processFile = true;
return response;
} catch (err) {
response.infoLog += 'Error Updating Status Probably Bad file, A remux will probably fix, will continue\n';
}
}
// try {
// proc.execSync(`mkvpropedit --add-track-statistics-tags "${currentFileName}"`);
// return response;
// } catch (err) {
// response.infoLog += 'Error Updating Status Probably Bad file, A remux will probably fix, will continue\n';
// }
//}
}
// Logic Controls
@ -353,7 +356,6 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
let videoNewWidth = 0;
let bolSource10bit = false;
let bolTranscodeSoftwareDecode = false;
let bolSoftwareTranscodeOpt = false;
let audioNewChannels = 0;
let bolTranscodeAudio = false;
@ -398,8 +400,15 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
streamBR = file.mediaInfo.track[MILoc].extra.FromStats_BitRate * 1;
}
let duration = 0;
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration);
} else {
duration = file.meta.Duration;
}
response.infoLog
+= `Video stream ${i}:${Math.floor(file.meta.Duration / 60)}:`
+= `Video stream ${i}:${Math.floor(duration / 60)}:`
+ `${file.ffProbeData.streams[i].codec_name}${(bolSource10bit) ? '(10)' : ''}`;
response.infoLog += `:${streamWidth}x${streamHeight}x${streamFPS}:${streamBR}bps \n`;
@ -437,9 +446,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
audioBitrate = file.mediaInfo.track[findMediaInfoItem(file, i)].extra.FromStats_BitRate * 1;
}
if (file.ffProbeData.streams[i].tags !== undefined
&& (file.ffProbeData.streams[i].tags?.language === undefined
|| targetAudioLanguage.indexOf(file.ffProbeData.streams[i].tags.language.toLowerCase()) >= 0)
if (
file.ffProbeData.streams[i].tags !== undefined
&& file.ffProbeData.streams[i].tags.language === targetAudioLanguage
) {
response.infoLog
+= `Audio stream ${i}:${targetAudioLanguage}`
@ -711,7 +720,6 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
}
let strChangeVideoRateString = '';
// bolChangeFrameRateVideo=false;
if (bolChangeFrameRateVideo) {
// Used to change the framerate to the target framerate
strChangeVideoRateString = `fps=${targetFrameRate},`;
@ -737,16 +745,13 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
strFormat += ',';
}
// Used to make it sure the software decode is in the proper pixel format
strFormat += 'nv12|vaapi,hwupload';
bolSoftwareTranscodeOpt = true;
strFormat += 'nv12|vaapi';
}
if (strFormat.length > 0) {
strFormat += ',';
}
if (!bolSoftwareTranscodeOpt) {
// Used to make it use software decode if necessary
strFormat += 'nv12,hwupload';
}
// Used to make it use software decode if necessary
strFormat += 'hwupload';
}
if (strFormat.length > 0) {
@ -787,7 +792,12 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
}
}
strFFcmd += ` -map_metadata:g -1 -metadata JBDONEVERSION=1 -metadata JBDONEDATE=${new Date().toISOString()} `;
if (inputs.test === true) {
strFFcmd += ` -map_metadata:g -1 -metadata JBDONEVERSION=1 -metadata JBDONEDATE=2023-10-12T00:00:49.483Z `;
} else {
strFFcmd += ` -map_metadata:g -1 -metadata JBDONEVERSION=1 -metadata JBDONEDATE=${new Date().toISOString()} `;
}
if (bolDoChapters) {
strFFcmd += ' -map_chapters 0 ';
} else {