Add wildcard support to Get-VideoInfo.ps1 for processing multiple video files with pattern matching and sequential metadata display

This commit is contained in:
2026-06-09 20:50:09 -04:00
parent 9cbe54d8d3
commit a057ab0d1d
+33 -7
View File
@@ -3,6 +3,8 @@
Extracts and displays video metadata from the comment tag in a video file's format metadata. Extracts and displays video metadata from the comment tag in a video file's format metadata.
.PARAMETER Video .PARAMETER Video
Path to the input video file. Can be absolute or relative to current directory. 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 .PARAMETER Full
When present, outputs the parsed comment metadata as JSON. When present, outputs the parsed comment metadata as JSON.
.DESCRIPTION .DESCRIPTION
@@ -23,17 +25,39 @@ $ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8
$VideoPath = $Video # Resolve video paths, supporting wildcards
$videoPaths = @()
if (-not (Test-Path -LiteralPath $VideoPath)) { if ($Video -match '[*?]') {
Write-Error ('Video file not found: {0}' -f $VideoPath) # 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 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 $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 { 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 $ffprobeExit = $LASTEXITCODE
if ($ffprobeExit -ne 0) { if ($ffprobeExit -ne 0) {
@@ -191,6 +215,8 @@ try {
Write-Output '----------------------------------------' Write-Output '----------------------------------------'
} }
catch { catch {
Write-Error ('Unexpected error: {0}' -f $_.Exception.Message) Write-Error ('Unexpected error processing {0}: {1}' -f $VideoPath, $_.Exception.Message)
exit 1 # Continue to next file instead of exiting
continue
}
} }