Page 1 of 2
How do I get mp3 bitrate?
Posted: 07 Oct 2017 16:39
by tlm2408
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.
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 17:03
by Squashman
And what third party console program are you using to get the tag information from the file?
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 17:09
by aGerman
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
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 17:13
by tlm2408
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.
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 17:16
by Squashman
I believe there are some free programs out on the Internet that will do what you want as well.
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 17:29
by tlm2408
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.
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 17:36
by aGerman
tlm2408 wrote:but doesn't write any data
I tested the code before I posted it. Definitely works for me.
Steffen
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 18:08
by tlm2408
I'm getting:
c:\bitrate.bat(20, 14) jscript compilation error: expected ';'
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 18:21
by aGerman
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
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 18:30
by tlm2408
Yeah I know. I don't know why it wants a semicolon there either. Must be a problem at my end.
Re: How do I get mp3 bitrate?
Posted: 07 Oct 2017 18:37
by tlm2408
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.
Re: How do I get mp3 bitrate?
Posted: 08 Oct 2017 05:07
by aGerman
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
Re: How do I get mp3 bitrate?
Posted: 08 Oct 2017 14:03
by tlm2408
Bingo!!!
That was it. That you so very much for your help and time. That was driving me nuts!!!
Re: How do I get mp3 bitrate?
Posted: 08 Oct 2017 15:47
by aGerman
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
Re: How do I get mp3 bitrate?
Posted: 09 Oct 2017 01:15
by tlm2408
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