Merge pull request 'BatchMergeSubtitleswithMKVMerge' (#125) from BatchMergeSubtitleswithMKVMerge into master

Reviewed-on: #125
This commit is contained in:
MilesTEG 2021-10-31 11:09:19 +01:00
commit 96c8de2a0e

View File

@ -33,7 +33,7 @@ $sourceDirectory_2 = "PATH_TO_SOURCE_2"
$destinationDirectory = "PATH_TO_DESTINATION"
# Rename output file with this settings :
$chain_to_search = '(.*).S(\d*)E(\d*).(.*)H.264(.*)'
$chain_to_search = '(.*) - S(\d*)E(\d*) - (.*)x264(.*)'
$chain__to_replace = '$1 - S$2E$3 - $4x265-10bits$5--Reencoded'
# The filenames must be like : blabla.S00E00.blabla.H.264.blabla
# They will be renamed to : blabla - S00E00 - blabla.x265-10bits.blabla--Reencoded
@ -42,7 +42,7 @@ $chain__to_replace = '$1 - S$2E$3 - $4x265-10bits$5--Reencoded'
# Is there an external subtitle ? Set the number of .SRT (0 - 2)
# It's exclusive, no internal SUB will be proceed..
$NB_External_SUB = 0
$NB_External_SUB = 2
# Extension without the .
$MkvExtension = "mkv"
@ -57,10 +57,10 @@ $merged_SUFFIX_name = "False"
# ================== AUDIO ==================
# Track 1 = Audio n°1
# Name and language of Audio Track n°1
$AudioTrackName_1 = "1:English - DDP 5.1"
$AudioTrackName_1 = "1:English - DTS-HD MA"
$AudioLang_1 = "1:en"
$AudioTrack_1_default = "1:yes"
$file_1_options = "--no-video"
#$file_1_options = "--no-video"
@ -79,7 +79,7 @@ if ( $NB_External_SUB -ne 0 ) {
$ExtSubTrackName_1 = "0:English - SRT"
$ExtSubTrackLang_1 = "0:eng"
$ExtSubTrack_1_default = "0:yes"
$Extsub_charset_1 = "0:UTF-8"
$ExtSub_charset_1 = "0:UTF-8"
####
#### FILE 4 - SRT - Keeping all but the video (audio + chapters tags)
# ================== SUBTITLES ==================
@ -88,7 +88,7 @@ if ( $NB_External_SUB -ne 0 ) {
$ExtSubTrackName_2 = "0:Français - SRT"
$ExtSubTrackLang_2 = "0:fr"
$ExtSubTrack_2_default = "0:no"
$Extsub_charset_2 = "0:UTF-8"
$ExtSub_charset_2 = "0:UTF-8"
####
# ================== OTHER SETTINGS ==================
# Define track order
@ -96,7 +96,7 @@ if ( $NB_External_SUB -ne 0 ) {
$track_order = "1:0,0:1,2:0"
}
elseif ( $NB_External_SUB -eq 2 ) {
$track_order = "1:0,0:1,2:0;3,0"
$track_order = "1:0,0:1,2:0,3:0"
}
}
else {
@ -192,7 +192,7 @@ if ($Count_1 -eq $Count_2) {
# Exit
# }
# #########################
$compteur = 1
# for ($i = $filename_ep_start; $i -lt $filename_ep_final+1; $i++) {
Foreach ($MKV_1 in $MKV_1_List) {
@ -212,10 +212,10 @@ Foreach ($MKV_1 in $MKV_1_List) {
$MKV_2 = $sourceDirectory_2 + "\" + $MKV_2_name + ".$MkvExtension"
if ( $NB_External_SUB -ne 0 ) {
$SRT_1_Name = $MKV_1_name
$SRT_1 = $sourceDirectory_1 + "\" + $SRT_1_name + ".$SubExtension_1"
$SRT_1_Name = $MKV_1_name + ".$SubExtension_1"
$SRT_1 = $sourceDirectory_1 + "\" + $SRT_1_name
$SRT_2_Name = $MKV_1_name + ".$SubExtension_2"
$SRT_2 = $sourceDirectory_1 + "\" + $SRT_2_name + ".$SubExtension_2"
$SRT_2 = $sourceDirectory_1 + "\" + $SRT_2_name
}
#########################################################
@ -282,7 +282,7 @@ Foreach ($MKV_1 in $MKV_1_List) {
# Title for the video track and for the destination file
#$VideoTrackName = $MKV_1_name -replace '(.*).S(\d*)E(\d*).(.*)H.264(.*)', '$1 - S$2E$3 - $4x265-10bits$5--Reencoded'
$VideoTrackName_BIS = $MKV_1_name -replace $chain_to_search, $chain__to_replace
$VideoTrackName = $MKV_1_name -replace $chain_to_search, $chain__to_replace
#Set Output File Name
#$Output = $Name + '___MERGED' + '.mkv'
@ -295,7 +295,9 @@ Foreach ($MKV_1 in $MKV_1_List) {
write-host "Should be set to True or False.`nScript is exiting now..." -foreground "white"
Exit
}
# write-host "Output file will be :" -foreground "white"
# write-host "$Output"
# write-host "--"
#Execute
# Keep Audio/Subtitles/tags from MKV_1 + Only video from MKV_2
@ -310,7 +312,10 @@ Foreach ($MKV_1 in $MKV_1_List) {
--language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes"
"$MKV_2"
#>
Write-Host "" -ForegroundColor "black" -BackgroundColor "white"
Write-Host "Traitement du fichier n° $compteur / $Count_1..." -ForegroundColor "black" -BackgroundColor "white"
Write-Host "" -ForegroundColor "black" -BackgroundColor "white"
if ( $NB_External_SUB -eq 1 ) {
<# Command to edit
& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" -o "$Output"
@ -336,7 +341,7 @@ Foreach ($MKV_1 in $MKV_1_List) {
--language "$AudioLang_2" --track-name "$AudioTrackName_2" --default-track "$AudioTrack_2_default"
"$MKV_1"
-no-audio --no-track-tags --no-global-tags
--no-audio --no-track-tags --no-global-tags
--language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes"
"$MKV_2"
--sub-charset "$Extsub_charset_1" --language "$ExtSubTrackLang_1" --track-name "$ExtSubTrackName_1" --default-track "$ExtSubTrack_1_default"
@ -345,7 +350,12 @@ Foreach ($MKV_1 in $MKV_1_List) {
"$SRT_2"
#>
& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" -o "$Output" --no-video --no-subtitles --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" --language "$AudioLang_2" --track-name "$AudioTrackName_2" --default-track "$AudioTrack_2_default" "$MKV_1" --no-audio --no-track-tags --no-global-tags --language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes" "$MKV_2" --sub-charset "$Extsub_charset_1" --language "$ExtSubTrackLang_1" --track-name "$ExtSubTrackName_1" --default-track "$ExtSubTrack_1_default" "$SRT_1" --sub-charset "$Extsub_charset_2" --language "$ExtSubTrackLang_2" --track-name "$ExtSubTrackName_2" --default-track "$ExtSubTrack_2_default" "$SRT_2"
# Write-Host "Commande qui va être lancée : " -foreground "green"
# Write-Host "MKVMerge --title "$VideoTrackName" --track-order "$track_order" -o "$Output" --no-video --no-subtitles --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" --language "$AudioLang_2" --track-name "$AudioTrackName_2" --default-track "$AudioTrack_2_default" "$MKV_1" --no-audio --no-track-tags --no-global-tags --language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes" "$MKV_2" --sub-charset "$ExtSub_charset_1" --language "$ExtSubTrackLang_1" --track-name "$ExtSubTrackName_1" --default-track "$ExtSubTrack_1_default" "$SRT_1"" -foreground "green"
& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" -o "$Output" --no-video --no-subtitles --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" "$MKV_1" --no-audio --no-track-tags --no-global-tags --language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes" "$MKV_2" --sub-charset "$ExtSub_charset_1" --language "$ExtSubTrackLang_1" --track-name "$ExtSubTrackName_1" --default-track "$ExtSubTrack_1_default" "$SRT_1" --sub-charset "$ExtSub_charset_2" --language "$ExtSubTrackLang_2" --track-name "$ExtSubTrackName_2" --default-track "$ExtSubTrack_2_default" "$SRT_2"
}
else {
@ -360,7 +370,10 @@ Foreach ($MKV_1 in $MKV_1_List) {
}
Write-Host "" -ForegroundColor "black" -BackgroundColor "white"
Write-Host "Fin du traitement du fichier n° $compteur / $Count_1." -ForegroundColor "black" -BackgroundColor "white"
Write-Host "" -ForegroundColor "black" -BackgroundColor "white"
If (Test-Path $Output) {
#Clean Up
@ -387,4 +400,5 @@ Foreach ($MKV_1 in $MKV_1_List) {
write-host "File NON-EXISTANT - $Output" -foreground "red"
"File NON-EXISTANT - $Output" | Out-File "$destinationDirectory\Errors.txt" -Append
}
$compteur++
}