Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
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.
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. . .
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:
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.
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.
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.
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.
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).
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.