3

I'd like to get a list of all mp3 files with >320 bitrate. I'm not sure, how to apply the regular expression to the output of exiftool -AudioBitrate command.

find . -type f -name '*.mp3' -print0 | while IFS= read -r -d '' i; do BITRATE=echo $(exiftool -AudioBitrate "$i")| grep -q '#([0-9]+) kbps#'; if $BITRATE > 320 then echo $BITRATE "$i" fi done 

3 Answers 3

2

Here is a bash script that works. It is basically what you have with a few tweaks:

#!/bin/bash set -o pipefail find . -type f -name "*.mp3" -print0 | while IFS= read -r -d '' file; do BITRATE=$(exiftool -AudioBitrate "$file" | grep -Eo '[0-9]+ kbps' | sed 's/ kbps//') if [[ $? -eq 0 ]] && [[ $BITRATE -ge 320 ]]; then echo $BITRATE "$file" fi done 

In setting the $BITRATE variable I run exiftool through a pipe directly and use $(...) to capture the output. Then, in the conditional I check if the exiftool -> grep pipe was successful and the bitrate is sufficiently high using Bash's numeric comparison operators.

I've checked that it handles some random .mp3 files I have lying around, including ones with spaces in the name.

1
  • Thanks! It works well Commented Feb 29, 2020 at 23:01
2

No need for all those tools...

exiftool -q -if '$AudioBitrate > 320' -p '$AudioBitrate $Directory/$Filename' -ext mp3 -r . 

exiftool searches recursively in the current directory, only files with mp3 extension, and prints the bitrate and filename if the condition $AudioBitrate > 320 is satisfied

1
  • 1
    Wow, nice ! Should be accepted answer Commented Dec 5, 2022 at 21:15
0

Simple and lazy way:

#!/bin/bash bitrateMin=320 find . -iname '*.mp3' -print0 | while IFS= read -r -d '' file; do [[ $(exiftool -AudioBitrate "$file" | awk -v br="$bitrateMin" '$4 >= br{print $4}') ]] && printf '%s\n' "$file" done 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.