diff --git a/Community/Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle.js b/Community/Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle.js index 4303716..793fb7b 100644 --- a/Community/Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle.js +++ b/Community/Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle.js @@ -7,9 +7,9 @@ function details() { id: "Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle", Name: "Drawmonster MP4 Stereo AAC, No Subs, No title meta data ", Type: "Video", - Description: `This plugin removes subs, metadata (if a title exists) and adds a stereo 192kbit AAC track if an AAC track (any) doesn't exist. The output container is mp4. \n\n + Description: `This plugin removes subs, metadata (if a title exists) and adds a stereo 192kbit AAC track if an AAC track (English or any) doesn't exist. The output container is mp4. \n\n `, - Version: "1.03", + Version: "1.04", Link: "https://github.com/HaveAGitGat/Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle" } @@ -50,7 +50,19 @@ function plugin(file) { } else { - var jsonString = JSON.stringify(file) + + var hasPreferredLangTrack = false + var hasPreferredLangInRequiredCodecs = false + var hasAnyInRequiredCodecs = false + + var audioIdx = -1 + var engTrackIdx = -1 + + var requiredAudioCodecs = "aac" + var preferredLangTrack = "eng" + var preferredCodec = "aac" + + var hasSubs = false @@ -66,32 +78,77 @@ function plugin(file) { } } catch (err) { } - } - + try { + if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { + audioIdx++ + } + } catch (err) { } - /// + try { + if (requiredAudioCodecs.includes(file.ffProbeData.streams[i].codec_name)) { + hasAnyInRequiredCodecs = true + + } + } catch (err) { } + + + try { + if ((requiredAudioCodecs.includes(file.ffProbeData.streams[i].codec_name)) && file.ffProbeData.streams[i].tags.language.toLowerCase().includes(preferredLangTrack)) { + hasPreferredLangInRequiredCodecs = true + + } + } catch (err) { } + + try { + if (file.ffProbeData.streams[i].tags.language.toLowerCase().includes(preferredLangTrack) && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") { + hasPreferredLangTrack = true + engTrackIdx = audioIdx + + } + } catch (err) { } - if((file.meta.Title != "undefined") && !jsonString.includes("aac") && hasSubs){ - response.infoLog += "☒File has title metadata and no aac and subs \n" - response.preset = ',-map_metadata -1 -c:v copy -c:a copy' - response.reQueueAfter = true; - response.processFile = true; - return response } - if(!jsonString.includes("aac") && hasSubs){ + if (hasPreferredLangInRequiredCodecs) { + + response.infoLog += `☑File already has ${preferredLangTrack} language track in ${requiredAudioCodecs}! \n` + + } else if (hasPreferredLangTrack) { - response.infoLog += "☒File has no aac track and has subs \n" - response.preset = ',-sn -map 0:v -map 0:a:0 -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 aac -b:a:0 192k -ac 2' - response.reQueueAfter = true; response.processFile = true; + response.preset = `,-map 0:v -map 0:a:${engTrackIdx} -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${preferredCodec} -b:a:0 192k -ac 2` + response.container = '.mp4' + response.handBrakeMode = false + response.FFmpegMode = true + response.reQueueAfter = true; + response.infoLog += `☒File has ${preferredLangTrack} language track but not in ${requiredAudioCodecs}! \n` return response - } + } else if (!hasAnyInRequiredCodecs) { + + if (audioIdx == -1) { + response.infoLog += `☒File does not have any audio streams. Can't create ${preferredCodec} track. \n` + + } else { + + response.processFile = true; + response.preset = `,-map 0:v -map 0:a:0 -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 ${preferredCodec} -b:a:0 192k -ac 2` + response.container = '.mp4' + response.handBrakeMode = false + response.FFmpegMode = true + response.reQueueAfter = true; + response.infoLog += `☒File has no language track in ${requiredAudioCodecs}. No ${preferredLangTrack} track marked so transcoding audio track 1 into ${preferredCodec}! \n` + return response + + } + } + + + if(file.meta.Title != "undefined" && hasSubs){ @@ -116,17 +173,7 @@ function plugin(file) { response.infoLog += "☑File has no title metadata \n" } - if(!jsonString.includes("aac")){ - - response.infoLog += "☒File has no aac track \n" - response.preset = ',-map 0:v -map 0:a:0 -map 0:a -map 0:s? -map 0:d? -c copy -c:a:0 aac -b:a:0 192k -ac 2' - response.reQueueAfter = true; - response.processFile = true; - return response - }else{ - response.infoLog += "☑File has aac track \n" - } if(hasSubs){