mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
new function + tidy
This commit is contained in:
parent
d60e0c17ad
commit
32b8d73e0f
5 changed files with 228 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
|||
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/')
|
||||
if (fs.existsSync(path.join(process.cwd() , "/npm"))) {
|
||||
var rootModules = path.join(process.cwd() , '/npm/node_modules/')
|
||||
} else{
|
||||
var rootModules = ''
|
||||
}
|
||||
|
|
@ -10,4 +10,4 @@ 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')
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
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/')
|
||||
if (fs.existsSync(path.join(process.cwd() , "/npm"))) {
|
||||
var rootModules = path.join(process.cwd() , '/npm/node_modules/')
|
||||
} else{
|
||||
var rootModules = ''
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
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/')
|
||||
if (fs.existsSync(path.join(process.cwd() , "/npm"))) {
|
||||
var rootModules = path.join(process.cwd() , '/npm/node_modules/')
|
||||
} else{
|
||||
var rootModules = ''
|
||||
}
|
||||
|
|
|
|||
212
methods/library/actions/transcodeAddAudioStream.js
Normal file
212
methods/library/actions/transcodeAddAudioStream.js
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
|
||||
|
||||
module.exports = function transcodeAddAudioStream(file, audioEncoder, langTag, channelCount) {
|
||||
|
||||
// response.preset = library.actions.transcodeAddAudioStream(file, 'aac', 'en', 1).preset
|
||||
|
||||
//Function required responses
|
||||
// preset
|
||||
// processFile
|
||||
// note
|
||||
|
||||
try {
|
||||
|
||||
var audioCodec = audioEncoder
|
||||
langTag = langTag.toLowerCase()
|
||||
|
||||
if (audioEncoder == 'dca') {
|
||||
audioCodec = 'dts'
|
||||
}
|
||||
|
||||
if (audioEncoder == 'libmp3lame') {
|
||||
audioCodec = 'mp3'
|
||||
}
|
||||
|
||||
|
||||
|
||||
//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) { }
|
||||
|
||||
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 => {
|
||||
|
||||
// console.log(stream)
|
||||
|
||||
console.log(stream.tags.language)
|
||||
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 attemptMakeStream(langTag)
|
||||
|
||||
} else {
|
||||
|
||||
return attemptMakeStream('und')
|
||||
|
||||
}
|
||||
|
||||
|
||||
function attemptMakeStream(langTag) {
|
||||
|
||||
console.log(langTag)
|
||||
|
||||
var streamsWithLangTag = file.ffProbeData.streams.filter(stream => {
|
||||
try {
|
||||
console.log(langTag)
|
||||
console.log(stream.tags.language.toLowerCase())
|
||||
console.log(stream.tags.language.toLowerCase().includes(langTag))
|
||||
if (stream.codec_type == 'audio' && 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.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`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
return {
|
||||
preset: '',
|
||||
processFile: false,
|
||||
note: `library.actions.transcodeAddAudioStream error: ${err} \n`
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -3,26 +3,27 @@
|
|||
module.exports = function transcodeStandardiseAudioCodecs(file, audioEncoder) {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
var audioIdx = -1
|
||||
var hasNonSpecifiedAudioCodecStream = false
|
||||
var ffmpegCommandInsert = ''
|
||||
|
||||
|
||||
//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++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue