Page 1 of 1

[Windows] Help needed! Flac to ogg converter script

Posted: September 2nd, 2015, 1:40 pm
by zdevel
I've written a little converter script, but have no idea why it's not working.
Process is as follows: when a flac download finishes, "call.bat" is called which in return calls "flacogg.ps1".

call.bat looks like this:

Code: Select all

PowerShell -ExecutionPolicy Bypass "C:\Progra~2\SABnzbd\scripts\flacogg.ps1" -PathName "%1"
flacogg.ps1 looks like this:

Code: Select all

param(
    [string]$PathName
)

# Move flac files from sub dir to processing dir
Get-ChildItem -Path $PathName -Recurse -File -Filter *.flac | Move-Item -Destination $PathName

# get all files for encoding
$files = Get-ChildItem -Path $PathName -File -Filter *.flac

for($i=0; $i -lt $files.count; $i++) {
	$outfile = $files[$i].Name + ".ogg"
	oggenc2 -q 10 -S 0 -o $outfile $files[$i]
}

exit 0
Problem might be a path issue, but I'm not sure. Any help is highly appreciated!


Thanks in advance

Re: [Windows] Help needed! Flac to ogg converter script

Posted: September 2nd, 2015, 3:12 pm
by shypike
Remove the quotes in the first script, since SABnzbd already has them in the parameters.

Code: Select all

PowerShell -ExecutionPolicy Bypass "C:\Progra~2\SABnzbd\scripts\flacogg.ps1" -PathName %1

Re: [Windows] Help needed! Flac to ogg converter script

Posted: September 3rd, 2015, 2:06 am
by zdevel
First of all, thank you.
That didn't solve my initial problem, but got me on the right track. I needed to tell sabnzbd to replace spaces with underscores, as escaping spaces in paths is rather dull in Powershell.
The other trick is to assemble the path in the script like so

Code: Select all

($PathName + "\" + $files[$i])
My final script is working perfectly now. I'm not at home to have a look at the exact code, but this should be it...

Code: Select all

param(
    [string]$PathName
)

# Move flac files from sub dir to processing dir
Get-ChildItem -Path $PathName -Recurse -File -Filter *.flac | Move-Item -Destination $PathName

# get all files for encoding
$files = Get-ChildItem -Path $PathName -File -Filter *.flac

for($i=0; $i -lt $files.count; $i++) {
   $outfile = $files[$i].Name + ".ogg"
   oggenc2 -q 10 -S 0 -o ($PathName + "\" + $outfile) ($PathName + "\" + $files[$i])
   Remove-Item ($PathName + "\" + $files[$i])
}

exit 0