Add wildcard support to Get-VideoInfo.ps1 for processing multiple video files with pattern matching and sequential metadata display
This commit is contained in:
+34
-8
@@ -3,6 +3,8 @@
|
||||
Extracts and displays video metadata from the comment tag in a video file's format metadata.
|
||||
.PARAMETER Video
|
||||
Path to the input video file. Can be absolute or relative to current directory.
|
||||
Supports Windows wildcards (* and ?) to match multiple files. When wildcards are used,
|
||||
metadata is extracted and displayed for each matching file sequentially.
|
||||
.PARAMETER Full
|
||||
When present, outputs the parsed comment metadata as JSON.
|
||||
.DESCRIPTION
|
||||
@@ -23,17 +25,39 @@ $ErrorActionPreference = 'Stop'
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
|
||||
$VideoPath = $Video
|
||||
|
||||
if (-not (Test-Path -LiteralPath $VideoPath)) {
|
||||
Write-Error ('Video file not found: {0}' -f $VideoPath)
|
||||
exit 1
|
||||
# Resolve video paths, supporting wildcards
|
||||
$videoPaths = @()
|
||||
if ($Video -match '[*?]') {
|
||||
# Wildcard pattern - use Get-ChildItem to resolve
|
||||
$resolvedFiles = Get-ChildItem -Path $Video -File -ErrorAction SilentlyContinue
|
||||
if (-not $resolvedFiles) {
|
||||
Write-Error ('No files matched wildcard pattern: {0}' -f $Video)
|
||||
exit 1
|
||||
}
|
||||
$videoPaths = $resolvedFiles | Select-Object -ExpandProperty FullName
|
||||
} else {
|
||||
# Single file path (literal)
|
||||
if (-not (Test-Path -LiteralPath $Video)) {
|
||||
Write-Error ('Video file not found: {0}' -f $Video)
|
||||
exit 1
|
||||
}
|
||||
$videoPaths = @($Video)
|
||||
}
|
||||
|
||||
$PSNativeCommandUseErrorActionPreference = $false
|
||||
|
||||
$firstFile = $true
|
||||
foreach ($VideoPath in $videoPaths) {
|
||||
# Add separator between files (but not before the first one)
|
||||
if (-not $firstFile) {
|
||||
Write-Output ''
|
||||
Write-Output '========================================'
|
||||
Write-Output ''
|
||||
}
|
||||
$firstFile = $false
|
||||
|
||||
try {
|
||||
$ffprobeOutput = & ffprobe -v quiet -print_format json -show_format -show_streams -- $VideoPath 2>&1
|
||||
$ffprobeOutput = & ffprobe -v quiet -print_format json -show_format -show_streams -- "$VideoPath" 2>&1
|
||||
$ffprobeExit = $LASTEXITCODE
|
||||
|
||||
if ($ffprobeExit -ne 0) {
|
||||
@@ -191,6 +215,8 @@ try {
|
||||
Write-Output '----------------------------------------'
|
||||
}
|
||||
catch {
|
||||
Write-Error ('Unexpected error: {0}' -f $_.Exception.Message)
|
||||
exit 1
|
||||
Write-Error ('Unexpected error processing {0}: {1}' -f $VideoPath, $_.Exception.Message)
|
||||
# Continue to next file instead of exiting
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user