File tree Expand file tree Collapse file tree
MilestoneSystems.PowerShell.MediaDB Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function ConvertTo-ValidFileName {
2+ [CmdletBinding ()]
3+ param (
4+ [Parameter (Mandatory , Position = 0 )]
5+ [string ]
6+ $Name
7+ )
8+
9+ [io.path ]::GetInvalidFileNameChars() | ForEach-Object {
10+ $Name = $Name -replace [regex ]::Escape($_ ), ' -'
11+ }
12+ $Name
13+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ function Export-MdbMkv {
4545 $null = New-Item - Path $fileInfo.DirectoryName - ItemType Directory - Force
4646 }
4747
48+ $pathIsFolder = $false
49+ if (Test-Path $fileInfo.FullName - PathType Container) {
50+ $pathIsFolder = $true
51+ }
4852
4953 try {
5054 Write-Verbose " Exporting $ ( $Device.Name ) from $ ( $Start.ToLocalTime ().ToString(' o' )) to $ ( $End.ToLocalTime ().ToString(' o' )) "
@@ -58,8 +62,8 @@ function Export-MdbMkv {
5862 $exporter = [videoos.platform.data.mkvexporter ]::new()
5963 $exporter.CameraList.Add ($Device )
6064
61- $exporter.Filename = $ fileInfo.Name
62- $exporter.Path = $ fileInfo.DirectoryName
65+ $exporter.Filename = if ( $pathIsFolder ) { ' {0}_{1}.mkv ' -f ( ConvertTo-ValidFileName $Device .Name ) , $Start .ToString ( ' yyyy-MM-dd_HH-mm-ss ' ) } else { $ fileInfo.Name }
66+ $exporter.Path = if ( $pathIsFolder ) { $ fileInfo.FullName } else { $fileInfo . DirectoryName }
6367 $exporter.Init ()
6468 if (! $exporter.StartExport ($Start , $End )) {
6569 Write-Error " MKVExporter could not begin the export process. Error code $ ( $exporter.LastError ) : $ ( $exporter.LastErrorString ) " - TargetObject $exporter
@@ -74,7 +78,7 @@ function Export-MdbMkv {
7478 Write-Error " MKVExporter returned error code $ ( $exporter.LastError ) : $ ( $exporter.LastErrorString ) " - TargetObject $exporter
7579 return
7680 }
77- Get-Item - LiteralPath $ Path
81+ Get-Item - LiteralPath ( Join-Path $exporter . Path $exporter .Filename )
7882 } catch {
7983 Write-Error - Message $_.Exception.Message
8084 } finally {
You can’t perform that action at this time.
0 commit comments