Merge pull request 'MAJ du script de fusion avec un peu plus d'automatisme.' (#123) from BatchMergeSubtitleswithMKVMerge into master
Reviewed-on: #123
This commit is contained in:
commit
35a34a0803
@ -28,9 +28,12 @@
|
||||
$MKVMerge = 'H:\z_MKV\mkvtoolnix\mkvmerge.exe'
|
||||
|
||||
#Set Source and Target directories (Don't put an \ at the end)
|
||||
$sourceDirectory_1 = "D:\DOSSIER_SOURCE-1"
|
||||
$sourceDirectory_2 = "D:\DOSSIER_SOURCE-2"
|
||||
$destinationDirectory = "F:\TEMP\"
|
||||
$sourceDirectory_1 = "PATH_TO_SOURCE_1"
|
||||
$sourceDirectory_2 = "PATH_TO_SOURCE_2"
|
||||
$destinationDirectory = "PATH_TO_DESTINATION"
|
||||
|
||||
# Extension without the .
|
||||
$MkvExtension = "mkv"
|
||||
|
||||
#If source and destination are the same folder, set this to True, Otherwise let it to "False"
|
||||
$merged_SUFFIX_name = "False"
|
||||
@ -41,37 +44,38 @@ $merged_SUFFIX_name = "False"
|
||||
# ================== AUDIO ==================
|
||||
# Track 1 = Audio n°1
|
||||
# Name and language of Audio Track n°1
|
||||
$AudioTrackName_1 = "1:Français - AC3 5.1 640kb/s"
|
||||
$AudioLang_1 = "1:fr"
|
||||
$AudioTrackName_1 = "1:English - DDP 5.1"
|
||||
$AudioLang_1 = "1:en"
|
||||
$AudioTrack_1_default = "1:yes"
|
||||
$file_1_options = "--no-video"
|
||||
|
||||
# ================== SUBTITLES ==================
|
||||
# Track 3 = Sub n°1 to keep
|
||||
# Track 2 = Sub n°1 to keep
|
||||
# Name and language of Subtitle Track n°1 + Sync Value
|
||||
$SubTrackName_1 = "2:Français Forcés - SRT"
|
||||
$SubTrackLang_1 = "2:fr"
|
||||
$SubTrackName_1 = "2:English SDH - SRT"
|
||||
$SubTrackLang_1 = "2:en"
|
||||
$SubTrack_1_default = "2:yes"
|
||||
$sub_charset_1 = "2:UTF-8"
|
||||
|
||||
# Track 3 = Sub n°2 to keep
|
||||
# Name and language of Subtitle Track n°1 + Sync Value
|
||||
# $SubTrackName_1 = "3:English SDH - SRT"
|
||||
# $SubTrackLang_1 = "3:eng"
|
||||
# $SubTrack_1_default = "3:yes"
|
||||
# $sub_charset_1 = "3:UTF-8"
|
||||
####
|
||||
|
||||
##########################################
|
||||
#### FILE 2 - MKV - Keeping only the video
|
||||
$file_2_options = "--no-audio --no-track-tags --no-global-tags"
|
||||
|
||||
|
||||
# ================== OTHER SETTINGS ==================
|
||||
# Define track order
|
||||
$track_order = "1:0,0:1,0:2"
|
||||
# Define subtitles track to keep
|
||||
$subtitle_tracks = "2"
|
||||
|
||||
# Files name, without .mkv :
|
||||
# format = filename_1_part_1 + S + filename_season + E + i_counter + filename_1_part_2 + .mkv
|
||||
# format = filename_2_part_1 + S + filename_season + E + i_counter + filename_2_part_2 + .mkv
|
||||
$filename_1_part_1 = "Ma série (20xx) - "
|
||||
$filename_1_part_2 = " - 1080p-h264"
|
||||
# Final name 1 = Ma série (20xx) - S01E01 - 1080p-h264
|
||||
|
||||
$filename_2_part_1 = "Ma série (20xx) - "
|
||||
$filename_2_part_2 = " - 1080p.x265"
|
||||
# Final name 2 = Ma série (20xx) - S01E01 - 1080p.x265
|
||||
|
||||
$filename_season = "02"
|
||||
$filename_ep_total = "10"
|
||||
##==============================================================================================
|
||||
##==============================================================================================
|
||||
|
||||
@ -84,6 +88,15 @@ If(!(test-path $Path_Folder_NotMerged_2)) {
|
||||
#Move-Item -Path $Path_Folder_NotMerged_2 -Destination "$sourceDirectory\Not-Merged--backup" -Verbose
|
||||
#Move-Item -Path $Path_Folder_NotMerged_2 -Destination "$sourceDirectory\Not-Merged--backup" -Verbose
|
||||
}
|
||||
# Testing if the Not-Merged folder already exists : if yes, it will be renamed, else it will be created.
|
||||
$Path_Folder_NotMerged_1 = $sourceDirectory_1 + "\Not-Merged"
|
||||
If(!(test-path $Path_Folder_NotMerged_1)) {
|
||||
New-Item -ItemType "Directory" -Force -Path $Path_Folder_NotMerged_1 -Verbose
|
||||
} else {
|
||||
# Don't know what's the best... TO BE IMPROVED
|
||||
#Move-Item -Path $Path_Folder_NotMerged_2 -Destination "$sourceDirectory\Not-Merged--backup" -Verbose
|
||||
#Move-Item -Path $Path_Folder_NotMerged_2 -Destination "$sourceDirectory\Not-Merged--backup" -Verbose
|
||||
}
|
||||
|
||||
|
||||
#Process
|
||||
@ -95,6 +108,8 @@ $MKV_2_List = Get-ChildItem $sourceDirectory_2 -Filter "*.mkv" | ForEach-Object
|
||||
$Count_2 = $MKV_2_List.count
|
||||
Write-Host "$Count_2 MKV's to be processed in $sourceDirectory_2."
|
||||
|
||||
|
||||
|
||||
if ($Count_1 -eq $Count_2) {
|
||||
Write-Host "There is the same number of MKV in the two sources folders. Let's continue."
|
||||
} else {
|
||||
@ -102,31 +117,76 @@ if ($Count_1 -eq $Count_2) {
|
||||
Exit
|
||||
}
|
||||
|
||||
if (!($Count_1 -eq $filename_ep_total)) {
|
||||
Write-Host "The number of epidoes set in the script isn't the same as the number of files in the folders... EXITING NOW !" -foreground "red"
|
||||
Exit
|
||||
}
|
||||
# if (!($Count_1 -eq ($filename_ep_final - $filename_ep_start + 1))) {
|
||||
# Write-Host "The number of episodes set in the script isn't the same as the number of files in the folders... EXITING NOW !" -foreground "red"
|
||||
# Exit
|
||||
# }
|
||||
|
||||
for ($i = 1; $i -lt $Count_1+1; $i++) {
|
||||
# for ($i = $filename_ep_start; $i -lt $filename_ep_final+1; $i++) {
|
||||
Foreach ($MKV_1 in $MKV_1_List) {
|
||||
|
||||
# Genreating File Name
|
||||
# format = filename_1_part_1 + S + filename_season + E + i_counter + filename_1_part_2 + .mkv
|
||||
# format = filename_2_part_1 + S + filename_season + E + i_counter + filename_2_part_2 + .mkv
|
||||
# Final name 1 = Le Bureau des Légendes (2015) - S01E01 - 1080p-h264
|
||||
# Final name 2 = Le Bureau des Légendes (2015) - S01E01 - 1080p.BDRip.x265.Aac.NoTag
|
||||
$FormatName_1 = (Get-Item $MKV_1).Basename
|
||||
$MKV_1_name = $FormatName_1.ToString()
|
||||
|
||||
if ($i -lt 10 ) { # i<10
|
||||
$MKV_1_name = $filename_1_part_1 + "S" + $filename_season + "E0" + $i + $filename_1_part_2
|
||||
$MKV_2_name = $filename_2_part_1 + "S" + $filename_season + "E0" + $i + $filename_2_part_2
|
||||
} else { # i=10
|
||||
$MKV_1_name = $filename_1_part_1 + "S" + $filename_season + "E" + $i + $filename_1_part_2
|
||||
$MKV_2_name = $filename_2_part_1 + "S" + $filename_season + "E" + $i + $filename_2_part_2
|
||||
}
|
||||
$MKV_1 = $sourceDirectory_1 + "\" + $MKV_1_name + ".mkv"
|
||||
$MKV_2 = $sourceDirectory_2 + "\" + $MKV_2_name + ".mkv"
|
||||
$MKV_2_file = get-ChildItem $sourceDirectory_2 -recurse | where {$_.name -like "*$MKV_1_name*"} | select name
|
||||
|
||||
# Title for the video track
|
||||
$VideoTrackName = $MKV_2_name
|
||||
# Faire test si count = 1 -> ok Sinon soucis !
|
||||
|
||||
$FormatName_2 = $MKV_2_file.Name.ToString()
|
||||
$MKV_2_name = $FormatName_2.Substring(0,$FormatName_2.Length-($MkvExtension.Length+1))
|
||||
$MKV_2 = $sourceDirectory_2 + "\" + $MKV_2_name + ".$MkvExtension"
|
||||
|
||||
#########################################################
|
||||
# Exceptions for some files with other than 2 SRT inside
|
||||
# switch ($MKV_1_name)
|
||||
# {
|
||||
# "Name of a media with not the same subtitles structure"
|
||||
# {
|
||||
# # Only One subtitle track : n°2
|
||||
# $SubTrackName_1 = "2:English SDH - SRT"
|
||||
# $SubTrackLang_1 = "2:en"
|
||||
# $SubTrack_1_default = "2:yes"
|
||||
# $sub_charset_1 = "2:UTF-8"
|
||||
# # Define track order
|
||||
# $track_order = "1:0,0:1,0:2"
|
||||
# # Define subtitles track to keep
|
||||
# $subtitle_tracks = "2"
|
||||
# break
|
||||
# }
|
||||
# "Star Trek Lower Decks.S01E10.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb"
|
||||
# #Default state
|
||||
# Default
|
||||
# {
|
||||
# # If not an exception, we don't want to modify the variables
|
||||
# $SubTrackName_1 = "3:English SDH - SRT"
|
||||
# $SubTrackLang_1 = "3:eng"
|
||||
# $SubTrack_1_default = "3:yes"
|
||||
# $sub_charset_1 = "3:UTF-8"
|
||||
# # Define track order
|
||||
# $track_order = "1:0,0:1,0:3"
|
||||
# # Define subtitles track to keep
|
||||
# $subtitle_tracks = "3"
|
||||
# break
|
||||
# }
|
||||
# }
|
||||
#########################################################
|
||||
|
||||
|
||||
# if ($i -lt 10 ) { # i<10
|
||||
# $MKV_1_name = $filename_1_part_1 + "S" + $filename_season + "E0" + $i + $filename_1_part_2
|
||||
# $MKV_2_name = $filename_2_part_1 + "S" + $filename_season + "E0" + $i + $filename_2_part_2
|
||||
# } else { # i=10
|
||||
# $MKV_1_name = $filename_1_part_1 + "S" + $filename_season + "E" + $i + $filename_1_part_2
|
||||
# $MKV_2_name = $filename_2_part_1 + "S" + $filename_season + "E" + $i + $filename_2_part_2
|
||||
# }
|
||||
# $MKV_1 = $sourceDirectory_1 + "\" + $MKV_1_name + ".mkv"
|
||||
# $MKV_2 = $sourceDirectory_2 + "\" + $MKV_2_name + ".mkv"
|
||||
|
||||
# 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'
|
||||
|
||||
#Set Output File Name
|
||||
#$Output = $Name + '___MERGED' + '.mkv'
|
||||
@ -143,14 +203,23 @@ for ($i = 1; $i -lt $Count_1+1; $i++) {
|
||||
|
||||
#Execute
|
||||
# Keep Audio/Subtitles/tags from MKV_1 + Only video from MKV_2
|
||||
# & $MKVMerge --title "$VideoTrackName" --track-order "$track_order" --subtitle-tracks "$subtitle_tracks" -o "$Output" --no-video
|
||||
#--language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default"
|
||||
#--sub-charset "2:UTF-8" --language "$SubTrackLang_1" --track-name "$SubTrackName_1" --default-track "$SubTrack_1_default"
|
||||
# "$MKV_1"
|
||||
# --language "0:fr" --track-name "0:$VideoTrackName" --default-track "0:yes"
|
||||
# "$MKV_2"
|
||||
<# Command to edit
|
||||
& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" --subtitle-tracks "$subtitle_tracks" -o "$Output"
|
||||
--no-video
|
||||
--language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default"
|
||||
--sub-charset "$sub_charset_1" --language "$SubTrackLang_1" --track-name "$SubTrackName_1" --default-track "$SubTrack_1_default"
|
||||
--sub-charset "$sub_charset_2" --language "$SubTrackLang_2" --track-name "$SubTrackName_2" --default-track "$SubTrack_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"
|
||||
#>
|
||||
# two subtiles to keep :
|
||||
#& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" --subtitle-tracks "$subtitle_tracks" -o "$Output" --no-video --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" --sub-charset "$sub_charset_1" --language "$SubTrackLang_1" --track-name "$SubTrackName_1" --default-track "$SubTrack_1_default" --sub-charset "$sub_charset_2" --language "$SubTrackLang_2" --track-name "$SubTrackName_2" --default-track "$SubTrack_2_default" "$MKV_1" --no-audio --no-track-tags --no-global-tags --language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes" --no-subtitles --no-audio "$MKV_2"
|
||||
|
||||
& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" --subtitle-tracks "$subtitle_tracks" -o "$Output" --no-video --no-chapters --no-global-tags --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" --sub-charset "2:UTF-8" --language "$SubTrackLang_1" --track-name "$SubTrackName_1" --default-track "$SubTrack_1_default" "$MKV_1" --language "0:fr" --track-name "0:$VideoTrackName" --default-track "0:yes" --no-subtitles --no-audio "$MKV_2"
|
||||
# Only one subtitles to keep
|
||||
& $MKVMerge --title "$VideoTrackName" --track-order "$track_order" --subtitle-tracks "$subtitle_tracks" -o "$Output" --no-video --language "$AudioLang_1" --track-name "$AudioTrackName_1" --default-track "$AudioTrack_1_default" --sub-charset "$sub_charset_1" --language "$SubTrackLang_1" --track-name "$SubTrackName_1" --default-track "$SubTrack_1_default" "$MKV_1" --no-audio --no-track-tags --no-global-tags --language "0:en" --track-name "0:$VideoTrackName" --default-track "0:yes" --no-subtitles --no-audio "$MKV_2"
|
||||
|
||||
|
||||
If (Test-Path $Output) {
|
||||
#Clean Up
|
||||
@ -158,6 +227,7 @@ for ($i = 1; $i -lt $Count_1+1; $i++) {
|
||||
#Remove-Item $Sub
|
||||
#Remove-Item $OtherSub
|
||||
# Move to folder Not-Merged, this folder's existence has already been tested, and the folder is created.
|
||||
Move-Item -Path $MKV_1 -Destination $Path_Folder_NotMerged_1 -Verbose
|
||||
Move-Item -Path $MKV_2 -Destination $Path_Folder_NotMerged_2 -Verbose
|
||||
#Move-Item -Path $Sub -Destination $Path_Folder_NotMerged_2 -Verbose
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user