id3info.sh revision 1.1 1 1.1 agc #! /bin/sh
2 1.1 agc
3 1.1 agc # $NetBSD: id3info.sh,v 1.1 2007/04/15 15:22:44 agc Exp $
4 1.1 agc #
5 1.1 agc # Copyright 2007 Alistair Crooks. All rights reserved.
6 1.1 agc #
7 1.1 agc # Redistribution and use in source and binary forms, with or without
8 1.1 agc # modification, are permitted provided that the following conditions
9 1.1 agc # are met:
10 1.1 agc # 1. Redistributions of source code must retain the above copyright
11 1.1 agc # notice, this list of conditions and the following disclaimer.
12 1.1 agc # 2. Redistributions in binary form must reproduce the above copyright
13 1.1 agc # notice, this list of conditions and the following disclaimer in the
14 1.1 agc # documentation and/or other materials provided with the distribution.
15 1.1 agc # 3. The name of the author may not be used to endorse or promote
16 1.1 agc # products derived from this software without specific prior written
17 1.1 agc # permission.
18 1.1 agc #
19 1.1 agc # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 1.1 agc # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 1.1 agc # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 agc # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 1.1 agc # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 agc # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 1.1 agc # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 agc # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 1.1 agc # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 1.1 agc # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 1.1 agc # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 agc #
31 1.1 agc
32 1.1 agc # set defaults
33 1.1 agc roots=/usr/music
34 1.1 agc infofile=/usr/music/.id3info
35 1.1 agc append=false
36 1.1 agc
37 1.1 agc # function to trawl through a directory to grab id3 tags from each file
38 1.1 agc # relies on id3 utility to do this
39 1.1 agc dodir() {
40 1.1 agc (cd $1 &&
41 1.1 agc for f in *; do
42 1.1 agc if [ -f $f ]; then
43 1.1 agc id3 -l -R $f >> $infofile
44 1.1 agc echo "Directory: $2" >> $infofile
45 1.1 agc elif [ -d $f ]; then
46 1.1 agc dodir $f $2/$f
47 1.1 agc fi
48 1.1 agc done)
49 1.1 agc }
50 1.1 agc
51 1.1 agc # argument processing
52 1.1 agc while [ $# -gt 0 ]; do
53 1.1 agc case $1 in
54 1.1 agc --append) append=true
55 1.1 agc ;;
56 1.1 agc --roots=) roots=$(echo $1 | sed -e 's|--roots=||')
57 1.1 agc ;;
58 1.1 agc --infofile=) infofile=$(echo $1 | sed -e 's|--infofile=||')
59 1.1 agc ;;
60 1.1 agc esac
61 1.1 agc shift
62 1.1 agc done
63 1.1 agc
64 1.1 agc # sort out whether we'll append or start afresh
65 1.1 agc if $append; then
66 1.1 agc echo "Appending to file $infofile"
67 1.1 agc else
68 1.1 agc rm -f $infofile
69 1.1 agc touch $infofile
70 1.1 agc fi
71 1.1 agc
72 1.1 agc # grab all the id3 info
73 1.1 agc for d in $roots; do
74 1.1 agc dodir $d $d
75 1.1 agc done
76 1.1 agc
77 1.1 agc exit 0
78