[Windows] Help needed! Flac to ogg converter script

Come up with a useful post-processing script? Share it here!
Post Reply
zdevel
Newbie
Newbie
Posts: 2
Joined: September 2nd, 2015, 1:25 pm

[Windows] Help needed! Flac to ogg converter script

Post 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
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

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

Post 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
zdevel
Newbie
Newbie
Posts: 2
Joined: September 2nd, 2015, 1:25 pm

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

Post 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
Post Reply