script to disc-at-once extract audio books with cdparanoia


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to disc-at-once extract audio books with cdparanoia
# 8  
Old 09-29-2011
Quote:
Originally Posted by iconoclast hero
So the $1+0 actually adds the initial number on the line? If it was 139ab5, $1+0 would be 139? It just goes through and changes n each time it encounters a number, stops at each . and then when it gets to the end, TOTAL does nothing? So watching n as it went through, it would be "0" for the first 7 lines, then it would proceed through each integer, 1-18, and remain at 18 for the last line?
Correct.

The idea in this case is to set n with each successive leading number. It assumes that the numbers as presented by the source will increase. It is a bit tricky, and a more obvious way of writing it might be along these lines:

Code:
cdparanoia -Q 2>&1| awk '
$1 ~/[0-9]+/ {     # if first token begins with a digit
   if( $1+0 > n )    # if this is the largest we've seen
      n = $1+0;    # capture it
} 
END {print n}'

You'll find with awk there are lots of ways to do the same thing.
# 9  
Old 10-06-2011
Ok... so here is what I have for the ripping:
Code:
#!/bin/bash

END=$(cdparanoia -Q 2>&1| awk ' $1+0 > 0 {   		# when the first field converted to a number is greater than 0
   n = $1+0; 						# save the first field as a number in variable n
   next;      						# continue processing with next line of input (not required for this case, but good form)
     }

END {     						# execute this code after the last line of input has been processed
   print n}')  						# print the value of n to standard output


cdparanoia 1-$END $1.wav
lame --abr 16 -mm -a "$1.wav" "$1.mp3"
rm $1.wav
eject cdrom
sox "$1.mp3" -t mp3 1.4/"$1.mp3" tempo 1.4 &

This rips to a .wav specified by $1, converts it to an mp3, deletes the .wav then advances the tempo of the .mp3 by 1.4x and saves both .mp3s.

So what I was hoping to do was to automate things a bit and call this as a subroutine in a script that would auto rename the files as I ripped each disc. I think I got it working with this:
Code:
#!/bin/bash
FILE=$1
num=1

while [ $num -lt 10 ]
do
	if [ -f $FILE"0"$num.mp3 ];
	then
	   echo "File $FILE"0"$num exists"
	
	else
	   echo "File $FILE"0"$num does not exist"
	   ./rip $FILE"0"$num
                exit
	fi
num=$[$num +1]
done

while [ $num -ge 10 ]
do
#echo "second loop $num"
	if [ -f $FILE$num.mp3 ];
	then
	   echo "File $FILE$num exists"

	else
	   echo "File $FILE$num does not exist"
	   ./rip $FILE$num
	   exit
	fi
num=$[$num +1]
done
echo "done"

unfortunately, if I want to use my standard format for file names which is "Title -- Disc ##.mp3", I can't get it to work with
Code:
#!/bin/bash
FILE=$1
num=1

while [ $num -lt 10 ]
do
	if [ -f $FILE' -- Disc 0'$num.mp3 ];
	then
	   echo "File $FILE" -- Disc 0"$num exists"
	
	else
	   echo "File $FILE" -- Disc 0"$num does not exist"
	   ./rip $1' -- Disc 0'$num
	fi
num=$[$num +1]
done

while [ $num -ge 10 ]
do
#echo "second loop $num"
	if [ -f $FILE$num.mp3 ];
	then
	   echo "File $FILE$num exists"

	else
	   echo "File $FILE$num does not exist"
	   ./rip $FILE$num
	   exit
	fi
num=$[$num +1]
done
echo "done"

Forgetting of course that I haven't updated the second while loop for an input such as Freddy and Fredericka as my $1.

a) what can I clean up from my first attempt at sequentially numbering file names and
b) how can I get it to use the $1 of something like Freddy and Fredricka ?
c) how do I put my ./rip script in as a subroutine and call it? just name it and put it in {}s?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

Neo's Recommended Audio Books

Just finished this Audible audio book. It's simply great. Highly recommended: This book was so well done that I did not want to miss a single word; so ended up listening to half of the book twice when I got distracted. This is a great audio book. ... (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

The Start Of A Simple Audio Scope Shell Script...

This is a DEMO shell script to generate a simple graticule and plot inside it... Apologies for any typos... it is another building block along with my other two shell uploads recently to start a semi_serious project of an Terminal_AudioScope... The fist upload I posted recently was to show... (83 Replies)
Discussion started by: wisecracker
83 Replies

3. Shell Programming and Scripting

Need a script for automation the convert a lot number audio files to another format

I have a lot number audio files in the MP3 proprietary format, I want to convert them to 'opus' the free and higher quality format, with keep metadata also. My selection command-line programs are SoX (Sound eXchange) for convert MP3 files to 'AIFF' format in order to keep quality and metadata*... (1 Reply)
Discussion started by: temp-usr
1 Replies

4. OS X (Apple)

Python script to do simple audio capture...

This site is the first to get this snippet. It will capture an audio recording of any time length within the limits of OSX's QuickTime Player's capablility... A shell script derivative of this will be used as a further capture for CygWin's AudioScope.sh. Thoroughly read ALL the comments in... (0 Replies)
Discussion started by: wisecracker
0 Replies

5. Slackware

Problems with audio recording in Audacity 2.0.5. Slackware64 14.1; Intel HD Audio.

I'm trying to record audio using Audacity 2.0.5 installed from SlackBuilds. My system is 64-bit Slackware 14.1 and a sound card is Intel HD Audio. I didn't change my sound system to OSS. (Default sound system in Slackware 14.1 is ALSA, isn't it?) First, I set Internal Microphone slider in KMix... (2 Replies)
Discussion started by: qzxcvbnm
2 Replies

6. Shell Programming and Scripting

Error with Audio Conversion Bash Script

Good evening, I'm currently working on a BASH script to convert audio between file formats and I've come across a snag. At the beginning of the script, I'm having the system check to see if any files with the .m4a extension exist in the directory, and if so, it runs the script. If there are no... (1 Reply)
Discussion started by: KBurkholder
1 Replies

7. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

8. Shell Programming and Scripting

Books for Shell Script and UNIX

Hi i am new to UNIX completely. i dont know any thing about UNIX. can some one please help me with some books on the unix archetecture and all the internal working of UNIX OS (i want to know every thing about unix from basics) and shell programming. can any one please if available provide... (1 Reply)
Discussion started by: amiman
1 Replies

9. Solaris

Ultra 10 - Copying Files From Disc After Booting Up With Recovery Disc?

Hello, I'm still learning unix and I have what is probably a simple question but I can't seem to find the question to. I have an Ultra 10 Sparc Server running solaris 8 and the drive may have crashed (I hope not). Currently, it appears some files in the /etc folder are missing. I have a backup... (1 Reply)
Discussion started by: ideffects
1 Replies
Login or Register to Ask a Question