Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#1
Post
by tlm2408 » 07 Oct 2017 16:39
Hello, I'm trying to save the bitrate and duration of each file in my mp3/flac collection to a text file.
For variable bitrates if it could just say VBR would be fine if it makes things easier.
I'd also like to find if the songs are stereo or mono (not important, but would be cool).
At the moment I get the file path and filename with this batch file:
Code: Select all
@echo off &setlocal
>"list.txt" type nul
for /r "C:\Audio" %%i in (*.mp3 *.flac) do (
set "fname=%%~nxi"
set "fpath=%%~fi"
setlocal EnableDelayedExpansion
>>"list.txt" echo {"Title": "!fname!", "Fullpath": "!fpath:\=/!"},
endlocal
)
Thank you for any help.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 07 Oct 2017 17:03
And what third party console program are you using to get the tag information from the file?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#3
Post
by aGerman » 07 Oct 2017 17:09
I don't know any possibility to get those informations using pure batch. A Batch/JScript hybrid script may work for you.
Code: Select all
@if (@a)==(@b) @end /*
:: Batch
@echo off &setlocal
set "property=Bitrate"
>"list.txt" type nul
for /r "C:\Audio" %%i in (*.mp3 *.flac) do (
set "fname=%%~nxi"
set "fpath=%%~fi"
setlocal EnableDelayedExpansion
for /f "tokens=* delims=?" %%j in ('cscript //nologo //e:jscript "%~fs0" "!fpath!" "!property!"') do (
>>"list.txt" echo {"Title": "!fname!", "Fullpath": "!fpath:\=/!", "bitrate": "%%j"},
)
endlocal
)
:: JScript
exit /b&::*/ try {
var objFSO = WScript.CreateObject('Scripting.FileSystemObject'), objWShell = WScript.CreateObject('WScript.Shell'),
objShell = WScript.CreateObject('Shell.Application');
objWShell.CurrentDirectory = objFSO.GetParentFolderName(WScript.ScriptFullName);
var strFullName = objFSO.GetAbsolutePathName(WScript.Arguments(0)), objFolder = objShell.Namespace(objFSO.GetParentFolderName(strFullName)),
objFolderItem = objFolder.ParseName(objFSO.GetFileName(strFullName)), i = 0, strPropName = '';
while ((strPropName = objFolder.GetDetailsOf(null, i)) != '') {
if (strPropName.toLowerCase() == WScript.Arguments(1).toLowerCase()) {
WScript.Echo(objFolder.GetDetailsOf(objFolderItem, i));
WScript.Quit(0);
}
i++;
}
}
catch(e) {
WScript.StdErr.WriteLine(e.message);
WScript.Quit(1);
}
FWIW I have not seen any property that states if a file is mono or stereo yet. Also I didn't know that something like a variable bitrate even exists.
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#4
Post
by tlm2408 » 07 Oct 2017 17:13
I'm a bit of a newbie when it comes to batch files sorry.
I really don't know what I need to do at all to get the info.
I'm on windows 8.1 and have winamp and windows media player if that helps.
Sorry for my ignorance.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#5
Post
by Squashman » 07 Oct 2017 17:16
I believe there are some free programs out on the Internet that will do what you want as well.
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#6
Post
by tlm2408 » 07 Oct 2017 17:29
Thank you aGerman I ran the batch you gave me it creates the file, but doesn't write any data to it.
Thank you Squashman I've had a bit of a look, but didn't see anything that jumped out at me. I'll have a better look to see what's around.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#7
Post
by aGerman » 07 Oct 2017 17:36
tlm2408 wrote:but doesn't write any data
I tested the code before I posted it. Definitely works for me.
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#8
Post
by tlm2408 » 07 Oct 2017 18:08
I'm getting:
c:\bitrate.bat(20, 14) jscript compilation error: expected ';'
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#9
Post
by aGerman » 07 Oct 2017 18:21
Line 20 position 14 in my script is the r in "try" of
exit /b&::*/ try {
Don't see any reason why a semi-colon is missing there.
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#10
Post
by tlm2408 » 07 Oct 2017 18:30
Yeah I know. I don't know why it wants a semicolon there either. Must be a problem at my end.
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#11
Post
by tlm2408 » 07 Oct 2017 18:37
My bad had saved it as utf-8 by accident. Changed it to ansi, now it runs with no error but still doesn't write the data to the file. I'll keep looking.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#12
Post
by aGerman » 08 Oct 2017 05:07
I was googling a little. Please have a look at the properties of the files. It seems that it shows up as "Bitrate" in my German environment while the English screen shots I found show "Bit rate" as two words. Try to change the "property" variable in the script to what you see in the Details-tab of of the file properties.
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#13
Post
by tlm2408 » 08 Oct 2017 14:03
Bingo!!!
That was it. That you so very much for your help and time. That was driving me nuts!!!
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#14
Post
by aGerman » 08 Oct 2017 15:47
Coming back to Squashman's suggestion...
https://www.sno.phy.queensu.ca/~phil/exiftool/Download the Windows Executable. Unpack the ZIP and rename the executable to "exiftool.exe"
I think it supports all that you need. Save this code in the same directory along with exiftool.exe:
Code: Select all
@echo off &setlocal
exiftool.exe -j -r -ext mp3 -ext flac "C:\Audio" |find /v "ExifToolVersion" >"list.txt"
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#15
Post
by tlm2408 » 09 Oct 2017 01:15
Wow! That is impressive, still playing around with it and it's works pretty good. Still working out how to add text before and after the results. With your script I have added stuff to output a js file. I haven't worked out how to do that yet with the exiftool.
Just out of curiosity with the other batch file you gave me, how would I specify another property?
For example adding the "Length" and "Year" properties?
Hopefully with that I can workout how to add more if I ever need them.
I'm still trying to decide what suits my needs better.
I like your batch file better as I don't have to have another program to get the info I want and I can live without the stereo, mono bit.
Thank you
Greg