1

I want to automatically tag a collection of MP3 to become custom-name VA Albums. Currently, I'm using quite fail-safe commands like this one :

find . -name "*.mp3" -exec eyeD3 -A "Indie 2015" -b "Various Artists" {} \;

Now, I would like to add a running track number to the files. The most straightforward way would be the current match/line number in the find -exec command - is there such a command?

eyeD3 sets the track number by using -n NUM, --track NUM, so I'm searching for something like

find . -name "*.mp3" -exec eyeD3 -A "Indie 2015" -b "Various Artists" -n **FIND_MATCH_NUMBER** {} \;
user2707001
  • 1,543
  • 12
  • 13

2 Answers2

2

One option, using globstar (assuming that you do have files in nested subdirectories, which was why you were using find in the first place):

shopt -s globstar
n=1
for file in **/*.mp3; do
    eyeD3 -A "Indie 2015" -b "Various Artists" -n "$((n++))" "$file"
done

With globstar enabled, the **/*.mp3 glob expands to all files ending in .mp3 in the current directory, as well as in subdirectories. $((n++)) evaluates to the current value of the counter $n and then increments it.

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • Works like a charm, and I learned something, never came across the globstar option. Thanks a lot! --- What I had to do to make it work : brew install bash and /usr/local/Cellar/bash/4.3.33/bin/bash, with the "old" OSX bash it doesn't work out of the box... – user2707001 Apr 16 '15 at 21:27
0

Dont know if find have internal variable that can tell record number like NR in awk. You could have something like this in your program

[[ -f file ]] && read i < file
[[ -z $i ]] && let i++
echo $i
let i++
echo $i > file

for each file we have count you can use. file can be any temporary file.

  • Thank you for answering my question. I do not really understand your answer unfortunately out of-the-box - you mean then using xargs on file in the call to eyeD3? - In any case, I have a perfect answer above. Still, thanks for your time. – user2707001 Apr 16 '15 at 21:31