Scripts/hq2cd-ps1/get-paths.ps1

40 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-11-21 02:57:03 -04:00
# From the current folder, make a powershell array that finds all files with the .flac extension and add them to a list
# Get all files with the .flac extension
$files = Get-ChildItem -Path . -Filter *.flac -Recurse
2023-11-21 04:56:52 -04:00
# Write-Host "Found" $files.Count "files"
2023-11-21 03:31:57 -04:00
2023-11-21 02:57:03 -04:00
# For each file, run ffprobe with json ouptut, and include it in a new list if it has a sample rate above 44100, and a bit depth above 16
2023-11-21 03:31:57 -04:00
<# This is the old way, use the new way below using -Parallel
foreach ($file in $files) {
$ffprobe = ffprobe -v quiet -print_format json -show_format -show_streams $file.FullName
$ffprobe = $ffprobe | ConvertFrom-Json
$stream = $ffprobe.streams | Where-Object {$_.codec_name -eq "flac"}
if ($stream.sample_rate -gt 44100 -or $stream.bits_per_raw_sample -gt 16) {
Write-Host $file.FullName
$hq += $file
}
}
#>
2023-11-21 04:56:52 -04:00
$hq = @()
2023-11-21 02:57:03 -04:00
$files | ForEach-Object -Parallel {
$ffprobe = ffprobe -v quiet -print_format json -show_format -show_streams $_.FullName
$ffprobe = $ffprobe | ConvertFrom-Json
2023-11-21 03:31:57 -04:00
$stream = $ffprobe.streams | Where-Object {$_.codec_name -eq "flac"}
if ($stream.sample_rate -gt 44100 -or $stream.bits_per_raw_sample -gt 16) {
Write-Host $_.FullName
2023-11-21 02:57:03 -04:00
$hq += $_
}
}
2023-11-21 04:56:52 -04:00
# Doesn't work, so use input redirection instead "script.ps1 *> input.txt" because of read host, or "(pwsh -c script.ps1) > hq.txt"
2023-11-21 03:31:57 -04:00
# Save each file in hq to a text file with its full path
2023-11-21 04:56:52 -04:00
# New-Item -Path . -Name hq.txt -ItemType File -Quiet
# foreach ($file in $hq) {
# $file.FullName | Out-File -FilePath hq.txt -Append
# }