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