Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Making a list of all WV files with a deviant compression (Read 7150 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Making a list of all WV files with a deviant compression

I'm not very good with DOS batch scripts. The lack of piping text output and the lack of any native text stream processor makes it very hard to achieve what I'm planning to do:

foobar2000 does not support showing the exact encoding profile in Wavpack files. All it shows will be "Wavpack fast", "Wavpack normal"(?) and "Wavpack high". But I want to transcode all Wavpack files to a certain compression level and the problem is that some of my files have already been compressed with those settings but many haven't.

The only tool I know that can show me the actual compression settings is wvunpack.exe. Now if I were using a Linux machine, it be a piece of cake for me to write a shell script that gives me a list of all WV files that do not match my preferred compression. (I need to get a list although I could transcode them right away using the script, but since I have a quad core I'd rather have a multi-threading capable launcher do that, like foobar2000).

So how would I get it done in Windows? I guess it would be very easy with Powershell, although lerning how to use the PS isn't that easy...

Making a list of all WV files with a deviant compression

Reply #1
You could use some language like perl, ruby or python to achieve similar results, but if you knew them you'd probably used them by now...

also, cygwin or msys offer bash for windows, which might be enough for that kind of script.
It's only audiophile if it's inconvenient.

Making a list of all WV files with a deviant compression

Reply #2
I'm not very good with DOS batch scripts. The lack of piping text output and the lack of any native text stream processor makes it very hard to achieve what I'm planning to do:

foobar2000 does not support showing the exact encoding profile in Wavpack files. All it shows will be "Wavpack fast", "Wavpack normal"(?) and "Wavpack high". But I want to transcode all Wavpack files to a certain compression level and the problem is that some of my files have already been compressed with those settings but many haven't.

The only tool I know that can show me the actual compression settings is wvunpack.exe. Now if I were using a Linux machine, it be a piece of cake for me to write a shell script that gives me a list of all WV files that do not match my preferred compression. (I need to get a list although I could transcode them right away using the script, but since I have a quad core I'd rather have a multi-threading capable launcher do that, like foobar2000).

So how would I get it done in Windows? I guess it would be very easy with Powershell, although lerning how to use the PS isn't that easy...

A simplified version of my script:
Code: [Select]
@echo off

::::::::::::::::::::
:: DEPENDENCIES:
:: - flac
:: - mac
:: - wavpack
:: - wvunpack


::::::::::::::::::::
:: SETTINGS

set PACKER.CMD=wavpack -hhx6 %%in%% %%out%%
set PACKER.FILE_EXTENSION=wv

::::::::::::::::::::
:: START


:get_temp_file_name
set TMP_FILE=%TMP%\c%RANDOM%.tmp
IF EXIST "%TMP_FILE%" goto get_temp_file_name

for /r %%a in (*.*) DO echo "%%a">>"%TMP_FILE%"
for /f "delims=" %%a in (%TMP_FILE%) DO call :convert %%a
del "%TMP_FILE%"

:convert
::there's an issue with files containing '&' character. That's why I add and remove the quotes
set fst="%~nx1"
call :DeQuote fst

set name="%~n1"
call :DeQuote name

echo "%fst%"

set Delete=1

:: convert to wav
if /i [%~x1] == [.wav] (
     set Delete=0
     goto compress
)
if /i [%~x1] == [.ape] (
     mac "%fst%" "%name%.wav" -d
     if [.%PACKER.FILE_EXTENSION%] == [%~x1] rename "%~dpnx1" "_%~nx1"
     goto compress
)
if /i [%~x1] == [.flac] (
     flac -d "%fst%" "%name%.wav"
     if [.%PACKER.FILE_EXTENSION%] == [%~x1] rename "%~dpnx1" "_%~nx1"
     goto compress
)
if /i [%~x1] == [.shn] (
     shorten -x "%fst%" "%name%.wav"
     if [.%PACKER.FILE_EXTENSION%] == [%~x1] rename "%~dpnx1" "_%~nx1"
     goto compress
)
if /i [%~x1] == [.wv] (
::--------------- ADD CHECKING FOR SETTINGS AFTER THIS LINE ---------------------
     wvunpack "%fst%" "%name%.wav"
     if [.%PACKER.FILE_EXTENSION%] == [%~x1] rename "%~dpnx1" "_%~nx1"
     goto compress
)
::not a convertable file
goto :eof

:: compress one file
:compress

set in="%name%.wav"
set out="%~dpn1.%PACKER.FILE_EXTENSION%"
cmd /c %PACKER.CMD%

::cleanup
if %Delete% == 1 (
     del "%name%.wav"
)
goto :EOF

:: DeQuote
:DeQuote

SET DeQuote.Variable=%1
CALL Set DeQuote.Contents=%%%DeQuote.Variable%%%
CALL Set DeQuote.Contents=%DeQuote.Contents:&=__AND__%
Echo.%DeQuote.Contents%|FindStr/brv ""^">NUL:&&Goto :EOF
Echo.%DeQuote.Contents%|FindStr/erv ""^">NUL:&&Goto :EOF
  
Set DeQuote.Contents=####%DeQuote.Contents%####
Set DeQuote.Contents=%DeQuote.Contents:####"=%
Set DeQuote.Contents=%DeQuote.Contents:"####=%
Set %DeQuote.Variable%=%DeQuote.Contents:__AND__=^&%
  
Set DeQuote.Variable=
Set DeQuote.Contents=
Goto :EOF

1. You need to enter checking for wavpack version in the marked place. I suggest parsing wvunpack output with grep.
I don't knot what did you mean with lack of piping, but wvunpack parameters | grep grep_parameters should work.
2. Unicode file names cause problems
3. It's not thoroughly debugged
4. Just BTW, if you're into space reduction, recently I saved .5 gig just by recompressing artwork.

Making a list of all WV files with a deviant compression

Reply #3
1. You need to enter checking for wavpack version in the marked place. I suggest parsing wvunpack output with grep.
I don't knot what did you mean with lack of piping, but wvunpack parameters | grep grep_parameters should work.

Oh my bad. cmd.exe does have piping, but I thought it would be insufficient. In fact thanks to the -q parameter piping wvunpack's error messages into oblivion isn't necessary.

Also cmd.exe comes with a tool almost equivalent to grep called findstr didn't knew about that one. But it lacks the -v parameter.

So here's the simple script I wrote, it works exactly as I want it to, except for one tiny cosmetical flaw I can't seem to get fixed. When findstr finds a match, it will print out the matching line to the screen and as I'm using ERRORLEVEL to find those cases where it didn't find a match, I can't seem to pipe findstr's output to NIL: without setting the ERRORLEVEL to 0 and thus breaking the logic of my whole script. Now it's only a minor flaw since findstr's output will not be written to "list.txt". Still I wonder if there is a way to silence findstr in some way, maybe by changing the logic of the script completely?

Code: [Select]
Not working! See code further down

@ECHO OFF

FOR /R %%F IN (*.wv) DO (
    wvunpack.exe -q -s "%%F" | findstr /c:"extra-3"
    IF %ERRORLEVEL% NEQ 0 (
        echo "%%F" >> list.txt
    )
)

Making a list of all WV files with a deviant compression

Reply #4
1. You need to enter checking for wavpack version in the marked place. I suggest parsing wvunpack output with grep.
I don't knot what did you mean with lack of piping, but wvunpack parameters | grep grep_parameters should work.

Oh my bad. cmd.exe does have piping, but I thought it would be insufficient. In fact thanks to the -q parameter piping wvunpack's error messages into oblivion isn't necessary.

Also cmd.exe comes with a tool almost equivalent to grep called findstr didn't knew about that one. But it lacks the -v parameter.

So here's the simple script I wrote, it works exactly as I want it to, except for one tiny cosmetical flaw I can't seem to get fixed. When findstr finds a match, it will print out the matching line to the screen and as I'm using ERRORLEVEL to find those cases where it didn't find a match, I can't seem to pipe findstr's output to NIL: without setting the ERRORLEVEL to 0 and thus breaking the logic of my whole script. Now it's only a minor flaw since findstr's output will not be written to "list.txt". Still I wonder if there is a way to silence findstr in some way, maybe by changing the logic of the script completely?

Code: [Select]
@ECHO OFF

FOR /R %%F IN (*.wv) DO (
     wvunpack.exe -q -s "%%F" | findstr /c:"extra-3"
     IF %ERRORLEVEL% NEQ 0 (
         echo "%%F" >> list.txt
     )
)



wvunpack.exe -q -s "%%F" | findstr /c:"extra-3">nul

Making a list of all WV files with a deviant compression

Reply #5
Hm, I tried that before with "> NIL:" but it didn't work although it should have. So I assumed piping to NIL: will set the error level to 0.

But now I just tried every step in the command prompt with >NUL and with >NIL: and everything should work.

But when I run the batch script I get the filename of every WV file, also echoing to a file does not work when using the script, but it works when using the command prompt... what the?

It's as if "IF %ERRORLEVEL% NEQ 0 " is ignored and ">> list.txt" is, too, when I use them in the script.

EDIT: Ah the trick is to not use %ERRORLEVEL% but ERRORLEVEL...

So this works now:

Code: [Select]
@ECHO OFF

FOR /R %%F IN (*.wv) DO (
    wvunpack.exe -q -s "%%F" | findstr /c:"extra-3" > NUL
    IF ERRORLEVEL 1 echo %%F >> list.m3u
)

Thanks _m²_ for the tips. Now let's see how much space I will save... 1h40m for the first batch of files.

Making a list of all WV files with a deviant compression

Reply #6
I have made a simple update to the script, so that it will also find files in other lossless formats and add them to the playlist: 

Code: [Select]
@ECHO OFF

FOR /R %%F IN (*.wv *.flac *.ape *.wav) DO (
    IF %%~xF == .wv (
        wvunpack.exe -q -s "%%F" | findstr /c:"extra-3" > NUL
        IF ERRORLEVEL 1 echo %%F >> list.m3u
    ) ELSE (
        echo %%F >> list.m3u
    )
)


So if you want to add some more file types add them to the list in the FOR line.
If your desired compression level for Wavpack is different you have to edit the string /c:"<here>".
The batch script must be executed in the base directory of where the to be processed audio files lie, it will then search all of its sub-directories. The script does not accept a directory path as an argument, but it can easily be changed for doing it both ways.