Wednesday, December 12, 2012

Scripting to reduce repetition.

There are things, simple things, that I don't know how people who can't write a script deal with. For example, setting ID3v2 tags on 100+ mp3s that compose an audiobook so that they sort correctly, etc. It is a very simple exercise using bash to pull this off, but by hand it seems like a pain.
#!/bin/bash

AUTH="Jim Butcher"
TITL="Cursors Fury"

Y=1
for x in `find . -name \*.mp3 |sort`
do
TEMPY=`printf "%03d" $Y`
id3v2 -a "$AUTH" -A "$TITL" -t "$TITL $TEMPY" -T $Y $x
Y=`expr $Y + 1`
done
Do the filenames happen to have spaces in them? Possibly the 'rename' command will help out.
rename 's/ /_/g'

No comments:

Post a Comment