0

I'm looking for a simple shell command that analyses all flac files in a folder and deletes all files that have a lower bitrate than 950kbps. Now I have to fire up Clementine, browse to the folder, sort the files and delete manually. That's all I use Clementine for, which is overkill I think. Thanks a lot

1 Answers1

0

To my knowledge there is no simple command to carry out such an operation. However a small script that browses the files in a folder can do the trick.

First thing first, we need a command line utility to get the bit rate of the files. I use mediainfo (mediainfo package on Debian). Other utilities can also do the job very well. Once installed, the following script lists all the FLAC files in the folder with a bit rate lower than 950 kbps.

#!/usr/bin/env sh

for flacfile in .flac; do [ $(mediainfo "$flacfile" | grep 'Bit rate' | grep -oi '[0-9].[0-9]' | sed 's/\s//g') -lt 950 ] && echo "$flacfile"
done

If it suits you, just replace the echo command by the rm command to proceed the file deletion:

#!/usr/bin/env sh

for flacfile in .flac; do [ $(mediainfo "$flacfile" | grep 'Bit rate' | grep -oi '[0-9].[0-9]' | sed 's/\s//g') -lt 950 ] && rm "$flacfile"
done

Explanation

  • the for loops browses all the .flac files in the directory;
  • mediainfo displays all the information about the FLAC file and gives it to the first grep command;
  • the first grep selects the bit rate line and gives it to the second grep;
  • the second grep selects in this line only the numbers. The . in [0-9].[0-9]* deals with space thousand separator (in 1␣050 for example);
  • sed removes the space thousand separator if needed;
  • finally [ ... -lt 950 ] checks if the bit rate is less than 950 kbps and if it is true the rm command removes the file.