LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-15-2004, 10:42 PM   #1
krock923
Member
 
Registered: Jul 2004
Posts: 171

Rep: Reputation: 30
CDDB in script?


Hi, I'm working on a script to automatically rip my audio cd's to mp3. So far, I'm able to rip + encode + normalize the songs. however, they're being saved with names like track01, track02, etc. Is there a way to query CDDB from within this? This is the first script i've ever done so if you know of a way can you please explain it for me? Thanks a lot!

Code:
echo Enter path to save files
read PH
cd $PH
mkdir ./new
cd ./new
cdparanoia -B 
rename .cdda.wav .wav *.cdda.wav
for i in $( ls *.wav ); do
            notlame -b 256 -q 0 $i
done
rename .wav.mp3 .mp3 *.wav.mp3
for j in $( ls *.mp3 ); do
	mp3gain -r -k $j
done
rm -f *.wav
mv ./* $PH
cd ..
rmdir ./new
 
Old 10-16-2004, 03:07 AM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
If you have to do it in bash, look up www.cddb.com for details on how to query the database, and grab a copy of cddbcmd.

If you're not averse to python, you can grab and modify a script I pasted for another guy here http://www.linuxquestions.org/questi...hreadid=240935. The script uses flac and oggenc rather than lame, but it would be easy to change.
 
Old 10-16-2004, 05:26 PM   #3
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Well, if i had to do it from a premade script, I guess I would, but I'd rather not. This is partially an exercise in scripting for me. I don't understand where I'd go from here. I suppoe i'd either need to get (or possibly make) some other program to lookup the info once i get the discid? It's not like it can be done with bash the way it is, right? So, does anyone here know what they're doing? Because I don't.
 
Old 10-16-2004, 07:24 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
No, you can't use bash alone to query cddb, if that's what you're asking. That's not what bash scripting is for. I kind of resent the implication that I don't know what I'm doing, seeing as I already wrote a script that does this AND told you what you needed to do if you didn't want to use that script.

If you install cd-discid and cddbcmd, this will give you the disc details.
Code:
DISCID=$(cddbcmd cddb query `cd-discid /dev/cdrom` | cut -f 1-2 -d' ') && cddbcmd cddb read $DISCID
 
Old 10-16-2004, 08:43 PM   #5
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Sorry if you got the wrong impression. I didn't say at all that you didn't know what you were doing. I just said that I was trying to learn and asked you for help.
 
Old 10-16-2004, 09:04 PM   #6
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Sorry dude, I have not slept properly all weekend, so I'm a bit messed up and took what you said too personally... don't mind me.
 
Old 10-17-2004, 10:31 AM   #7
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
HIi again. When I tried the line that you gave me, I got this error message: Command code 500: Command syntax error.

I went to freedb.org and found that the command cddb read had to be categ discid.

I see that your script did that by removing everything but the first and second entries from the query response using the cut command. I didn't understand why it wasn't working so I wrote this. . .

Code:
DISCID=$( discid )
cddbcmd -m http -p 10.1.1.2:808 cddb query $DISCID
CATEG=$( cddbcmd -m http -p 10.1.1.2:808 cddb query $DISCID | cut -f 1 )
cddbcmd -m http -p 10.1.1.2:808 cddb read $CATEG $DISCID
I think it does the exact same thing yours did, but it still gave me the error message. (I changed the -m and -p because this computer is behind a proxy.) Any ideas of why it wouldn't be working. It seems to do it exactly the way freedb.org specifies.

Thanks for all of your help btw.

edit// i fixed part of the problem by using a space as the field seperator instead of the colon so now i really don't understand why it won't work. new script:

Code:
DISCID=$( discid )
cddbcmd -m http -p 10.1.1.2:808 cddb query $DISCID > query.txt
CATEG=$( cut -d ' ' -f 1 ./query.txt )
cddbcmd -m http -p 10.1.1.2:808 cddb read $CATEG $DISCID

Last edited by krock923; 10-17-2004 at 10:56 AM.
 
Old 10-17-2004, 01:34 PM   #8
mpn
Member
 
Registered: Oct 2004
Distribution: Slackware 10.2
Posts: 33

Rep: Reputation: 15
This might be useful to you:

http://mpn.ath.cx/goofyheadedpunk/misc/bash/ripit

It queries cddb and rips to ogg. Since he used cdmp3 with an --ogg flag I imagine you can easily modify it to rip to mp3s.
 
Old 10-17-2004, 03:57 PM   #9
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
The problem may be that DISCID includes more than just the serial number - it has number of tracks and some extra info on the end. The cddb query command needs this extra info, but the cddb read command doesn't like it.
 
Old 10-17-2004, 06:58 PM   #10
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Thanks. Got it working now by taking the serial number from the query command and feeding it to the read command. all that's left is to set it up to write the lame tags automatically from the cd data file. I should be able to figure that out. Thanks for your help. I learned a lot.
 
Old 11-02-2004, 08:22 AM   #11
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Sigh, I can admit when I can't figure out how to do something. I have the text file that cddb sends back from a query. . .

Code:
# xmcd CD database file
# Copyright (C) 2001 CDDB, Inc.
#


# Track frame offsets:
#	150
#	22043
#	45851
#	64978
#	88713
#	108122
#	134045
#	156544
#	176947
#	200033
#	228147
#	254903
#


# Disc length: 3630
#


# Revision: 8
# Processed by: cddbd v1.4.2PL1 Copyright (c) 1996-2000 CDDB Inc.
# Submitted via: CDDB2_Bridge 1.0
#


DISCID=b60e2b0c
DTITLE=Creed / Human Clay
TTITLE0=Are You Ready
TTITLE1=What If
TTITLE2=Beautiful
TTITLE3=Say I
TTITLE4=Wrong Way
TTITLE5=Faceless Man
TTITLE6=Never Die
TTITLE7=With Arms Wide Open
TTITLE8=Higher
TTITLE9=Wash Away Those Years
TTITLE10=Inside Us All
TTITLE11=Young Grow Old
EXTD=mp3 - cdda\n\n\n\nOctober 18, 1999 \n\n  \n\nCreed\n\nHuman Clay\n\n(
EXTD=Wind-Up)\n\n\n\nCreed's highly anticipated second album is vivid proo
EXTD=f that the Florida quartet's knack for striking grungy, charismatic p
EXTD=oses hasn't abated a bit since it struck quadruple-platinum pay dirt 
EXTD=with its 1997 debut. \n\n\n\nThese tunes all bristle with the same cr
EXTD=unchy guitars, churning rhythms, and raspy angst that drove Creed (no
EXTD=t to mention kindred spirits like Third EyeBlind and Matchbox 20) to 
EXTD=Soundscan success. \n\n\n\nFrontman Scott Stapp hammers home his calc
EXTD=ulatedly unaffected sentiments in a voice that falls somewhere betwee
EXTD=n Joe Cocker, Alice in Chains' Layne Staley and Motorhead main man Le
EXTD=mmy Kilmister but without achieving the focused, gut-level impact of 
EXTD=those singers. \n\n\n\nDespite the enthusiasm with which he tackles t
EXTD=opics like spurned love and carefully veiled religious themes, there 
EXTD=are few tracks where feeling and form meet equally. Mark Tremonti is 
EXTD=an agile guitarist, and his gripping riffs, moody reverberating lines
EXTD= and stinginglicks add a distinct stylistic edge to the pedestrian ha
EXTD=rd-rock numbers,but in mellower moments ("Never Die"), even his most 
EXTD=skillful ambient flourishes can't keep the tunes from meandering off 
EXTD=track. \n\n\n\nCreed is most vulnerable during power ballads, not bec
EXTD=ause the songs actually reveal anytender emotional insights, but beca
EXTD=use they blatantly expose the group'sreal soft spot: its songwriting.
EXTD= \n\n\n\nTechnically, the guys in Creed are adept players and when th
EXTD=e songwriting works, and they pull out the stops("Higher," "What If")
EXTD=, they pull off some reasonably compelling music. But ultimately, Hum
EXTD=an Clay feels like passion by numbers.
EXTT0=
EXTT1=
EXTT2=
EXTT3=
EXTT4=
EXTT5=
EXTT6=
EXTT7=
EXTT8=
EXTT9=
EXTT10=
EXTT11=
PLAYORDER=
However, when I try to extract the track names from it, using the cut command, using = as the delimiter and using a variable with the number of tracks in the field option, the cut command doesn't honor the field option. It spits back everything after equal signs. Am I doing something wrong with the syntax of the cut command? I suspect the real problem is that bash wasn't really designed to do this and I should be using a real programming language and just do it in C++, but I'm not great with C++ and now that I've been working on this for a while, would like to get it to work.

Code:
DISCID=$( discid )
cddbcmd -m http -p 10.1.1.2:808 cddb query $DISCID > query.txt
CATEG=$( cut -d ' ' -f 1 ./query.txt )
SERIAL=$( cut -d ' ' -f 2 ./query.txt)
cddbcmd -m http -p 10.1.1.2:808 cddb read $CATEG $SERIAL > cdinfo.txt
TRACKNUM=$( discid | cut -d ' ' -f 2)
#echo $TRACKNUM
cut -f2-$TRACKNUM -d '=' -s ./cdinfo.txt > title.txt
As far as the ripping and encoding, I have a seperate script to do that and i'll combine the two later. I just want to get the info for the ID3 tags that I will somehow pass to lame. Ugh.

Last edited by krock923; 11-02-2004 at 08:24 AM.
 
Old 11-03-2004, 02:09 AM   #12
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
The cut command is giving you exactly what you ask for - everything after an equal sign on any line that has an equal sign (this includes blank lines everywhere a line ends in an equal sign). You might want to consider something like this to trim the lines to just the titles:
Code:
grep TTITLE cdinfo.txt | cut -f2 -d=
Also, C++ is definitely overkill for this sort of thing - bash and the command line tools are definitely capable of performing this task, but if you want a language to make it easier, look at perl, python, or ruby. These three languages are excellent for those shell-script type jobs that seem to be just that little bit more complicated than you'd like. They seem to cover the range of brain patterns out there, so chances are if you have a look at all three, you will find that one really appeals to you (for me, that would be python).
 
Old 11-03-2004, 07:58 PM   #13
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
I promise that I'll stop bugging you after this, I don't want to try and leech of you.

I have what I thought would work (while extremely unelegant and using a million temporary text files, i was pretty proud as this was my first script I ever wrote), it works fine up until the encoding. It crashes there. Does lame have a problem with variables? I'm thikning that maybe spaces in the variables are messing things up.

Code:
echo Enter path to save files
read PH
cd $PH
mkdir ./new
cd ./new
cdparanoia -B 
rename .cdda.wav .wav *.cdda.wav
DISCID=$( discid )
cddbcmd -m http -p 10.1.1.2:808 cddb query $DISCID > query.txt
CATEG=$( cut -d ' ' -f 1 ./query.txt )
SERIAL=$( cut -d ' ' -f 2 ./query.txt)
cddbcmd -m http -p 10.1.1.2:808 cddb read $CATEG $SERIAL > cdinfo.txt
TRACKNUM=$( discid | cut -d ' ' -f 2)
#echo $TRACKNUM
grep TITLE cdinfo.txt > title.txt
sed '1d' title.txt > title1.txt
cut -d '=' -f2-"$TRACKNUM" -s title1.txt > list.txt
grep DTITLE cdinfo.txt > altitle.txt
ALTITLE=$( cut -d '/' -f2 -s altitle.txt )
cut -d '=' -f2 -s altitle.txt > artist.txt
ARTIST=$(cut -d '/' -f1 -s artist.txt)
for i in $( ls *.wav ); do
TRACKTITLE=$( sed q list.txt )
sed '1d' list.txt > newlist.txt
rename newlist.txt list.txt newlist.txt
sed 's/TTITLE//' title1.txt > title2.txt
sed = list.txt | sed 'N;s/\n/\t/' > newlist1.txt
cut -f1 newlist1.txt > tracknums.txt
TRACKNUMBER=$( sed q tracknums.txt)
sed '1d' title1.txt > title3.txt
rename title3.txt title1.txt title3.txt
notlame --preset standard -tt"$TRACKTITLE" -ta "$ARTIST" -tl "$ALTITLE" -tn "$TRACKNUMBER" $i
done
rename .wav.mp3 .mp3 *.wav.mp3
for j in $( ls *.mp3 ); do
	mp3gain -r -k $j
done
rm -f *.wav
rm -f *.txt
mv ./* $PH
cd ..
rmdir ./new
I'm going to figure this out eventually.
 
Old 11-03-2004, 08:16 PM   #14
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Wow. I'm a moron. The id3 tag options require 2 dashes. A case of RTFM in my case, read it a bit more closely.
 
Old 11-03-2004, 08:49 PM   #15
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Don't worry, everyone misreads a man page at some time or another

As for your script, if it does what you need and no-one else will ever use it, then ugly is only a side effect I would use variables more and avoid the temporary files, but that's just a personal preference. I would advise against the rm wildcards though - you have a defined set of files that you create, so just delete those explicitly (maybe set a $CLEANUP variable with all names).

Oh, and if you get the urge to clean the script up - make a copy of the working one first! This is the best advice you will ever read
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CDDB in Linux mstep Linux - Software 10 12-24-2015 09:17 AM
Kaffeine and cddb steffendenize Linux - Software 0 11-04-2005 01:41 AM
grip problem with CDDB Mistreated Linux - Software 2 02-09-2005 10:34 AM
XMMS freezing with CDDB Wynd Linux - Software 0 02-03-2004 08:18 PM
Cddb Ztyx Linux - General 2 11-29-2002 01:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration