mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
tidy
This commit is contained in:
parent
d28272f6d4
commit
9c8ac98728
60 changed files with 5481 additions and 5980 deletions
|
|
@ -1,14 +1,21 @@
|
|||
var fs = require('fs');
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
if (fs.existsSync(path.join(process.cwd() , "/npm"))) {
|
||||
var rootModules = path.join(process.cwd() , '/npm/node_modules/')
|
||||
} else{
|
||||
var rootModules = ''
|
||||
if (fs.existsSync(path.join(process.cwd(), "/npm"))) {
|
||||
var rootModules = path.join(process.cwd(), "/npm/node_modules/");
|
||||
} else {
|
||||
var rootModules = "";
|
||||
}
|
||||
const importFresh = require(rootModules+'import-fresh');
|
||||
const importFresh = require(rootModules + "import-fresh");
|
||||
|
||||
|
||||
module.exports.remuxContainer = importFresh('./library/actions/remuxContainer.js')
|
||||
module.exports.transcodeStandardiseAudioCodecs = importFresh('./library/actions/transcodeStandardiseAudioCodecs.js')
|
||||
module.exports.transcodeAddAudioStream = importFresh('./library/actions/transcodeAddAudioStream.js')
|
||||
module.exports.transcodeKeepOneAudioStream = importFresh('./library/actions/transcodeKeepOneAudioStream.js')
|
||||
module.exports.remuxContainer = importFresh(
|
||||
"./library/actions/remuxContainer.js"
|
||||
);
|
||||
module.exports.transcodeStandardiseAudioCodecs = importFresh(
|
||||
"./library/actions/transcodeStandardiseAudioCodecs.js"
|
||||
);
|
||||
module.exports.transcodeAddAudioStream = importFresh(
|
||||
"./library/actions/transcodeAddAudioStream.js"
|
||||
);
|
||||
module.exports.transcodeKeepOneAudioStream = importFresh(
|
||||
"./library/actions/transcodeKeepOneAudioStream.js"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,20 @@
|
|||
var fs = require('fs');
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
if (fs.existsSync(path.join(process.cwd() , "/npm"))) {
|
||||
var rootModules = path.join(process.cwd() , '/npm/node_modules/')
|
||||
} else{
|
||||
var rootModules = ''
|
||||
if (fs.existsSync(path.join(process.cwd(), "/npm"))) {
|
||||
var rootModules = path.join(process.cwd(), "/npm/node_modules/");
|
||||
} else {
|
||||
var rootModules = "";
|
||||
}
|
||||
const importFresh = require(rootModules+'import-fresh');
|
||||
const importFresh = require(rootModules + "import-fresh");
|
||||
|
||||
|
||||
module.exports.filterByAge = importFresh('./library/filters/filterByAge.js')
|
||||
module.exports.filterByCodec = importFresh('./library/filters/filterByCodec.js')
|
||||
module.exports.filterByMedium = importFresh('./library/filters/filterByMedium.js')
|
||||
module.exports.filterByResolution = importFresh('./library/filters/filterByResolution.js')
|
||||
module.exports.filterBySize = importFresh('./library/filters/filterBySize.js')
|
||||
module.exports.filterByAge = importFresh("./library/filters/filterByAge.js");
|
||||
module.exports.filterByCodec = importFresh(
|
||||
"./library/filters/filterByCodec.js"
|
||||
);
|
||||
module.exports.filterByMedium = importFresh(
|
||||
"./library/filters/filterByMedium.js"
|
||||
);
|
||||
module.exports.filterByResolution = importFresh(
|
||||
"./library/filters/filterByResolution.js"
|
||||
);
|
||||
module.exports.filterBySize = importFresh("./library/filters/filterBySize.js");
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
var fs = require('fs');
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
if (fs.existsSync(path.join(process.cwd() , "/npm"))) {
|
||||
var rootModules = path.join(process.cwd() , '/npm/node_modules/')
|
||||
} else{
|
||||
var rootModules = ''
|
||||
if (fs.existsSync(path.join(process.cwd(), "/npm"))) {
|
||||
var rootModules = path.join(process.cwd(), "/npm/node_modules/");
|
||||
} else {
|
||||
var rootModules = "";
|
||||
}
|
||||
const importFresh = require(rootModules+'import-fresh');
|
||||
const importFresh = require(rootModules + "import-fresh");
|
||||
|
||||
module.exports.filters = importFresh('./filters.js')
|
||||
module.exports.actions = importFresh('./actions.js')
|
||||
module.exports.filters = importFresh("./filters.js");
|
||||
module.exports.actions = importFresh("./actions.js");
|
||||
|
|
|
|||
|
|
@ -1,38 +1,25 @@
|
|||
|
||||
|
||||
function remuxContainer(file, container) {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
if (file.container != container) {
|
||||
|
||||
var response = {
|
||||
processFile: true,
|
||||
note:`File is not in ${container} \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
processFile: false,
|
||||
note:`File is already in ${container} \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
var response = {
|
||||
processFile: false,
|
||||
note:`library.actions.remuxContainer error: ${err} \n`
|
||||
}
|
||||
return response
|
||||
try {
|
||||
if (file.container != container) {
|
||||
var response = {
|
||||
processFile: true,
|
||||
note: `File is not in ${container} \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
processFile: false,
|
||||
note: `File is already in ${container} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
} catch (err) {
|
||||
var response = {
|
||||
processFile: false,
|
||||
note: `library.actions.remuxContainer error: ${err} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = remuxContainer
|
||||
module.exports = remuxContainer;
|
||||
|
|
|
|||
|
|
@ -1,313 +1,276 @@
|
|||
module.exports = function transcodeAddAudioStream(
|
||||
file,
|
||||
audioEncoder,
|
||||
langTag,
|
||||
channelCount
|
||||
) {
|
||||
// response.preset = library.actions.transcodeAddAudioStream(file, 'aac', 'en', 1).preset
|
||||
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
|
||||
module.exports = function transcodeAddAudioStream(file, audioEncoder, langTag, channelCount) {
|
||||
try {
|
||||
var audioCodec = audioEncoder;
|
||||
langTag = langTag.toLowerCase();
|
||||
|
||||
// response.preset = library.actions.transcodeAddAudioStream(file, 'aac', 'en', 1).preset
|
||||
if (audioEncoder == "dca") {
|
||||
audioCodec = "dts";
|
||||
}
|
||||
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
if (audioEncoder == "libmp3lame") {
|
||||
audioCodec = "mp3";
|
||||
}
|
||||
|
||||
try {
|
||||
//Step 1: Check if the file already has the required stream codec/langtag/channel count
|
||||
|
||||
var audioCodec = audioEncoder
|
||||
langTag = langTag.toLowerCase()
|
||||
|
||||
if (audioEncoder == 'dca') {
|
||||
audioCodec = 'dts'
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) &&
|
||||
stream.channels == channelCount
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
if (audioEncoder == 'libmp3lame') {
|
||||
audioCodec = 'mp3'
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels\n`,
|
||||
};
|
||||
}
|
||||
|
||||
//Step 2: Check if file has streams with specified lang tag
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.tags.language.toLowerCase().includes(langTag)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
//Step 1: Check if the file already has the required stream codec/langtag/channel count
|
||||
return false;
|
||||
});
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
console.log("streamsWithLangTag:" + streamsWithLangTag);
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) && stream.channels == channelCount) {
|
||||
return true
|
||||
}
|
||||
if (streamsWithLangTag.length != 0) {
|
||||
return attemptMakeStreamLang(langTag);
|
||||
} else {
|
||||
return attemptMakeStreamUnd("und");
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
function attemptMakeStreamLang(langTag) {
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.tags.language.toLowerCase().includes(langTag)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest);
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first;
|
||||
} else {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
stream.tags.language
|
||||
.toLowerCase()
|
||||
.includes(langTag.toLowerCase()) &&
|
||||
stream.channels == channelCount
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels\n`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Step 2: Check if file has streams with specified lang tag
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.tags.language.toLowerCase().includes(langTag)) {
|
||||
return true
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
|
||||
})
|
||||
|
||||
console.log("streamsWithLangTag:" + streamsWithLangTag)
|
||||
|
||||
if (streamsWithLangTag.length != 0) {
|
||||
|
||||
return attemptMakeStreamLang(langTag)
|
||||
|
||||
} else {
|
||||
|
||||
return attemptMakeStreamUnd('und')
|
||||
|
||||
}
|
||||
|
||||
|
||||
function attemptMakeStreamLang(langTag) {
|
||||
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.tags.language.toLowerCase().includes(langTag)) {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
|
||||
})
|
||||
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest)
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first
|
||||
} else {
|
||||
return second
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) && stream.channels == channelCount) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}). Adding! \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
console.log('here3')
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) && stream.channels == highestChannelCount.channels) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${highestChannelCount.channels} channels (Highest available) \n`
|
||||
}
|
||||
} else {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track. \n`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function attemptMakeStreamUnd(langTag) {
|
||||
|
||||
console.log('No tracks with specified lang tag exist. Checking undefined tracks.')
|
||||
|
||||
console.log(langTag)
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && (stream.tags == undefined || stream.tags.language == undefined || stream.tags.language.toLowerCase().includes(langTag))) {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
|
||||
})
|
||||
|
||||
if (streamsWithLangTag.length == 0) {
|
||||
return {
|
||||
preset: ``,
|
||||
processFile: false,
|
||||
note: `Unable to add audio stream in ${langTag}/und with ${channelCount} channels \n`
|
||||
}
|
||||
}
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest)
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first
|
||||
} else {
|
||||
return second
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && (stream.tags == undefined || stream.tags.language == undefined || stream.tags.language.toLowerCase().includes(langTag)) && stream.channels == channelCount) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}). Adding! \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && (stream.tags == undefined || stream.tags.language == undefined || stream.tags.language.toLowerCase().includes(langTag)) && stream.channels == highestChannelCount.channels) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${highestChannelCount.channels} channels (Highest available) \n`
|
||||
}
|
||||
} else {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track. \n`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeAddAudioStream error: ${err} \n`
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}). Adding! \n`,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
console.log("here3");
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
stream.tags.language
|
||||
.toLowerCase()
|
||||
.includes(langTag.toLowerCase()) &&
|
||||
stream.channels == highestChannelCount.channels
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${highestChannelCount.channels} channels (Highest available) \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track. \n`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attemptMakeStreamUnd(langTag) {
|
||||
console.log(
|
||||
"No tracks with specified lang tag exist. Checking undefined tracks."
|
||||
);
|
||||
|
||||
console.log(langTag);
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
(stream.tags == undefined ||
|
||||
stream.tags.language == undefined ||
|
||||
stream.tags.language.toLowerCase().includes(langTag))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (streamsWithLangTag.length == 0) {
|
||||
return {
|
||||
preset: ``,
|
||||
processFile: false,
|
||||
note: `Unable to add audio stream in ${langTag}/und with ${channelCount} channels \n`,
|
||||
};
|
||||
}
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest);
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first;
|
||||
} else {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
(stream.tags == undefined ||
|
||||
stream.tags.language == undefined ||
|
||||
stream.tags.language.toLowerCase().includes(langTag)) &&
|
||||
stream.channels == channelCount
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}). Adding! \n`,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
(stream.tags == undefined ||
|
||||
stream.tags.language == undefined ||
|
||||
stream.tags.language.toLowerCase().includes(langTag)) &&
|
||||
stream.channels == highestChannelCount.channels
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasStreamAlready.length > 0) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${highestChannelCount.channels} channels (Highest available) \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track. \n`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeAddAudioStream error: ${err} \n`,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,365 +1,325 @@
|
|||
module.exports = function transcodeKeepOneAudioStream(
|
||||
file,
|
||||
audioEncoder,
|
||||
langTag,
|
||||
channelCount
|
||||
) {
|
||||
// response.preset = library.actions.transcodeKeepOneAudioStream(file, 'aac', 'en', 1).preset
|
||||
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
|
||||
module.exports = function transcodeKeepOneAudioStream(file, audioEncoder, langTag, channelCount) {
|
||||
try {
|
||||
var audioCodec = audioEncoder;
|
||||
langTag = langTag.toLowerCase();
|
||||
|
||||
// response.preset = library.actions.transcodeKeepOneAudioStream(file, 'aac', 'en', 1).preset
|
||||
if (audioEncoder == "dca") {
|
||||
audioCodec = "dts";
|
||||
}
|
||||
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
if (audioEncoder == "libmp3lame") {
|
||||
audioCodec = "mp3";
|
||||
}
|
||||
|
||||
try {
|
||||
var reqLang = langTag;
|
||||
|
||||
var audioCodec = audioEncoder
|
||||
langTag = langTag.toLowerCase()
|
||||
var numberOfAudioStreams = file.ffProbeData.streams.filter(
|
||||
(stream) => stream.codec_type == "audio"
|
||||
).length;
|
||||
|
||||
if (audioEncoder == 'dca') {
|
||||
audioCodec = 'dts'
|
||||
//Step 1: Check if the file already has the required stream codec/langtag/channel count
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) &&
|
||||
stream.channels == channelCount
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
if (audioEncoder == 'libmp3lame') {
|
||||
audioCodec = 'mp3'
|
||||
return false;
|
||||
});
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels. It is the only track! \n`,
|
||||
};
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
var audioStreamToKeep = hasStreamAlready[0].index;
|
||||
var ffmpegCommandInsert = "";
|
||||
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||
try {
|
||||
if (
|
||||
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" &&
|
||||
i !== audioStreamToKeep
|
||||
) {
|
||||
ffmpegCommandInsert += ` -map -0:${i}`;
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
return {
|
||||
preset: `, -map 0 ${ffmpegCommandInsert} -c copy`,
|
||||
processFile: true,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels. It is not the only track, removing others. \n`,
|
||||
};
|
||||
}
|
||||
|
||||
//Step 2: Check if file has streams with specified lang tag
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.tags.language.toLowerCase().includes(langTag)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
var reqLang = langTag
|
||||
return false;
|
||||
});
|
||||
|
||||
var numberOfAudioStreams = file.ffProbeData.streams.filter(stream => stream.codec_type == 'audio').length
|
||||
console.log("streamsWithLangTag:" + streamsWithLangTag);
|
||||
|
||||
if (streamsWithLangTag.length != 0) {
|
||||
return attemptMakeStreamLang(langTag);
|
||||
} else {
|
||||
return attemptMakeStreamUnd("und");
|
||||
}
|
||||
|
||||
//Step 1: Check if the file already has the required stream codec/langtag/channel count
|
||||
function attemptMakeStreamLang(langTag) {
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.tags.language.toLowerCase().includes(langTag)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
return false;
|
||||
});
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) && stream.channels == channelCount) {
|
||||
return true
|
||||
}
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest);
|
||||
|
||||
} catch (err) { }
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first;
|
||||
} else {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
stream.tags.language
|
||||
.toLowerCase()
|
||||
.includes(langTag.toLowerCase()) &&
|
||||
stream.channels == channelCount
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
|
||||
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels. It is the only track! \n`
|
||||
}
|
||||
|
||||
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
|
||||
var audioStreamToKeep = hasStreamAlready[0].index
|
||||
var ffmpegCommandInsert = ''
|
||||
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||
|
||||
try {
|
||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && i !== audioStreamToKeep) {
|
||||
ffmpegCommandInsert += ` -map -0:${i}`
|
||||
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
preset: `, -map 0 ${ffmpegCommandInsert} -c copy`,
|
||||
processFile: true,
|
||||
note: `File already has ${langTag} stream in ${audioEncoder}, ${channelCount} channels. It is not the only track, removing others. \n`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Step 2: Check if file has streams with specified lang tag
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.tags.language.toLowerCase().includes(langTag)) {
|
||||
return true
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
|
||||
})
|
||||
|
||||
console.log("streamsWithLangTag:" + streamsWithLangTag)
|
||||
|
||||
if (streamsWithLangTag.length != 0) {
|
||||
|
||||
return attemptMakeStreamLang(langTag)
|
||||
|
||||
} else {
|
||||
|
||||
return attemptMakeStreamUnd('und')
|
||||
|
||||
}
|
||||
|
||||
|
||||
function attemptMakeStreamLang(langTag) {
|
||||
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.tags.language.toLowerCase().includes(langTag)) {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
|
||||
})
|
||||
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest)
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first
|
||||
} else {
|
||||
return second
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) && stream.channels == channelCount) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `The required stream already exists. It is the only audio stream. \n`
|
||||
}
|
||||
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `The required stream already exists. Removing others. \n`
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}). Adding it and removing others! \n`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
console.log('here3')
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && stream.tags.language.toLowerCase().includes(langTag.toLowerCase()) && stream.channels == highestChannelCount.channels) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `The best ${reqLang} stream already exists. It is the only audio stream. \n`
|
||||
}
|
||||
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `The best ${reqLang} stream already exists. Removing others. \n`
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track, removing others. \n`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function attemptMakeStreamUnd(langTag) {
|
||||
|
||||
console.log('No tracks with specified lang tag exist. Checking undefined tracks.')
|
||||
|
||||
console.log(langTag)
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && (stream.tags == undefined || stream.tags.language == undefined || stream.tags.language.toLowerCase().includes(langTag))) {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
|
||||
})
|
||||
|
||||
if (streamsWithLangTag.length == 0) {
|
||||
return {
|
||||
preset: ``,
|
||||
processFile: false,
|
||||
note: `Unable to add audio stream in ${langTag}/und with ${channelCount} channels \n`
|
||||
}
|
||||
}
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest)
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first
|
||||
} else {
|
||||
return second
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && (stream.tags == undefined || stream.tags.language == undefined || stream.tags.language.toLowerCase().includes(langTag)) && stream.channels == channelCount) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `No ${reqLang} streams. The required und stream already exists. It is the only audio stream. \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The required und stream already exists. Removing others. \n`
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}).Adding it and removing others! \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter(stream => {
|
||||
|
||||
try {
|
||||
if (stream.codec_type == 'audio' && stream.codec_name === audioCodec && (stream.tags == undefined || stream.tags.language == undefined || stream.tags.language.toLowerCase().includes(langTag)) && stream.channels == highestChannelCount.channels) {
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (err) { }
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `No ${reqLang} streams. The best und stream already exists. It is the only audio stream. \n`
|
||||
}
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The best stream already exists. Removing others. \n`
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track, removing others. \n`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeKeepOneAudioStream error: ${err} \n`
|
||||
note: `The required stream already exists. It is the only audio stream. \n`,
|
||||
};
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `The required stream already exists. Removing others. \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}). Adding it and removing others! \n`,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
console.log("here3");
|
||||
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
stream.tags.language
|
||||
.toLowerCase()
|
||||
.includes(langTag.toLowerCase()) &&
|
||||
stream.channels == highestChannelCount.channels
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `The best ${reqLang} stream already exists. It is the only audio stream. \n`,
|
||||
};
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `The best ${reqLang} stream already exists. Removing others. \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track, removing others. \n`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attemptMakeStreamUnd(langTag) {
|
||||
console.log(
|
||||
"No tracks with specified lang tag exist. Checking undefined tracks."
|
||||
);
|
||||
|
||||
console.log(langTag);
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
(stream.tags == undefined ||
|
||||
stream.tags.language == undefined ||
|
||||
stream.tags.language.toLowerCase().includes(langTag))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (streamsWithLangTag.length == 0) {
|
||||
return {
|
||||
preset: ``,
|
||||
processFile: false,
|
||||
note: `Unable to add audio stream in ${langTag}/und with ${channelCount} channels \n`,
|
||||
};
|
||||
}
|
||||
|
||||
var highestChannelCount = streamsWithLangTag.reduce(getHighest);
|
||||
|
||||
function getHighest(first, second) {
|
||||
if (first.channels > second.channels && first) {
|
||||
return first;
|
||||
} else {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
||||
if (parseInt(highestChannelCount.channels) >= parseInt(channelCount)) {
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
(stream.tags == undefined ||
|
||||
stream.tags.language == undefined ||
|
||||
stream.tags.language.toLowerCase().includes(langTag)) &&
|
||||
stream.channels == channelCount
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `No ${reqLang} streams. The required und stream already exists. It is the only audio stream. \n`,
|
||||
};
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The required und stream already exists. Removing others. \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${channelCount}`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The required channel count ${channelCount} is lower than the highest available channel count (${highestChannelCount.channels}).Adding it and removing others! \n`,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
var hasStreamAlready = file.ffProbeData.streams.filter((stream) => {
|
||||
try {
|
||||
if (
|
||||
stream.codec_type == "audio" &&
|
||||
stream.codec_name === audioCodec &&
|
||||
(stream.tags == undefined ||
|
||||
stream.tags.language == undefined ||
|
||||
stream.tags.language.toLowerCase().includes(langTag)) &&
|
||||
stream.channels == highestChannelCount.channels
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (numberOfAudioStreams == 1 && hasStreamAlready.length == 1) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `No ${reqLang} streams. The best und stream already exists. It is the only audio stream. \n`,
|
||||
};
|
||||
} else if (hasStreamAlready.length >= 1) {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${hasStreamAlready[0].index} -map 0:s? -map 0:d? -c copy`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The best stream already exists. Removing others. \n`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:${highestChannelCount.index} -map 0:s? -map 0:d? -c copy -c:a:0 ${audioEncoder} -ac ${highestChannelCount.channels}`,
|
||||
processFile: true,
|
||||
note: `No ${reqLang} streams. The required channel count (${channelCount}) is higher than the highest channel available in specified lang tag (${highestChannelCount.channels}). Adding lower channel track, removing others. \n`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeKeepOneAudioStream error: ${err} \n`,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,77 +1,59 @@
|
|||
|
||||
|
||||
module.exports = function transcodeStandardiseAudioCodecs(file, audioEncoder) {
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
|
||||
try {
|
||||
var audioIdx = -1;
|
||||
var hasNonSpecifiedAudioCodecStream = false;
|
||||
var ffmpegCommandInsert = "";
|
||||
var audioCodec = audioEncoder;
|
||||
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
|
||||
try {
|
||||
|
||||
var audioIdx = -1
|
||||
var hasNonSpecifiedAudioCodecStream = false
|
||||
var ffmpegCommandInsert = ''
|
||||
var audioCodec = audioEncoder
|
||||
|
||||
if (audioEncoder == 'dca') {
|
||||
audioCodec = 'dts'
|
||||
}
|
||||
|
||||
if (audioEncoder == 'libmp3lame') {
|
||||
audioCodec = 'mp3'
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||
|
||||
|
||||
try {
|
||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
|
||||
audioIdx++
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
|
||||
try {
|
||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].codec_name != audioCodec) {
|
||||
|
||||
ffmpegCommandInsert += ` -c:a:${audioIdx} ${audioEncoder}`
|
||||
hasNonSpecifiedAudioCodecStream = true
|
||||
|
||||
}
|
||||
} catch (err) { }
|
||||
}
|
||||
|
||||
|
||||
if (hasNonSpecifiedAudioCodecStream === true) {
|
||||
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:a -map 0:s? -map 0:d? -c copy ${ffmpegCommandInsert}`,
|
||||
processFile: true,
|
||||
note: `File has audio streams which aren't in ${audioCodec} \n`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `File does not have any audio streams which aren't in ${audioCodec} \n`
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeStandardiseAudioCodecs error: ${err} \n`
|
||||
}
|
||||
|
||||
if (audioEncoder == "dca") {
|
||||
audioCodec = "dts";
|
||||
}
|
||||
}
|
||||
|
||||
if (audioEncoder == "libmp3lame") {
|
||||
audioCodec = "mp3";
|
||||
}
|
||||
|
||||
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||
try {
|
||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
|
||||
audioIdx++;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
if (
|
||||
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" &&
|
||||
file.ffProbeData.streams[i].codec_name != audioCodec
|
||||
) {
|
||||
ffmpegCommandInsert += ` -c:a:${audioIdx} ${audioEncoder}`;
|
||||
hasNonSpecifiedAudioCodecStream = true;
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
if (hasNonSpecifiedAudioCodecStream === true) {
|
||||
return {
|
||||
preset: `,-map 0:v -map 0:a -map 0:s? -map 0:d? -c copy ${ffmpegCommandInsert}`,
|
||||
processFile: true,
|
||||
note: `File has audio streams which aren't in ${audioCodec} \n`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `File does not have any audio streams which aren't in ${audioCodec} \n`,
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
preset: "",
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeStandardiseAudioCodecs error: ${err} \n`,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,40 +1,29 @@
|
|||
|
||||
|
||||
function filterByAge(file, ageCutOff_Seconds) {
|
||||
try {
|
||||
var timeNow = new Date();
|
||||
var dateCreated = new Date(file.statSync.birthtime);
|
||||
var fileAge = Math.round((timeNow - dateCreated) / 1000);
|
||||
|
||||
try {
|
||||
|
||||
var timeNow = new Date()
|
||||
var dateCreated = new Date(file.statSync.birthtime)
|
||||
var fileAge = Math.round((timeNow - dateCreated) / 1000)
|
||||
|
||||
|
||||
if (fileAge > ageCutOff_Seconds) {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File creation date is older than specified requirement. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File creation date is within specified requirement. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByAge error: ${err} \n`
|
||||
}
|
||||
return response
|
||||
if (fileAge > ageCutOff_Seconds) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File creation date is older than specified requirement. \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File creation date is within specified requirement. \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByAge error: ${err} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = filterByAge
|
||||
module.exports = filterByAge;
|
||||
|
|
|
|||
|
|
@ -1,82 +1,60 @@
|
|||
|
||||
|
||||
function filterByCodec(file, mode, codecs) {
|
||||
try {
|
||||
// console.log(file,mode,codecs)
|
||||
|
||||
var allCodecs = file.ffProbeData.streams.map((row) => row.codec_name);
|
||||
|
||||
try {
|
||||
var included = false;
|
||||
|
||||
// console.log(file,mode,codecs)
|
||||
|
||||
var allCodecs = file.ffProbeData.streams.map(row => row.codec_name)
|
||||
|
||||
var included = false
|
||||
|
||||
for (var i = 0; i < allCodecs.length; i++) {
|
||||
|
||||
if (codecs.toLowerCase().includes(allCodecs[i])) {
|
||||
included = true
|
||||
}
|
||||
}
|
||||
|
||||
if (mode === 'include') {
|
||||
|
||||
if (included) {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑Codec included \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒Codec excluded \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
} else if (mode === 'exclude') {
|
||||
|
||||
if (included) {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒Codec excluded \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑Codec not excluded \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByCodec error: ${err} \n`
|
||||
}
|
||||
return response
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
console.log(err)
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `Filter error hello! ${err}\n`
|
||||
}
|
||||
return response
|
||||
for (var i = 0; i < allCodecs.length; i++) {
|
||||
if (codecs.toLowerCase().includes(allCodecs[i])) {
|
||||
included = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode === "include") {
|
||||
if (included) {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑Codec included \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒Codec excluded \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
} else if (mode === "exclude") {
|
||||
if (included) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒Codec excluded \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑Codec not excluded \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByCodec error: ${err} \n`,
|
||||
};
|
||||
return response;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `Filter error hello! ${err}\n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = filterByCodec
|
||||
module.exports = filterByCodec;
|
||||
|
|
|
|||
|
|
@ -1,34 +1,25 @@
|
|||
|
||||
|
||||
function filterByMedium(file, medium) {
|
||||
|
||||
try {
|
||||
|
||||
if (file.fileMedium !== medium) {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File is not ${medium} \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File is ${medium} \n`
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByMedium error: ${err} \n`
|
||||
}
|
||||
return response
|
||||
try {
|
||||
if (file.fileMedium !== medium) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File is not ${medium} \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File is ${medium} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByMedium error: ${err} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = filterByMedium
|
||||
module.exports = filterByMedium;
|
||||
|
|
|
|||
|
|
@ -1,58 +1,45 @@
|
|||
|
||||
|
||||
function filterByResolution(file, mode, resolution) {
|
||||
|
||||
try {
|
||||
|
||||
if (mode === 'exclude') {
|
||||
|
||||
if (resolution.toLowerCase().includes(file.video_resolution.toLowerCase())) {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File is in excluded resolution. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File is not in excluded resolution. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
} else if (mode === 'include') {
|
||||
|
||||
if (resolution.toLowerCase().includes(file.video_resolution.toLowerCase())) {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File is in included resolution. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File is not in included resolution. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
try {
|
||||
if (mode === "exclude") {
|
||||
if (
|
||||
resolution.toLowerCase().includes(file.video_resolution.toLowerCase())
|
||||
) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByResolution error: ${err} \n`
|
||||
}
|
||||
return response
|
||||
outcome: false,
|
||||
note: `☒File is in excluded resolution. \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File is not in excluded resolution. \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
} else if (mode === "include") {
|
||||
if (
|
||||
resolution.toLowerCase().includes(file.video_resolution.toLowerCase())
|
||||
) {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File is in included resolution. \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File is not in included resolution. \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterByResolution error: ${err} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = filterByResolution
|
||||
module.exports = filterByResolution;
|
||||
|
|
|
|||
|
|
@ -1,34 +1,28 @@
|
|||
|
||||
|
||||
function filterBySize(file, lowerBound, upperBound) {
|
||||
|
||||
try {
|
||||
|
||||
if (file.file_size / 1000 >= lowerBound && file.file_size / 1000 <= upperBound) {
|
||||
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File size is within filter limits. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
} else {
|
||||
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File size is not within filter limits. \n`
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterBySize error: ${err} \n`
|
||||
}
|
||||
return response
|
||||
try {
|
||||
if (
|
||||
file.file_size / 1000 >= lowerBound &&
|
||||
file.file_size / 1000 <= upperBound
|
||||
) {
|
||||
var response = {
|
||||
outcome: true,
|
||||
note: `☑File size is within filter limits. \n`,
|
||||
};
|
||||
return response;
|
||||
} else {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `☒File size is not within filter limits. \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
} catch (err) {
|
||||
var response = {
|
||||
outcome: false,
|
||||
note: `library.filters.filterBySize error: ${err} \n`,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = filterBySize
|
||||
module.exports = filterBySize;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue