Merge pull request #267 from Enigma0/patch-3

Better precision for checking file duration
make-only-subtitle-default
HaveAGitGat 4 years ago committed by GitHub
commit 86b8c7c64c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,13 +8,13 @@ const details = () => ({
Operation: 'Transcode', Operation: 'Transcode',
Description: `Give an error if new file is not within the specified upper and lower bound duration limits. Description: `Give an error if new file is not within the specified upper and lower bound duration limits.
Make sure MediaInfo scan is enabled in library settings \n\n`, Make sure MediaInfo scan is enabled in library settings \n\n`,
Version: '1.00', Version: '1.02',
Tags: '', Tags: '',
Inputs: [ Inputs: [
{ {
name: 'upperBound', name: 'upperBound',
type: 'number', type: 'number',
defaultValue: 101, defaultValue: 100.5,
inputUI: { inputUI: {
type: 'text', type: 'text',
}, },
@ -25,7 +25,7 @@ const details = () => ({
{ {
name: 'lowerBound', name: 'lowerBound',
type: 'number', type: 'number',
defaultValue: 99, defaultValue: 99.5,
inputUI: { inputUI: {
type: 'text', type: 'text',
}, },
@ -50,8 +50,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
infoLog: '', infoLog: '',
}; };
let newData = 0; let newData = 0.0;
let oldData = 0; let oldData = 0.0;
const getData = (obj) => { const getData = (obj) => {
try { try {
@ -65,12 +65,12 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
newData = getData(file); newData = getData(file);
oldData = getData(otherArguments.originalLibraryFile); oldData = getData(otherArguments.originalLibraryFile);
const ratio = parseInt((newData / oldData) * 100, 10); const ratio = ((newData / oldData) * 100.0).toFixed(3);
const dataText = `New file has duration ${newData} s which is ${ratio}% ` const dataText = `New file has duration ${newData} s which is ${ratio}% `
+ `of original file duration: ${oldData} s`; + `of original file duration: ${oldData} s`;
const getBound = (bound) => (bound / 100) * oldData; const getBound = (bound) => (bound / 100.0) * oldData;
const errText = 'New file duration not within limits.'; const errText = 'New file duration not within limits.';
if (newData > getBound(inputs.upperBound)) { if (newData > getBound(inputs.upperBound)) {

Loading…
Cancel
Save