Making a list of all WV files with a deviant compression, using wvunpack? |
![]() ![]() |
Making a list of all WV files with a deviant compression, using wvunpack? |
Dec 17 2009, 17:16
Post
#1
|
|
|
Group: Members Posts: 1540 Joined: 13-August 03 Member No.: 8353 |
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... |
|
|
|
Dec 17 2009, 17:33
Post
#2
|
|
![]() Group: Members (Donating) Posts: 762 Joined: 12-March 05 From: Kiel, Germany Member No.: 20561 |
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. This post has been edited by Kohlrabi: Dec 17 2009, 17:34 -------------------- Audiophiles live in constant fear of jitter.
|
|
|
|
Dec 17 2009, 17:35
Post
#3
|
|
|
Group: Members Posts: 231 Joined: 6-April 09 Member No.: 68706 |
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 @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. This post has been edited by _mē_: Dec 17 2009, 17:56 |
|
|
|
Dec 17 2009, 20:19
Post
#4
|
|
|
Group: Members Posts: 1540 Joined: 13-August 03 Member No.: 8353 |
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 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 ) ) This post has been edited by Fandango: Dec 17 2009, 20:59 |
|
|
|
Dec 17 2009, 20:31
Post
#5
|
|
|
Group: Members Posts: 231 Joined: 6-April 09 Member No.: 68706 |
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 @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 |
|
|
|
Dec 17 2009, 20:37
Post
#6
|
|
|
Group: Members Posts: 1540 Joined: 13-August 03 Member No.: 8353 |
Hm, I tried that before with "> NIL:" but it didn't work
But now I just tried every step in the command prompt with >NUL 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 @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. This post has been edited by Fandango: Dec 17 2009, 20:53 |
|
|
|
Dec 25 2009, 17:50
Post
#7
|
|
|
Group: Members Posts: 1540 Joined: 13-August 03 Member No.: 8353 |
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 @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. This post has been edited by Fandango: Dec 25 2009, 17:50 |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 20th May 2013 - 13:48 |