3 # Copyright (C) 1999 Nathaniel Smith <njs@uclink4.berkeley.edu>
4 # Copyright (C) 1999, 2000, 2001 Robert Woodcock <rcw@debian.org>
5 # Copyright (C) 2003, 2004 Jesus Climent <jesus.climent@hispalinux.es>
6 # This code is hereby licensed for public consumption under either the
7 # GNU GPL v2 or greater, or Larry Wall's Artistic License - your choice.
9 # You should have recieved a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software
11 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13 # Copyright for this work is to expire January 1, 2010, after which it
14 # shall be public domain.
17 # - Add more error checking
20 # - Not much error checking, esp. of arguments
21 # - Submitted via: line is created by template, when it really should be in send.
28 BAD_SYNTAX_ERR
=10 # invalid CDDB file
29 NO_TMP_ERR
=11 # can't create a temp file
30 NO_MATCH_ERR
=12 # try submitting one
31 LOOKUP_ERR
=13 # problem connecting to cddb server
32 EMPTY_QUERY_RESPONSE
=14 # query response = "", (probably no net connection)
34 # assume a reasonable default if $HTTPGET is undefined
35 if [ "$HTTPGET" = "" ]; then
36 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
38 HTTPGETOPTS
=${HTTPGETOPTS:="-q -o -"}
39 elif [ X
"$(uname)" = X
"Darwin" ] ; then
41 HTTPGETOPTS
=${HTTPGETOPTS:="-f -s"}
44 HTTPGETOPTS
=${HTTPGETOPTS:="-q -O -"}
48 HTTPGET
="$HTTPGET $HTTPGETOPTS"
52 $NAME version $VERSION
55 $0 template disc-id tracks
57 $0 read server proto user host disc-id genre
58 $0 query server proto user host disc-id tracks
59 $0 stat serverurl user host proto
66 $NAME version $VERSION
67 A toolbox for doing cddb related stuff
69 Usage: $0 command [command_options]
73 Get data out of a cddb file - dumps to stdout in a form
74 source'able by the shell
77 Mails a CDDB file to a specified address, using correct format.
78 Category should be one of blues, classical, country, data, folk,
79 jazz, newage, reggae, rock, soundtrack, or misc.
80 template disc-id tracks
81 Generates a template (empty) cddb file to stdout. The command
82 line should be essentially the output of cd-discid.
83 query server proto user host disc-id tracks
84 Looks up disc on server (should be of form "http://host/~cddb/cddb.cgi")
85 remainder of command line is in the same form as that returned
86 by the cd-discid program.
87 read server proto user host disc-id genre
88 CDDB file is dumped to stdout. File will contain an extra
89 #CATEGORY= line, which leaves it a valid CDDB file but which will
90 be recognized by parse and send commands. Uses wget, so if you
91 need to use a proxy then just configure wget to do so. user and
92 host will be used for identifying ourselves to the CDDB server.
93 stat serverurl user host proto
94 Check server status with given protocol. This can be used to check
95 if the server supports given protocol. Most common values for proto
96 should be 5 and 3. With 3 you will not get DYEAR and DGENRE fields
106 while [ $i -ne `expr $2 + 1` ]
116 parse
) # takes 1 argument, a filename, and dumps out a sh parseable version
120 # names chosen to match usage in abcde code
121 DISCID
=$
(grep ^DISCID
= "$CDDBFILE" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
122 DARTISTALBUM
=$
(grep ^DTITLE
= "$CDDBFILE" | cut
-f2- -d= |
tr -d \\n |
sed 's- / -~-g' |
tr -d \
[:cntrl
:\
])
123 DARTIST
=$
(echo "$DARTISTALBUM" | cut
-f1 -d~ |
sed 's,\\,\\\\,g;s,\([\"\$\`]\),\\\1,g' |
tr -d \
[:cntrl
:\
])
124 DALBUM
=$
(echo "$DARTISTALBUM" | cut
-f2 -d~ |
sed 's,\\,\\\\,g;s,\([\"\$\`]\),\\\1,g' |
tr -d \
[:cntrl
:\
])
125 CDDBGENRE
=$
(grep '^#CATEGORY=' "$CDDBFILE" | cut
-f2- -d= |
tr -d \
[:cntrl
:\
])
126 if grep "^DYEAR" "$CDDBFILE" 2>&1 > /dev
/null
; then
127 CDYEAR
=$
(grep "^DYEAR" "$CDDBFILE" | cut
-f2- -d= |
tr -d \
[:cntrl
:\
])
128 elif grep YEAR
"$CDDBFILE" 2>&1 > /dev
/null
; then
129 CDYEAR
=$
(grep "YEAR" "$CDDBFILE" |
grep -v "DYEAR" |
awk 'BEGIN{FS="YEAR:"}{print $2}' |
awk '{print $1}')
133 CDGENRE
=$
(grep '^DGENRE=' "$CDDBFILE" | cut
-f2- -d= |
tr -d \
[:cntrl
:\
])
136 echo DISCID
="\"$DISCID\""
137 echo DALBUM
="\"$DALBUM\""
138 echo DARTIST
="\"$DARTIST\""
139 echo CDDBGENRE
="\"$CDDBGENRE\""
140 echo CDYEAR
="\"$CDYEAR\""
141 echo CDGENRE
="\"$CDGENRE\""
142 NUMTRACKS
=$
(grep -E '^TTITLE[0-9]+=' "$CDDBFILE" |
wc -l)
144 while [ "$CURRTRACK" -lt $NUMTRACKS ]; do
145 CURRTRACKM1
=$CURRTRACK # Track minus 1 (cddb numbers from 0)
146 CURRTRACK
=$
(expr $CURRTRACK + 1)
147 echo -n "TRACK${CURRTRACK}=\""
148 grep ^TTITLE
${CURRTRACKM1}= "$CDDBFILE" | cut
-f2 -d= |
sed 's,\\,\\\\,g;s,\([\"\$\`]\),\\\1,g' |
tr -d \
[:cntrl
:\
]
156 echo '# xmcd CD database file'
158 echo '# Track frame offsets:'
160 for x
in $
(f_seq
3 $
(expr $NUMTRACKS + 2))
162 printf "#\t$(echo "$DISCID" | cut -f$x -d' ')\n"
165 LENGTH
=$
(echo "$DISCID" | cut
-f$x -d' ')
167 echo "# Disc length: $LENGTH seconds"
169 echo "# Submitted via: $NAME $VERSION"
171 echo "#blues,classical,country,data,folk,jazz,newage,reggae,rock,soundtrack,misc"
172 echo "#CATEGORY=misc"
173 echo DISCID
="$DISCNUM"
174 echo "DTITLE=Unknown Artist / Unknown Album"
178 for x
in $
(f_seq
1 $NUMTRACKS)
180 echo "TTITLE$(expr $x - 1)=Track $x"
184 for x
in $
(f_seq
1 $NUMTRACKS)
186 echo "EXTT$(expr $x - 1)="
191 send
) # cddb-tool send filename email@address
194 DISCID
=$
(grep ^DISCID
= "$FILE" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
195 CDDBGENRE
=$
(grep '^#CATEGORY=' "$FILE" | cut
-f2- -d= |
tr -d \
[:cntrl
:\
])
196 grep -v "^#CATEGORY=" "$FILE" |
mail -s "cddb $CDDBGENRE $DISCID" "$ADDRESS"
199 query
) # cddb-tool query serverurl proto user host discid...
204 HELLOINFO
="$USER+$HOST+$NAME+$VERSION"
207 TRACKINFOPLUS
=$
(echo $TRACKINFO |
tr ' ' '+')
208 RESULTS
=$
($HTTPGET "$SERVER?cmd=cddb+query+$TRACKINFOPLUS\&hello=$HELLOINFO\&proto=$PROTO") ||
exit $LOOKUP_ERR
209 echo $RESULTS |
tr '\r' '\n' |
tr -s '\n' |
sed 's/^ //g'
212 read) # cddb-tool read serverurl proto user host genre discnumber
219 HELLOINFO
="$USER+$HOST+$NAME+$VERSION"
220 $HTTPGET $CDDBDATA "$SERVER?cmd=cddb+read+$CATEGORY+$DISCID\&hello=$HELLOINFO\&proto=$PROTO" 2>/dev
/null
223 stat
) # cddb-tool stat serverurl user host proto
228 HELLOINFO
="$USER+$HOST+$NAME+$VERSION"
229 $HTTPGET $CDDBDATA "$SERVER?cmd=stat&hello=$HELLOINFO\&proto=$PROTO" 2>/dev
/null