Scripts/hq2cd-ps1/convert-from-file.ps1

50 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-11-21 05:33:03 -04:00
# Delete output folder if it exists
if (Test-Path -Path "Output") {
Remove-Item -Path "Output" -Recurse -Force
}
2023-11-21 03:31:57 -04:00
# Read each line in the file
$filePaths = Get-Content -Path $args[0]
# Save to output folder "Output"
$destination = "Output"
if (-not (Test-Path -Path $destination)) {
New-Item -Path $destination -ItemType Directory
}
# Now use ffmpeg to convert each file to 16-bit 44.1kHz
<# This is the old way, use the new way below using -Parallel
foreach ($file in $files) {
$destinationPath = $destination + "\" + $file.Name
ffmpeg -i $file.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath
}
#>
2023-11-21 04:56:52 -04:00
2023-11-21 05:33:03 -04:00
$filePaths | ForEach-Object -Parallel {
# Stupid apostrophe in the file name
# Intentional, as this is how Picard names files with apostrophes
$path = $_.Replace("'", "")
$file = Get-Item -LiteralPath $path
$destination = "Output"
$prefix = "Z:\Music-HQ\"
$oldLocation = $file.FullName
2023-11-21 04:56:52 -04:00
# Remove the prefix
$newLocation = $oldLocation.Substring($prefix.Length)
# Remove the name of the file for folder creation
2023-11-21 05:33:03 -04:00
$newLocation = $newLocation.Substring(0, $newLocation.IndexOf($file.Name))
2023-11-21 04:56:52 -04:00
# Create the folder if it doesn't exist
if (-not (Test-Path -Path $destination\$newLocation)) {
New-Item -Path $destination\$newLocation -ItemType Directory
}
2023-11-21 05:33:03 -04:00
$destinationPath = $destination + "\" + $newLocation + $file.Name
2023-11-21 04:56:52 -04:00
Write-Host $destinationPath
2023-11-21 05:33:03 -04:00
ffmpeg -i $_.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath
2023-11-21 03:31:57 -04:00
}