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
macaque33
  • 43
  • 2

3 Answers3

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.

celadon
  • 117
  • 9
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

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
don_crissti
  • 79,330
  • 30
  • 216
  • 245
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
Gilles Quénot
  • 31,569
  • 7
  • 64
  • 82