DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Sort/organize mp3 files by bitrate, into folders  (Read 14,146 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Sort/organize mp3 files by bitrate, into folders
« on: May 13, 2020, 12:55 PM »
Looking for a way to sort/organize mp3 files in a folder into a set of folders by bitrate:

320 kbps mp3s --> appropriate folder named "320"
192 kbps mp3s --> appropriate folder named "192"
etc.

Any thoughts appreciated.

Nicholas Kormanik

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #1 on: May 13, 2020, 02:28 PM »
Looking for a way to sort/organize mp3 files in a folder into a set of folders by bitrate:

320 kbps mp3s --> appropriate folder named "320"
192 kbps mp3s --> appropriate folder named "192"

What happens if the files are VBR (Variable Bit Rate)?  If you have VBR files, you will end up with a mess.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #2 on: May 14, 2020, 01:08 AM »
Excellent point, Skwire.  That may be the reason why no such program seems to exist out there.

Request still stands, however.  I'd really like to be able to do as I ask.

You did something similar with image files.  Auto sorting into folders by dimension.



4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #3 on: May 14, 2020, 02:02 AM »
Add the four lines needed to create the folder, and change the Remove-Item line to Move-Item.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #4 on: May 14, 2020, 07:17 AM »
4wd, please elaborate?

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,175
    • Coding Snacks
    • Participated in NANY Challenge Three Times
    • Plugin Coding Medal
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #5 on: May 14, 2020, 12:53 PM »
This worked for me in a quick test. But do try it out on some smaller folders first to see that it works as expected on your files, since mp3 tags and exif data can be complicated and I don't know if the function I use handles all corner cases correctly.

Code: (AutoHotkey)
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force
ListLines, Off
SetBatchLines, -1

; sort mp3 files into folders based on bitrate and if they are VBR or not
; AutoHotkey script
; by nod5
; 2020-05-14

; ---------------------------------------
; folder with mp3 files that we want to sort move

sourcefolder      := "C:\some\folder"

; also recurse in sourcefolder? 1 means yes, 0 means no
recurse := 1

; target folder where we want the files to end up in subfolders 
; for example VBR files go to \VBR subfolder, 128kbs CBR files got to \128 subfolder

destinationfolder := "D:\this other\location"

; ---------------------------------------

; disable recurse if in/out folders are same, to avoid endless loop
if (sourcefolder = destinationfolder)
  recurse := 0

; recursively loop sourcefolder for mp3 files and move to a destinationfolder subfolder
Loop, Files, % sourcefolder "\*.mp3", % recurse ? "R" : ""
{
  ToolTip, % A_LoopFileName
  ; get audio properties as object
  ; we need these two properties:
  ; System.Audio.EncodingBitrate      examples: 128000 (which is 128kbs), 320000, 263704, ...
  ; System.Audio.IsVariableBitRate    value -1 if VBR otherwise value 0
  Props := ["System.Audio.IsVariableBitRate", "System.Audio.EncodingBitrate"]
  obj := Filexpro(A_LoopFilePath,, Props*)           ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9

  ; if VBR then move to subfolder "\VBR"
  if (obj["System.Audio.IsVariableBitRate"] = "-1")
    subfolder := "VBR"
  else
  {
    ; else move CBR to matching bitrate folder, for example "\128"
    ; get bitrate in kbs, for example 128000 -> 128
    subfolder := SubStr(obj["System.Audio.EncodingBitrate"],1,-3)
  }
  if subfolder
  {
    if !FileExist(destinationfolder "\" subfolder)
      FileCreateDir, % destinationfolder "\" subfolder
    FileMove, % A_LoopFilePath, % destinationfolder "\" subfolder
  }
}
ToolTip DONE
sleep 2000
ExitApp



; function: Filexpro
; get extended properties from file
; by SKAN 2018-12-11 
; https://www.autohotkey.com/boards/viewtopic.php?t=59882

Filexpro( sFile := "", Kind := "", P* ) {           ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Local
Static xDetails 

  If ( sFile = "" )
    {                                                           ;   Deinit static variable
        xDetails := ""
        Return
    }
  
  fex := {}, _FileExt := "" 

  Loop, Files, % RTrim(sfile,"\*/."), DF 
    {
        If not FileExist( sFile:=A_LoopFileLongPath )
          {
              Return
          } 

        SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv

        If ( p[p.length()] = "xInfo" )                          ;  Last parameter is xInfo 
          {
              p.Pop()                                           ;         Delete parameter
              fex.SetCapacity(11)                               ; Make room for Extra info
              fex["_Attrib"]    := A_LoopFileAttrib
              fex["_Dir"]       := _Dir
              fex["_Drv"]       := _Drv
              fex["_Ext"]       := _Ext
              fex["_File"]      := _File
              fex["_File.Ext"]  := _FileExt
              fex["_FilePath"]  := sFile
              fex["_FileSize"]  := A_LoopFileSize
              fex["_FileTimeA"] := A_LoopFileTimeAccessed
              fex["_FileTimeC"] := A_LoopFileTimeCreated
              fex["_FileTimeM"] := A_LoopFileTimeModified
          }              
        Break            
    }

  If Not ( _FileExt )                                   ;    Filepath not resolved
    {
        Return
    }        

  
  objShl := ComObjCreate("Shell.Application")
  objDir := objShl.NameSpace(_Dir) 
  objItm := objDir.ParseName(_FileExt) 
                                                                
  If ( VarSetCapacity(xDetails) = 0 )                           ;     Init static variable
    {
        i:=-1,  xDetails:={},  xDetails.SetCapacity(309)
        
        While ( i++ < 309 )
          {
            xDetails[ objDir.GetDetailsOf(0,i) ] := i
          } 

        xDetails.Delete("")
    }

  If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) )        ;  File isn't desired kind  
    {
        Return
    }

  i:=0,  nParams:=p.Count(),  fex.SetCapacity(nParams + 11) 

  While ( i++ < nParams )
    {
        Prop := p[i]
        
        If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) )
          {
              fex[Prop] := objItm.ExtendedProperty(Prop)
              Continue 
          }
          
        If ( PropNum := xDetails[Prop] ) > -1
          {
              fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum)
              Continue 
          }  
    }
  
  fex.SetCapacity(-1)
Return fex  

}

Alternatively if you want a GUI approach you could drag all the mp3 files into Mp3Tag, sort by columns bitrate and VBR, select a range of files e.g. all with 128 kbs and use right click context menu action "move...".
« Last Edit: May 14, 2020, 01:26 PM by Nod5 »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #6 on: May 15, 2020, 04:26 AM »
Skwire, your Tags2Folders is about as close as they come.  Just need the additional token bitrate....

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #7 on: May 15, 2020, 04:40 AM »
Nod5, beautifully done.  Worked on sample set of mp3s. 

Before I try on actual collection I'll give it a few days to see if it works for others, or if you decide to make any refinements.

Thanks a million!

IainB

  • @Slartibartfarst
  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #8 on: May 15, 2020, 05:00 PM »
@nkormanik:
"Looking for a way to sort/organize mp3 files in a folder into a set of folders by bitrate:"

I don't think I understand the need for this question.

You would already have all you seem to need to do this on an ad hoc basis. The system knows all about what audio files you have and their properties and the file manager can be invoked to swiftly sort these as and when you require. I use xplorer² (it also lets you turn nested directories into a manageable virtual flat file), but I presume Windows file manager can do it also - since the system knows all about what files you have.

If you had a dynamically changing population of audio files though, and wanted to (say) periodically sort newcomers into the appropriate folders, then you could do so manually or automate via a macro, I suppose, but again, I'd do that in xplorer².

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #9 on: May 16, 2020, 01:44 AM »
the file manager can be invoked to swiftly sort these

If only.  Yes, in a small set of mp3 files, Explorer can show a column of bitrate values.  But in larger collections Explorer chokes.  One has to 'page down' for all the files, and even then....

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #10 on: May 16, 2020, 08:16 PM »
Skwire, your Tags2Folders is about as close as they come.  Just need the additional token bitrate....

Added in v1.1.2.  See here: https://www.donationcoder.com/forum/index.php?topic=19543.msg438418#msg438418

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #11 on: May 17, 2020, 01:53 AM »
You the man, Skwire.  Thanks so much.  Yes, creates a mess.  But, at least now possible.

And thanks Nod5.  Such amazing work.

Original address: https://www.donationcoder.com/forum/index.php?topic=49914.0