1 #! /bin/sh 2 3 # $NetBSD: id3db.sh,v 1.1 2007/04/15 15:22:44 agc Exp $ 4 # 5 # Copyright 2007 Alistair Crooks. All rights reserved. 6 # 7 # Redistribution and use in source and binary forms, with or without 8 # modification, are permitted provided that the following conditions 9 # are met: 10 # 1. Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # 2. Redistributions in binary form must reproduce the above copyright 13 # notice, this list of conditions and the following disclaimer in the 14 # documentation and/or other materials provided with the distribution. 15 # 3. The name of the author may not be used to endorse or promote 16 # products derived from this software without specific prior written 17 # permission. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 20 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 # 31 32 id3info=/usr/music/.id3info 33 id3db=/usr/music/.id3.db 34 35 db -w -C -E B btree $id3db 36 37 awk -v database=$id3db ' 38 /^Filename:/ { filename = $2 } 39 /^Title:/ { title = $2 } 40 /^Artist:/ { artist = $2 } 41 /^Album:/ { album = $2 } 42 /^Year:/ { year = $2 } 43 /^Genre:/ { genre = $2 " " $3 } 44 /^Track:/ { track = $2 } 45 /^Comment:/ { comment = $0 } 46 /^Directory/ { directory = $2 } 47 /^$/ { 48 if (artist == "") 49 artist = "Unknown" 50 if (year == "") 51 year = "Unknown" 52 if (genre == "") 53 genre = "Unknown" 54 s = sprintf("db -w -E B btree %s %ca%s/%s%c %c%s%c %cy%s/%s%c %c%s%c %cg%s/%s%c %c%s%c", 55 database, 56 39, directory, filename, 39, 39, artist, 39, 57 39, directory, filename, 39, 39, year, 39, 58 39, directory, filename, 39, 39, genre, 39); 59 system(s); 60 } 61 ' $id3info 62 63 exit 0 64