3

I'm cleaning my music library and got stuck with getting rid of thousands of albums with bitrate <320kbps which gathered there for years. Checking single files bitrate and deleting whole folder by hand is realy tedious. Maybe someone here can come up with some idea which would help me with cleanup? I'd like to have after that only MP3s@320kbps and flacs. Thanks in advance!

6
  • 1
    Please give us an example of your folder structure. Are these all mp3 and flac files? Can we assume that the flac will have the right bitrate?
    – terdon
    Sep 29 '14 at 15:51
  • All albums are in one folder with single exceptions (which one may ommit - I'll cleanup them on my own). Flac files have right bitrate - one can ommit them, too. Sep 29 '14 at 16:02
  • Here is fragment from tree -R output: pastebin.com/HBugq48R Sep 29 '14 at 16:06
  • 2
    I would load them into an audio library manager, sort by bit rate and delete the part that's too low. Sep 29 '14 at 16:09
  • That's nice idea - I'll look for some. Sep 29 '14 at 16:12
3

Here's a shell approach. It will delete any directories that don't contain .mp3 files of the >= 320 kbps bitrate:

find /path/to/Music -type d -print0 | 
    while IFS= read -r -d '' dir; do 
     mp3=$(find "$dir" -type f -iname '*.mp3' | head -n 1); 
     [ -e "$mp3" ] && [[ $(mp3info -x "$mp3" | grep -oP '\d+(?=\s*kbps)') -lt 320 ]] && 
            rm -rf "$(dirname "$mp3")"; 
    done

Notes

  • This will remove any directories that contain at least one mp3 file with a bitrate less than 320. If another file exists in the same directory with the right bitrate, that will be deleted as well. This approach assumes that all files in a directory have the same bitrate.

  • This will miss files of variable bitrate.

  • It should work with any type of file name, including those with spaces, newlines or even backslashes.

  • You might need to install mp3info: sudo apt-get install mp3info

  • Run it on a test directory first.

Explanation

  • find /path/to/Music -type d -print0 : find all directories under /path/to/Music and print them separated by the null string. This is needed to deal with strange file names.

  • while IFS= read -r -d '' dir; do : go through each of the results of find, saving them in the $dir variable.

  • mp3=$(find "$dir" -type f -iname '*.mp3' | head -n 1); : save the name of the first mp3 file in this directory as $mp3.

  • [ -e "$mp3" ] : if this file exists. This is needed for skipping directories with no mp3 files.

  • [[ $(mp3info -x "$mp3" | grep -oP '\d+(?=\s*kbps)') -lt 320 ]] : this checks the bitrate of $mp3. It runs mp3info, greps the bitrate and checks if it is less than 320.

  • rm -rf "$(dirname "$mp3")"; : delete the directory that contains the mp3 file. This will only be run if its bitrate is less than desired.

1
  • That's the answer I was expecting. Sep 30 '14 at 4:55
2

From @DavidFoerster's comment I would use Banshee.

Import all your media files from the folder's (or even whole partitions) you want by going to media->import media and choose folders.

Once all your media has been imported, right click on the column bar (shown below in the screenshot) and select Bitrate. Then click on the column name to order by that column.

You can then select the Bitrate you want (in your case 320) scroll down, press Shift and click the last song. Then right click on the selected songs and choose Delete from Drive.

enter image description here

2
  • But it'll left empty folders, won't it? Sep 29 '14 at 16:29
  • 1
    Yah. I think you better ask another question for that.
    – Parto
    Sep 29 '14 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.