ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Sort/organize mp3 files by bitrate, into folders

<< < (2/3) > >>

Nod5:
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 ---#NoEnvSendMode InputSetWorkingDir %A_ScriptDir%#SingleInstance forceListLines, OffSetBatchLines, -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 norecurse := 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 loopif (sourcefolder = destinationfolder)  recurse := 0 ; recursively loop sourcefolder for mp3 files and move to a destinationfolder subfolderLoop, 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 DONEsleep 2000ExitApp   ; 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/jyXFo9LocalStatic 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...".

nkormanik:
Skwire, your Tags2Folders is about as close as they come.  Just need the additional token bitrate....

nkormanik:
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:
@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:
the file manager can be invoked to swiftly sort these
-IainB (May 15, 2020, 12:00 PM)
--- End quote ---

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....

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version