topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 5, 2024, 8:39 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Sort/organize mp3 files by bitrate, into folders
« on: May 13, 2020, 07:55 AM »
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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #1 on: May 13, 2020, 09:28 AM »
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: 554
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #2 on: May 13, 2020, 08:08 PM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #3 on: May 13, 2020, 09:02 PM »
Add the four lines needed to create the folder, and change the Remove-Item line to Move-Item.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #4 on: May 14, 2020, 02:17 AM »
4wd, please elaborate?

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #5 on: May 14, 2020, 07:53 AM »
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 [Select]
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. ; sort mp3 files into folders based on bitrate and if they are VBR or not
  4. ; AutoHotkey script
  5. ; by nod5
  6. ; 2020-05-14
  7.  
  8. ; ---------------------------------------
  9. ; folder with mp3 files that we want to sort move
  10.  
  11. sourcefolder      := "C:\some\folder"
  12.  
  13. ; also recurse in sourcefolder? 1 means yes, 0 means no
  14. recurse := 1
  15.  
  16. ; target folder where we want the files to end up in subfolders
  17. ; for example VBR files go to \VBR subfolder, 128kbs CBR files got to \128 subfolder
  18.  
  19. destinationfolder := "D:\this other\location"
  20.  
  21. ; ---------------------------------------
  22.  
  23. ; disable recurse if in/out folders are same, to avoid endless loop
  24. if (sourcefolder = destinationfolder)
  25.   recurse := 0
  26.  
  27. ; recursively loop sourcefolder for mp3 files and move to a destinationfolder subfolder
  28. Loop, Files, % sourcefolder "\*.mp3", % recurse ? "R" : ""
  29. {
  30.   ; get audio properties as object
  31.   ; we need these two properties:
  32.   ; System.Audio.EncodingBitrate      examples: 128000 (which is 128kbs), 320000, 263704, ...
  33.   ; System.Audio.IsVariableBitRate    value -1 if VBR otherwise value 0
  34.   Props := ["System.Audio.IsVariableBitRate", "System.Audio.EncodingBitrate"]
  35.   obj := Filexpro(A_LoopFilePath,, Props*)           ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
  36.  
  37.   ; if VBR then move to subfolder "\VBR"
  38.   if (obj["System.Audio.IsVariableBitRate"] = "-1")
  39.     subfolder := "VBR"
  40.   else
  41.   {
  42.     ; else move CBR to matching bitrate folder, for example "\128"
  43.     ; get bitrate in kbs, for example 128000 -> 128
  44.     subfolder := SubStr(obj["System.Audio.EncodingBitrate"],1,-3)
  45.   }
  46.   if subfolder
  47.   {
  48.     if !FileExist(destinationfolder "\" subfolder)
  49.       FileCreateDir, % destinationfolder "\" subfolder
  50.     FileMove, % A_LoopFilePath, % destinationfolder "\" subfolder
  51.   }
  52. }
  53. ToolTip DONE
  54. sleep 2000
  55.  
  56.  
  57.  
  58. ; function: Filexpro
  59. ; get extended properties from file
  60. ; by SKAN 2018-12-11
  61. ; https://www.autohotkey.com/boards/viewtopic.php?t=59882
  62.  
  63. Filexpro( sFile := "", Kind := "", P* ) {           ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
  64. Local
  65. Static xDetails
  66.  
  67.   If ( sFile = "" )
  68.     {                                                           ;   Deinit static variable
  69.         xDetails := ""
  70.         Return
  71.     }
  72.  
  73.   fex := {}, _FileExt := ""
  74.  
  75.   Loop, Files, % RTrim(sfile,"\*/."), DF
  76.     {
  77.         If not FileExist( sFile:=A_LoopFileLongPath )
  78.           {
  79.               Return
  80.           }
  81.  
  82.         SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv
  83.  
  84.         If ( p[p.length()] = "xInfo" )                          ;  Last parameter is xInfo
  85.           {
  86.               p.Pop()                                           ;         Delete parameter
  87.               fex.SetCapacity(11)                               ; Make room for Extra info
  88.               fex["_Attrib"]    := A_LoopFileAttrib
  89.               fex["_Dir"]       := _Dir
  90.               fex["_Drv"]       := _Drv
  91.               fex["_Ext"]       := _Ext
  92.               fex["_File"]      := _File
  93.               fex["_File.Ext"]  := _FileExt
  94.               fex["_FilePath"]  := sFile
  95.               fex["_FileSize"]  := A_LoopFileSize
  96.               fex["_FileTimeA"] := A_LoopFileTimeAccessed
  97.               fex["_FileTimeC"] := A_LoopFileTimeCreated
  98.               fex["_FileTimeM"] := A_LoopFileTimeModified
  99.           }              
  100.         Break            
  101.     }
  102.  
  103.   If Not ( _FileExt )                                   ;    Filepath not resolved
  104.     {
  105.         Return
  106.     }        
  107.  
  108.  
  109.   objShl := ComObjCreate("Shell.Application")
  110.   objDir := objShl.NameSpace(_Dir)
  111.   objItm := objDir.ParseName(_FileExt)
  112.                                                                
  113.   If ( VarSetCapacity(xDetails) = 0 )                           ;     Init static variable
  114.     {
  115.         i:=-1,  xDetails:={},  xDetails.SetCapacity(309)
  116.        
  117.         While ( i++ < 309 )
  118.           {
  119.             xDetails[ objDir.GetDetailsOf(0,i) ] := i
  120.           }
  121.  
  122.         xDetails.Delete("")
  123.     }
  124.  
  125.   If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) )        ;  File isn't desired kind  
  126.     {
  127.         Return
  128.     }
  129.  
  130.   i:=0,  nParams:=p.Count(),  fex.SetCapacity(nParams + 11)
  131.  
  132.   While ( i++ < nParams )
  133.     {
  134.         Prop := p[i]
  135.        
  136.         If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) )
  137.           {
  138.               fex[Prop] := objItm.ExtendedProperty(Prop)
  139.               Continue
  140.           }
  141.          
  142.         If ( PropNum := xDetails[Prop] ) > -1
  143.           {
  144.               fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum)
  145.               Continue
  146.           }  
  147.     }
  148.  
  149.   fex.SetCapacity(-1)
  150. Return fex  
  151.  
  152. }

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, 08:26 AM by Nod5 »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #6 on: May 14, 2020, 11:26 PM »
Skwire, your Tags2Folders is about as close as they come.  Just need the additional token bitrate....


nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #7 on: May 14, 2020, 11:40 PM »
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

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #8 on: May 15, 2020, 12: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: 554
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #9 on: May 15, 2020, 08:44 PM »
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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #10 on: May 16, 2020, 03: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: 554
    • View Profile
    • Donate to Member
Re: Sort/organize mp3 files by bitrate, into folders
« Reply #11 on: May 16, 2020, 08:53 PM »
You the man, Skwire.  Thanks so much.  Yes, creates a mess.  But, at least now possible.

And thanks Nod5.  Such amazing work.