70 lines
1.8 KiB
PowerShell
70 lines
1.8 KiB
PowerShell
function Merge-MkvVideos {
|
|
<#
|
|
.SYNOPSIS
|
|
Used to merge two MKV files into one output file
|
|
|
|
.PARAMETER OutputFile
|
|
Target a single file for output, full name
|
|
|
|
.PARAMETER Path
|
|
Two or more paths, comma separated, will concatenate in the order presented
|
|
|
|
.LINK
|
|
https://mkvtoolnix.download/downloads.html
|
|
#>
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[Alias('Target')]
|
|
[Alias('Output')]
|
|
[Alias('o')]
|
|
[string[]]$OutputFile,
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[Alias('Source')]
|
|
[Alias('Input')]
|
|
[string[]]$Path
|
|
)
|
|
|
|
$mkvmergePath = "/usr/bin/mkvmerge"
|
|
|
|
$alternateMvkMergePath = (which mkvmerge)
|
|
|
|
if (-not (Test-Path -Path $mkvmergePath)) {
|
|
if ($alternateMvkMergePath.indexOf(": no")) {
|
|
Write-Warning "Maybe you should do: [https://mkvtoolnix.download/downloads.html] ?"
|
|
throw "Could not find the path for mkvmerge [$mkvmergePath] Is it installed? Is it in the PATH?"
|
|
} else {
|
|
$mkvmergePath = $alternateMvkMergePath
|
|
}
|
|
}
|
|
|
|
if ($Path.Count -lt 2) {
|
|
throw "Must supply more than one path to this function"
|
|
}
|
|
|
|
if (Test-Path -Path $OutputFile) {
|
|
Write-Warning "The specified file already exists. This file will be overwritten."
|
|
}
|
|
|
|
$commandArguments = @("-o", $OutputFile)
|
|
|
|
$firstPath = $true
|
|
|
|
foreach ($filePath in $Path) {
|
|
$filePath = Resolve-Path -Path $filePath
|
|
if (-not $firstPath) {
|
|
$commandArguments += "+"
|
|
}
|
|
$commandArguments += $filePath
|
|
$firstPath = $false
|
|
}
|
|
|
|
$invokeArguments = @{
|
|
Path = $mkvmergePath
|
|
Arguments = $commandArguments
|
|
}
|
|
|
|
Invoke-CallPathWithArguments @invokeArguments
|
|
} |