From f4386b178500bd56b8c37427021bcf1b1cc58720 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Tue, 21 Nov 2023 04:56:52 -0400 Subject: [PATCH] Some fixes --- hq2cd-ps1/convert-from-file.ps1 | 22 +++++++++++++++++----- hq2cd-ps1/get-paths.ps1 | 14 ++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hq2cd-ps1/convert-from-file.ps1 b/hq2cd-ps1/convert-from-file.ps1 index f32358a..06a5ae3 100644 --- a/hq2cd-ps1/convert-from-file.ps1 +++ b/hq2cd-ps1/convert-from-file.ps1 @@ -1,10 +1,8 @@ -# Output to a flat directory as I am going to use picard to rename the files after the fact - # Read each line in the file $filePaths = Get-Content -Path $args[0] $files = @() foreach ($filePath in $filePaths) { - $files += Get-Item -Path $filePath + $files += Get-Item -Path "$($filePath)" -Force } # Save to output folder "Output" @@ -20,7 +18,21 @@ foreach ($file in $files) { ffmpeg -i $file.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath } #> + +$prefix = "Z:\Music-HQ\" $files | ForEach-Object -Parallel { - $destinationPath = $destination + "\" + $_.Name - ffmpeg -i $_.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath + $oldLocation = $_.FullName + # Remove the prefix + $newLocation = $oldLocation.Substring($prefix.Length) + # Remove the name of the file for folder creation + $newLocation = $newLocation.Substring(0, $newLocation.IndexOf($_.Name)) + + # Create the folder if it doesn't exist + if (-not (Test-Path -Path $destination\$newLocation)) { + New-Item -Path $destination\$newLocation -ItemType Directory + } + + $destinationPath = $destination + "\" + $newLocation + $_.Name + Write-Host $destinationPath + # ffmpeg -i $_.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath } \ No newline at end of file diff --git a/hq2cd-ps1/get-paths.ps1 b/hq2cd-ps1/get-paths.ps1 index 1b156b8..aa7cd87 100644 --- a/hq2cd-ps1/get-paths.ps1 +++ b/hq2cd-ps1/get-paths.ps1 @@ -3,12 +3,10 @@ # Get all files with the .flac extension $files = Get-ChildItem -Path . -Filter *.flac -Recurse -Write-Host "Found" $files.Count "files" +# Write-Host "Found" $files.Count "files" # 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 -$hq = @() - <# 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 @@ -21,6 +19,8 @@ foreach ($file in $files) { } } #> + +$hq = @() $files | ForEach-Object -Parallel { $ffprobe = ffprobe -v quiet -print_format json -show_format -show_streams $_.FullName $ffprobe = $ffprobe | ConvertFrom-Json @@ -32,7 +32,9 @@ $files | ForEach-Object -Parallel { } } +# Doesn't work, so use input redirection instead "script.ps1 *> input.txt" because of read host, or "(pwsh -c script.ps1) > hq.txt" # Save each file in hq to a text file with its full path -foreach ($file in $hq) { - $file.FullName | Out-File -FilePath hq.txt -Append -} \ No newline at end of file +# New-Item -Path . -Name hq.txt -ItemType File -Quiet +# foreach ($file in $hq) { +# $file.FullName | Out-File -FilePath hq.txt -Append +# } \ No newline at end of file