#!/bin/sh # RipEnc 2.6a for BeOS # Scot Hacker, beos@birdhouse.org 08/00 # With contributions from many members of the BeOS community # Updates at http://www.bebits.com/app/94 # See readme.html for details # Default settings RipEncRC=/boot/home/config/settings/ripencrc EncodeDir=/boot/home RawPath=/dev/disk/ide/atapi/0/slave/0/raw BitRate=160 OutputFreq=44.1 OutputFormat=j VBR=n VBRQuality=4 AllTracks=y ThisGenre=Blues ThisYear=0 NamingConvention=17 UseTemplate=y PlayWhenDone=n OpenTracker=y Comment="_" AlertType=2 PlaylistDir=/boot/home SavePlaylist=n PlaylistMIME=text/x-playlist QueryVolume=/boot OutputType=MP3 Encoder=gogo UseExtension=y VariousArtists=n ArtistFirst=y # Read in program settings from last time user saved prefs if [ -f "$RipEncRC" ]; then . "$RipEncRC" fi # Check to see if id3ren is installed. Offer to download if not. if ! type -p id3ren; then echo echo "id3ren does not appear to be installed on this machine." echo "It should have been installed along with RipEnc." echo "You may have moved it out of your path or renamed it." echo "Without id3ren, your MP3 files won't get ID3 tags." echo "press D to download the latest version of id3ren now." echo "Press any other key to continue." echo read downloadid3ren if [ "$downloadid3ren" = "d" ] || [ "$downloadid3ren" = "D" ]; then NetPositive http://www.bebits.com/app/552/ # Return to start by invoking BuildMenu BuildMenu else echo "Continuing without id3ren." fi fi ############## # Make sure indices are properly installed. # We'll cheat and assume that if they don't have # Audio:Album, they don't have any. AudioIndex=$(lsindex | grep "Audio:Album") if [ "$AudioIndex" == "" ]; then OK=$(alert "This appears to be the first time you've run RipEnc. Is it okay to add and/or modify MP3 indexes to your filesystem? If you don't understand this question, it's safe to click Yes. These indexes are useful not just for RipEnc, but for BeOS audio in general. Adding them will allow you to search for newly created MP3s by artist, title, year, etc. If previously created indexes of the same name are found, they will not be modified." "No" "Yes") if [ "$OK" = "No" ]; then alert "Indexes were neither added nor modified. You can do this manually later with the mkindex command if you want. Be sure that your Audio:Year index is an integer, not a string!" else mkindex Audio:Album mkindex Audio:Artist mkindex Audio:Comment mkindex Audio:Genre mkindex Audio:Title mkindex -t int Audio:Year alert "Six indexes added (if you didn't have them already)." fi fi ############## # Script itself is one giant function, called from menu item "b" Encode() { # Clean up from the last usage of RipEnc. # We do this at the start of the script # rather than at the end in case the user # quit with Ctrl+C during the last usage. # For future reference: # tracks.txt lists the numbered tracks on disc. Unsorted. # ripfiles.txt is just filenames (no numbers) in the CD's wav dir. Sorted. # selectfiles.txt momentarily holds user selection from ripfiles # cdlist.txt lists numbered raw CD devices for auto-detection routine # cddev.txt lists un-numbered raw CD devices for auto-detection routine if [ -f /tmp/ripfiles.txt ]; then rm /tmp/ripfiles.txt fi if [ -f /tmp/selectfiles.txt ]; then rm /tmp/selectfiles.txt fi if [ -f /tmp/tracks.txt ]; then rm /tmp/tracks.txt fi if [ -f /tmp/cddev.txt ]; then rm /tmp/cddev.txt fi if [ -f /tmp/cdlist.txt ]; then rm /tmp/cdlist.txt fi # Check to see if selected encoder is installed. echo echo "Encoder currently selected in Setup is: \"$Encoder\"." echo if ! type -p $Encoder; then echo echo "The $Encoder encoder does not appear to be installed on this machine." echo "You can choose between encoders in the Setup menu, which will also" echo "help you download an encoder (GoGo is recommended for most users)." echo echo -n "Press Enter to return to menu."; read BuildMenu else echo echo "Good. $Encoder is installed on this machine." echo fi # Get the CD volume name. # Use the df command, which shows names of all mounted volumes. # We locate the only one with "cdda" as the filesystem type. ThisCD=$(df | grep $RawPath | grep cdda) # Now that we've checked to see if "cdda" appears in the list of # mounted filesystems, we can error out if no CD has been mounted. if [ ! "$ThisCD" ]; then echo echo No audio CD found in selected drive. echo Are you sure you\'ve mounted one\? echo Right-click on Desktop and choose your CD echo from the Mount submenu. echo echo Use option D in Setup to auto-detect echo your CD-ROM drive. echo echo -n "Hit Enter to continue" read # Return to menu BuildMenu fi # Now assuming CD has been mounted, so we'll trim the string # down to size with bash's pattern matching. ThisCD=${ThisCD/cdda*/} ThisCD=$(echo "$ThisCD" | sed s@^/@@g | sed s@\ \$@@g) echo echo Quick check for stray space characters from CDDB... # Check to see if CD volume has a double space in it - some of them come # from CDDB that way, and screw everything up. We also need # to remove and any extra spaces at the end. In a minute, we're # going to rename the volume with the cleaned up name, so use # a NewCD variable to swap with. Hopefully this will work in all cases. NewCD=$(echo "$ThisCD" | sed s@\ \ @\ @g | sed s@^/@@g | sed s@\ *\$@@g) if [ "$NewCD" != "$ThisCD" ]; then [ -d "$ThisCD" ] && mv "$ThisCD" "$NewCD" ThisCD="$NewCD" fi echo This CD is now called \"$ThisCD\" # Check to see if any of the track titles end with spaces and rename them. # Yup, they come from CDDB this way and it screws up more stuff. for i in /"$ThisCD"/wav/* ; do cleantrack=$(echo "$i" | sed s@\ *\$@@g) if [ "$i" != "$cleantrack" ]; then [ -f "$i" ] && mv "$i" "$cleantrack" fi done # Check to see if we've made a successful cddb lookup. We do this by # checking to see if the string "Audio CD" shows up in the volume name # and then trimming it, since it contains a bunch of weirdo spaces. VolName=$(echo "$ThisCD" | grep -w "Audio\ CD" | sed s/CD.*$/CD/g) # Error correction in case we don't get the cddb lookup. # The CD volume won't have an artist - album hyphen and we therefore # need to compensate for all the extra spaces in "Audio CD ". # These spaces are an artifact of the way df sets tabular output. if [ "$VolName" == "Audio CD" ]; then ThisCD="Audio CD" fi # Throw a warning so user can decide how to proceed if [ "$VolName" == "Audio CD" ]; then echo echo " ***WAIT!!!***" echo echo "This CD has not been successfully looked up" echo "in an online database. This means that either:" echo echo "o You haven't installed or are not running cddblinkd" echo "o You're not connected to the Internet" echo "o This is a rare CD which wasn't found in any database." echo echo "You should probably stop and wait for a successful lookup. When" echo "lookup is complete, \"Audio CD\" on your desktop will" echo "automatically be renamed to \"Artist Name - Album Name\"." echo echo "If you are running cddblinkd and still can't get a lookup," echo "use the Tracker to rename the CD volume as specified above" echo "and rename the tracks in the WAV directory to match the" echo "actual track names." echo echo "You may want to recompile cddblinkd to query a different database." echo "See cdda-fs: Guarantee successful lookups at" echo "http://www.betips.net/cgi-bin/chunga.pl?ID=tip433" echo echo "If you choose to continue, the album or songs will be" echo "encoded with generic track names." echo echo "If you're unsure what cddblinkd is," echo "see readme.html in the installation folder." echo echo "[R]=Return to main menu" echo "[C]=Continue without looking up CD" read continue # If users chooses c or C, proceed without lookup. # Otherwise, return to main menu. if [ "$continue" == "c" ] || [ "$continue" == "C" ]; then echo echo "Continuing without database lookup." echo else BuildMenu fi fi # Time to get the artist and album names # We use the variable ThisArtistMain rather than just ThisArtist # because we want to be able to handle compilation CDs, where we # run into a conflict between ThisArtist as interpreted for the # 1) folder naming and in regular CD handling, and # 2) ThisArtist where it changes for each track, as happens on a compilation CD. # This way we can use the exact variant of the variable later on, # when differentiating between folder, ID3 tag, attribute, and filename artist entries. ThisArtistMain=$(echo "$ThisCD" | sed s/\ -\ .*$//g) ThisAlbum=$(echo "$ThisCD" | sed s/^.*\ -\ //g) # Check to see if the artist directory already exists; if not, create it. if [ ! -d "$EncodeDir/$ThisArtistMain" ]; then mkdir "$EncodeDir/$ThisArtistMain" fi # Check to see if the album directory already exists; if not, create it. # If folder templates is enabled, copy attributes from the template directory. if [ ! -d "$EncodeDir/$ThisArtistMain/$ThisAlbum" ]; then mkdir -p "$EncodeDir/$ThisArtistMain/$ThisAlbum" if [ "$UseTemplate" = "y" ]; then # Copy attributes from the template directory. copyattr ~/config/settings/Tracker/DefaultQueryTemplates/audio_x-mpeg "$EncodeDir/$ThisArtistMain/$ThisAlbum" echo echo "MP3 folder template copied to destination." fi fi # Simplify the working path for future use WorkingDir="$EncodeDir/$ThisArtistMain/$ThisAlbum" # Get an output name for the playlist Playlist="$ThisArtistMain - $ThisAlbum.m3u" # Create a list of tracks to rip (start with all) # Each track on the mounted volume has an Audio:Track attribute. # If we don't extract this attribute, our list will be alphabetical. # It takes a bit of time to create this list, but it's the only way # to have the track list correspond to the CD jacket. It also lets # us offer a NamingConvention including the track#. We extract the # track title and number for each file in the dir, hack it down to # just the info we need, dump to a temp file, and sort that file. # The -n flag makes sort put #11 after #10, rather than after #1, etc. echo echo Building track list. Hang on... echo # Loop through each WAV on the disc and give it a name. for i in /"$ThisCD"/wav/*; do #*/ # Trim the TrackNum and ThisTrack variables and # write a final list of tracks to be encoded. TrackNum=$(catattr Audio:Track "$i" | sed s/\ \:\ /%/g | cut -f3 -d\%) ThisTrack=$(catattr Audio:Track "$i" | sed s/\ \:\ /%/g | cut -f1 -d\% | sed s/^.*\\/wav\\///g) echo $TrackNum\] "$ThisTrack" >> /tmp/tracks.txt done # Sort tracks.txt numerically and dump to ripfiles.txt sort -n /tmp/tracks.txt > /tmp/ripfiles.txt # If AllTracks is set to "y", all we have to do # is remove the digits from the start of each # line in the ripfile. if [ "$AllTracks" == "y" ]; then cat /tmp/ripfiles.txt | sed s/^.*\\]\ //g >> /tmp/selectfiles.txt mv -f /tmp/selectfiles.txt /tmp/ripfiles.txt echo Encoding all tracks from: $ThisCD: echo cat /tmp/ripfiles.txt echo fi # If AllTracks is set to "n", we create a track chooser. # This assigns a number to each track. User types in # the appropriate numbers and we grep the ripfile for # occurences of those numbers at the beginning of lines. # If found, we strip the number from that line # and copy it to another temp file. When the new # temp file is done, we replace ripfile with it. if [ "$AllTracks" == "n" ]; then echo echo Available tracks on "$ThisCD" echo cat /tmp/ripfiles.txt echo echo Enter numbers for the tracks you echo want to encode, separated by spaces. echo read -a TrackPicks for z in "${TrackPicks[@]}"; do grep "^$z"\\] /tmp/ripfiles.txt | sed s/^$z\\]\ //g >> /tmp/selectfiles.txt done mv -f /tmp/selectfiles.txt /tmp/ripfiles.txt fi # Sanity check for VariousArtists mode if [ "$VariousArtists" == "y" ] || [ "$VariousArtists" == "Y" ]; then echo echo "Warning: You are in various artists / compilation CD mode." echo "If you're encoding a normal CD, tracks will be tagged and" echo "attributed incorrectly." echo echo "To switch to normal mode now, press \"n\"." echo "Press any other key to continue in various artists mode." read Normal if [ "$Normal" == "n" ]; then VariousArtists=n fi fi # Now encode and tag each file in the list { while read ThisTrack; do # If this is a compilation / various artists CD, we need to # further parse ThisTrack because normal CDs have just the track # names in the WAV directory, while compilation CDs have both the # track and artist names in each filename in that dir. Earlier in # the script we distinguished between ThisArtist and ThisArtistMain, # so we don't have namespace conflicts between the folder naming # and the separate artists found on compilation CDs. We also have to # be careful that the right artist strings goes in the right places # in the tags, attributes, and filenames. This turned out to be # trickier than I thought it would be, especially because some compilations # come down from cddb with "Artist Name - Track Name" and others do it # the other way around. We'll work with either format here. if [ "$VariousArtists" == "y" ] || [ "$VariousArtists" == "Y" ]; then if [ "$ArtistFirst" == "1" ]; then # Files in wav dir are "Artist Name - Track Name" ThisArtistVar=$(echo "$ThisTrack" | sed s/\ -\ .*//g) ThisTrackVar=$(echo "$ThisTrack" | sed s/^.*\ -\ //g) ActualTrackName="$ThisTrackVar" else # Files in wav dir are "Track Name - Artist Name" ThisTrackVar=$(echo "$ThisTrack" | sed s/\ -\ .*//g) ThisArtistVar=$(echo "$ThisTrack" | sed s/^.*\ -\ //g) ActualTrackName="$ThisTrackVar" fi else # Handle regular CDs ThisArtistVar="$ThisArtistMain" ActualTrackName="$ThisTrack" ThisTrackVar="$ThisTrack" fi echo echo ================================================ echo Encoding track: "$ActualTrackName" echo ================================================ echo #Invoke NameIt function to get track naming convention NameIt # Routine to set attributes is in an independent function # so that both MP3 and Ogg routines can use the same code. SetAttributes() { echo echo "Copying audio attributes to $OutputName..." echo addattr -t string Audio:Album "$ThisAlbum" "$WorkingDir/$OutputName" addattr -t string Audio:Artist "$ThisArtistVar" "$WorkingDir/$OutputName" addattr -t string Audio:Title "$ThisTrackVar" "$WorkingDir/$OutputName" addattr -t string Audio:Comment "$Comment" "$WorkingDir/$OutputName" addattr -t string Audio:Genre "$ThisGenre" "$WorkingDir/$OutputName" addattr -t int Audio:Year "$ThisYear" "$WorkingDir/$OutputName" copyattr -n Audio:Length /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" copyattr -n Audio:Track /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" addattr -t string Audio:Bitrate "$BitRate kbit" "$WorkingDir/$OutputName" addattr -t string Audio:Frequency "$OutputFreq kHz" "$WorkingDir/$OutputName" } # Separate routines for MP3 and Ogg files if [ "$OutputType" == "Ogg" ]; then VorbisEncoder /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" SetAttributes else # We need a section for each possible encoder, and within those, one line each for VBR on or off # (although blade doesn't do VBR) #gogo if [ "$Encoder" == "gogo" ]; then if [ "$VBR" == "y" ]; then gogo -b $BitRate -m $OutputFormat -d $OutputFreq -v $VBRQuality /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" else gogo -b $BitRate -m $OutputFormat -d $OutputFreq /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" fi fi #lame if [ "$Encoder" == "lame" ]; then if [ "$VBR" == "y" ]; then lame -h -m $OutputFormat -s $OutputFreq -v -V $VBRQuality -b $BitRate -h /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" else lame -h -m $OutputFormat -s $OutputFreq -b $BitRate -h /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" fi fi #blade if [ "$Encoder" == "bladeenc" ]; then bladeenc -quit -crc -br $BitRate /"$ThisCD"/wav/"$ThisTrack" "$WorkingDir/$OutputName" fi if [ "$OutputType" == "MP3" ]; then # Set the MIME type for MP3 settype -t audio/x-mpeg "$WorkingDir/$OutputName" # Set the ID3 tags # changed by grahams 8/08 id3ren -nocfg -tagonly -song "$ActualTrackName" -album "$ThisAlbum" -artist "$ThisArtistVar" -year $ThisYear -comment "$Comment" -track $TrackNum -genre "$ThisGenre" "$WorkingDir"/"$OutputName" else # Set the MIME type for Ogg settype -t audio/x-ogg "$WorkingDir/$OutputName" fi # Invoke SetAttributes function SetAttributes fi # Add file to playlist if that's enabled if [ $SavePlaylist == "y" ]; then echo "$WorkingDir/$OutputName" >> "$PlaylistDir/$Playlist" fi echo echo Next file... done } < /tmp/ripfiles.txt # Get user's attention if [ $AlertType == "2" ]; then beep fi if [ $AlertType == "3" ]; then alert "MP3 encoding complete" fi if [ $AlertType == "4" ]; then beep alert "MP3 encoding complete" fi # If OpenTracker is enabled, launch output folder in Tracker if [ $OpenTracker == "y" ]; then /system/Tracker "$WorkingDir" fi # If SavePlaylist is enabled, set type of playlist properly if [ $SavePlaylist == "y" ]; then settype -t $PlaylistMIME "$PlaylistDir/$Playlist" fi # If PlayWhenDone is enabled, pass playlist to Tracker (play the list) if [ $PlayWhenDone == "y" ]; then /system/Tracker "$PlaylistDir/$Playlist" fi } #################################### # Establish output naming convention NameIt() { # We'll need to know the track number for many of these naming conventions. # Get this by grepping tracks.txt and removing everything *but* the track num. # We also invoke the CorrectTrackNumber function, which # inserts a zero before track numbers with only one digit. TrackNum=$(grep "$ThisTrack"$ /tmp/tracks.txt | sed s/\\].*$//g) CorrectTrackNumber # The filename extension depends on whether OutputType is Ogg or MP3 # and whether extensions are disabled in Setup if [ "$OutputType" == "Ogg" ]; then ext=".ogg" else ext=".mp3" fi if [ "$UseExtension" == "n" ]; then ext="" fi # Get the actual naming convention. # Using a case statement here is cleaner and faster # than the old if/then statements. case $NamingConvention in 1) OutputName=$(echo "$TrackNum - $ThisArtistVar - $ActualTrackName$ext") ;; 2) OutputName=$(echo "$TrackNum - $ThisArtistVar - $ThisAlbum - $ActualTrackName$ext") ;; 3) OutputName=$(echo "$TrackNum - $ActualTrackName$ext") ;; 4) OutputName=$(echo "[$TrackNum] $ActualTrackName$ext") ;; 5) OutputName=$(echo "$ThisArtistVar - $ActualTrackName$ext") ;; 6) OutputName=$(echo "$ThisArtistVar--$ActualTrackName$ext" | tr ' ' '_') ;; 7) OutputName=$(echo "$ThisArtistVar - $ThisAlbum - $ActualTrackName$ext") ;; 8) OutputName=$(echo "$ThisArtistVar - $ActualTrackName - $TrackNum$ext") ;; 9) OutputName=$(echo "$ThisArtistVar - $TrackNum - $ActualTrackName$ext") ;; 10) OutputName=$(echo "$ThisAlbum - $ThisArtistVar - $ActualTrackName$ext") ;; 11) OutputName=$(echo "$ThisAlbum - $ActualTrackName$ext") ;; 12) OutputName=$(echo "$ActualTrackName$ext") ;; 13) OutputName=$(echo "$ActualTrackName$ext" | tr 'A-Z' 'a-z') ;; 14) OutputName=$(echo "$ActualTrackName$ext" | tr ' ' '_' | tr 'A-Z' 'a-z') ;; 15) OutputName=$(echo "$ThisArtistVar-$ThisAlbum-$TrackNum-$ActualTrackName$ext" | tr ' ' '_' | tr 'A-Z' 'a-z') ;; 16) OutputName=$(echo "$ThisArtistVar - $ThisAlbum - [$TrackNum] - $ActualTrackName$ext") ;; 17) OutputName=$(echo "$ThisArtistVar - $ThisAlbum - $TrackNum - $ActualTrackName$ext") ;; esac } CorrectTrackNumber() { if [ "${#TrackNum}" = "1" ]; then TrackNum=$(echo 0$TrackNum) fi } BuildMenu() { while [ "$MENU" != "23" ] ; do clear echo "RipEnc version 2.6a for BeOS" echo echo "Y) Year.............["$ThisYear"]" echo "G) Genre............["$ThisGenre"]" echo "C) Comment..........["$Comment"]" echo echo "O) Options" echo "Q) Quality" echo "S) Setup" echo echo "L) Create playlist from query" echo echo "P) Save preferences" echo "X) Exit" echo "B) Begin encoding" echo -n "? " ; read MENU case $MENU in y|Y) echo echo "Enter the year this album was recorded." echo "If no year is entered, 0 will be used." echo read ThisYear # Year cannot be blank or id3ren chokes if [ "$ThisYear" = "" ] ; then ThisYear=0 fi if [ "$ThisYear" = " " ] ; then ThisYear=0 fi ;; g|G) echo id3ren -showgen echo -n Enter a genre by number: ; read ThisGenre ThisGenre=$(id3ren -searchgen $ThisGenre) ;; c|C) echo echo "Enter a comment for this album." echo "ID3 tags will be truncated at 30 characters," echo "but corresponding attributes can be of unlimited length." echo "If you leave this blank, RipEnc will use an underscore (_)." echo read Comment # Comment field cannot be blank or id3ren chokes # Yes, id3ren has a -nocomment option, but if we start using that, # we'll have to have a ton of different id3ren lines, one for each # possible combination of -nocomment, -nogenre, and -noyear. # Therefore RipEnc just forces you to use something in each field. # If you can think of a more elegant way to handle this, let me know. if [ "$Comment" == "" ] || [ "$Comment" == " " ]; then Comment="_" fi ;; b|B) # Start the engines Encode ;; p|P) # Save all settings echo EncodeDir="\""$EncodeDir"\"" > "$RipEncRC" echo AllTracks="\""$AllTracks"\"" >> "$RipEncRC" echo RawPath="\""$RawPath"\"" >> "$RipEncRC" echo BitRate="\""$BitRate"\"" >> "$RipEncRC" echo OutputFreq="\""$OutputFreq"\"" >> "$RipEncRC" echo OutputFormat="\""$OutputFormat"\"" >> "$RipEncRC" echo ThisYear="\""$ThisYear"\"" >> "$RipEncRC" echo ThisGenre="\""$ThisGenre"\"" >> "$RipEncRC" echo NamingConvention="\""$NamingConvention"\"" >> "$RipEncRC" echo VBR="\""$VBR"\"" >> "$RipEncRC" echo VBRQuality="\""$VBRQuality"\"" >> "$RipEncRC" echo UseTemplate="\""$UseTemplate"\"" >> "$RipEncRC" echo PlayWhenDone="\""$PlayWhenDone"\"" >> "$RipEncRC" echo Comment="\""$Comment"\"" >> "$RipEncRC" echo AlertType="\""$AlertType"\"" >> "$RipEncRC" echo OpenTracker="\""$OpenTracker"\"" >> "$RipEncRC" echo PlaylistDir="\""$PlaylistDir"\"" >> "$RipEncRC" echo SavePlaylist="\""$SavePlaylist"\"" >> "$RipEncRC" echo PlaylistMIME="\""$PlaylistMIME"\"" >> "$RipEncRC" echo QueryVolume="\""$QueryVolume"\"" >> "$RipEncRC" echo OutputType="\""$OutputType"\"" >> "$RipEncRC" echo Encoder="\""$Encoder"\"" >> "$RipEncRC" echo UseExtension="\""$UseExtension"\"" >> "$RipEncRC" echo VariousArtists="\""$VariousArtists"\"" >> "$RipEncRC" echo ArtistFirst="\""$ArtistFirst"\"" >> "$RipEncRC" ;; x|X) # Buh-bye. exit ;; s|S) while [ "$SETUP" != "23" ] ; do clear echo echo "-+- Setup -+-" echo echo "O) MP3 output folder...................["$EncodeDir"]" echo "F) Playlist folder.....................["$PlaylistDir"]" echo "I) Playlist MIME type..................["$PlaylistMIME"]" echo "T) Use MP3 folder template?............["$UseTemplate"]" echo "X) Use filename extensions?............["$UseExtension"]" echo "Q) Query volume........................["$QueryVolume"]" echo "E) Encoder ............................["$Encoder"]" echo "D) Find CD-ROM device..................["$RawPath"]" echo echo "M) Return to main menu" echo echo -n "Enter choice: "; read SETUP case $SETUP in e|E) # Choose an encoder OldEncoder=$Encoder echo echo "Which MP3 encoder do you want to use?" echo "The encoder (or a link to it) must be installed in ~/config/bin." echo echo "G) GoGo" echo "L) LAME" echo "B) Blade" echo echo -n "Enter letter for choice: "; read Encoder if [ "$Encoder" == "g" ] || [ "$Encoder" == "G" ]; then Encoder=gogo if ! type -p $Encoder; then echo echo "$Encoder does not appear to be installed on your machine." echo echo "RipEnc will now open your web browser on a page that" echo "may appear in Japanese. Find the link on the page that says" echo "\"Version [whatever] for Be.\" Click that link. When the download" echo "is complete, move the gogo binary to /boot/home/config/bin." echo echo "Hit Enter when ready." read NetPositive http://homepage1.nifty.com/herumi/soft.html echo echo "RipEnc will now assume you've installed GoGo properly." echo "Press Enter to continue." read fi elif [ "$Encoder" == "l" ] || [ "$Encoder" == "L" ]; then Encoder=lame if ! type -p $Encoder; then echo echo "$Encoder does not appear to be installed on your machine." echo echo "RipEnc will now open NetPositive on a page from which you" echo "can download a LAME binary. If you want to make sure you" echo "have the latest version, download the LAME source code" echo "from http://www.sulaco.org/mp3/ . It compiles cleanly for BeOS -- " echo "just type \"make\" in the archive directory." echo "When the download is complete, move the lame binary to /boot/home/config/bin." echo echo "Hit Enter when ready." read NetPositive http://home.iae.nl/users/gertjan/be/ echo echo "RipEnc will now assume you've installed LAME properly." echo "Press Enter to continue." read fi elif [ "$Encoder" == "b" ] || [ "$Encoder" == "B" ]; then Encoder=bladeenc if ! type -p $Encoder; then echo echo "$Encoder does not appear to be installed on your machine." echo echo "RipEnc does not use Be's native version of blade, because it" echo "can't be used from the command line. There was once a blade" echo "binary on BeWare, but it never made it over to BeBits. You might" echo "have an old version or be able to find a copy floating around somewhere." echo "The blade source is at http://bladeenc.mp3.no/skeleton/sourcearchive.html" echo "but does not compile cleanly on BeOS. Let me know if you get it compiled" echo "and can host the port somewhere or get your changes folded into the source." echo "Also, note that bladeenc doesn't do VBR. If you choose VBR and use bladeenc," echo "you'll still get CBR files." echo echo "In other words, most users shouldn't bother with blade. Just use gogo or lame." echo echo "RipEnc will now assume you've installed bladeenc properly, so if you don't" echo "have it installed, be sure to go back and choose a different encoder." echo echo "Press Enter to continue." read fi else echo "Not a valid option, keeping previous encoder option." echo -n "Press Enter to continue."; read continue Encoder=$OldEncoder fi ;; d|D) # Detect CD-ROM TEMPDEVICE=$RawPath echo echo "Auto-detecting connected CD-ROM devices..." echo # Use the BeOS play command to get what we need. # grep its output for the device paths. # Last sed of line below makes it possible to handle enhanced CDs properly (thanks Jon Watte). play | grep "/dev" | sed s@\ @@g | sed -e s@raw\$@@ > /tmp/cddev.txt { # Create list of CD-ROM drives to choose from i=1 while read ThisDevice; do echo $i\) $ThisDevice i=$(expr $i + 1) done } < /tmp/cddev.txt > /tmp/cdlist.txt # Report back list of numbered devices cat /tmp/cdlist.txt echo echo "Your CD-ROM drive(s) are listed above." echo "Choose one from the list (you might have only one)" echo # User picks a device by number read DevNum # Make sure they didn't just enter a space or hit Return. if [ -z "$DevNum" ]; then echo "That is not a valid response. Please re-run CD-ROM " echo "device detection and choose a number from the list." echo "Hit Enter to continue." read continue BuildMenu fi # Check to see the number they entered is on the list. # This also checks to see that they didn't enter a letter. if grep ^$DevNum /tmp/cdlist.txt then echo else echo "That is not a valid response. Please re-run CD-ROM " echo "device detection and choose a number from the list." echo "Hit Enter to continue." read continue BuildMenu fi # Find this number in cdlist.txt and remove the number, # parenthesis, and space from the variable. We'll now have # a usable device path. RawPath=$(grep ^$DevNum /tmp/cdlist.txt | sed s/^$DevNum\)\ //) # In case of error... if [ ! -e $RawPath ] ; then echo $RawPath "does not exist...hit enter to continue" read continue RawPath=$TEMPDEVICE fi if [ "$RawPath" = "" ] ; then RawPath=$TEMPDEVICE fi ;; x|X) # Use filename extensions? echo echo "With this option enabled, MP3 files will be named with \".mp3\"" echo "on the end and Ogg files with \".ogg\". If disabled, files will" echo "have no filename extensions. This is fine for BeOS, but other" echo "operating systems will have problems identifying the files correctly." echo echo -n "Use filename extensions? (y/n): "; read UseExtension if [ "$UseExtension" != "n" ] && [ "$UseExtension" != "N" ]; then UseExtension=y fi ;; o|O) # MP3 Output folder TEMPSAVETO=$EncodeDir echo echo "Enter path to output folder." echo "Tip: You can drag a folder out of the Tracker and into this spot!" echo read EncodeDir if [ ! -d $EncodeDir ] ; then echo -n $EncodeDir "does not exist, create [y/n]? " read create if [ "$create" = "y" ] ; then mkdir $EncodeDir else EncodeDir=$TEMPSAVETO fi fi if [ "$EncodeDir" = "" ] then EncodeDir=$TEMPSAVETO fi ;; f|F) # Playlist folder TEMPSAVETO=$PlaylistDir echo echo -n "Enter path to playlist output folder: " read PlaylistDir if [ ! -d $PlaylistDir ] ; then echo -n $PlaylistDir "does not exist, create [y/n]? " read create if [ "$create" = "y" ] || [ "$create" = "Y" ] || [ "$create" = "yes" ] || [ "$create" = "YES" ] ; then mkdir $PlaylistDir else PlaylistDir=$TEMPSAVETO fi fi if [ "$PlaylistDir" = "" ] then PlaylistDir=$TEMPSAVETO fi ;; i|I) # Account for the three different playlist MIME types out there echo echo Select the preferred playlist MIME type for your system: echo echo "1) New SoundPlay or CL-Amp....(text/x-playlist)" echo "2) Old SoundPlay..............(text/x-soundplay-playlist)" echo "3) Old CL-Amp.................(text/x-cl-amp-playlist)" echo echo -n Enter number for choice: ; read PlaylistMIME if [ "$PlaylistMIME" = "1" ] ; then PlaylistMIME="text/x-playlist" elif [ "$PlaylistMIME" = "3" ] ; then PlaylistMIME="text/x-cl-amp-playlist" elif [ "$PlaylistMIME" = "2" ] ; then PlaylistMIME="text/x-soundplay-playlist" else echo "That is not a valid choice. Try again." echo "Hit Enter to continue" read fi ;; t|T) # Use folder template echo echo "Use MP3 Folder Template?" echo echo "Enabling this option will make sure the" echo "relevant MP3 attribute columns in the output" echo "folder are displayed, so you don't have to" echo "enable them manually later on. Disable this" echo "option only if encoding to a non-BFS volume." echo "(y is highly recommended for BeOS users)." echo echo -n "Use MP3 folder template? (y/n) : "; read UseTemplate if [ "$UseTemplate" == "y" ] || [ "$UseTemplate" == "Y" ]; then echo -n "Edit template folder? (y/n) : "; read EditTemplate if [ "$EditTemplate" == "y" ] || [ "$EditTemplate" == "Y" ]; then echo echo "Your template folder will now appear in the Tracker, showing a dummy MP3 file." echo "Adjust its columns or column widths by dragging column headers." echo "Turn attributes on or off by using the Attribute menu. Close the" echo "Tracker window when done. RipEnc will start using the new template immediately." echo "Press Enter to continue." read continue /system/Tracker /boot/home/config/settings/Tracker/DefaultQueryTemplates/audio_x-mpeg fi fi ;; q|Q) # Query volume (used by playlist generator) TEMPSAVETO=$QueryVolume echo echo -n "Enter path to query volume. Default is /boot: " read QueryVolume if [ ! -d $QueryVolume ] ; then echo -n $QueryVolume "does not exist. Using /boot." echo Hit Enter to continue read continue fi if [ "$QueryVolume" = "" ]; then QueryVolume=$TEMPSAVETO fi ;; m|M) BuildMenu ;; esac done ;; q|Q) while [ "$QUALITY" != "23" ] ; do clear echo echo "-+- Quality -+- " echo echo "I) Bitrate.............................["$BitRate"]" echo "F) Frequency...........................["$OutputFreq"]" echo "T) Method..............................["$OutputFormat"]" echo "V) Variable bitrate? (y/n).............["$VBR"]" echo echo "M) Return to main menu" echo echo -n "Enter choice: "; read QUALITY case $QUALITY in i|I) # Select bitrate TEMPBITRATE=$BitRate echo echo -n "Specify a bitrate in kbps, e.g. 64, 96, 128, 160, 192, 256, 320 : " read BitRate if [ "$BitRate" = "" ] ; then BitRate=$TEMPBITRATE fi ;; f|F) # Select frequency TEMPOUTPUTFREQ=$OutputFreq echo echo -n "Specify an output frequency in kHz, e.g. 11.025, 22.05, 44.1, 48 : " read OutputFreq if [ "$OutputFreq" = "" ] ; then OutputFreq=$TEMPOUTPUTFREQ fi ;; t|T) # Select encododing method TEMPOUTPUTFORMAT=$OutputFormat echo echo "Specify an encoding method, e.g. j=joint stereo, s=stereo, m=mono" echo "If unsure, use option \"j\". Hit Enter to leave unchanged." echo echo -n "Encoding method: "; read OutputFormat if [ "$OutputFormat" = "" ] ; then OutputFormat=$TEMPOUTPUTFORMAT fi ;; v|V) # Select VBR and VBR ratio echo -n "Use variable bitrate? (y/n)" read VBR if [ "$VBR" == "y" ]; then echo echo -n "VBR quality? (0=highest, 10=lowest) : " read VBRQuality fi ;; m|M) BuildMenu ;; esac done # End Quality submenu ################# ;; o|O) ################# # Start Options submenu while [ "$OPTIONS" != "23" ] ; do clear echo echo "-+- Options -+- " echo echo "V) Various Artists (compilation).......["$VariousArtists"]" echo "O) Output type (MP3 or Ogg)............["$OutputType"]" echo "N) Naming convention...................["$NamingConvention"]" echo "E) Encode entire CD? (y/n).............["$AllTracks"]" echo "L) Save playlist?......................["$SavePlaylist"]" echo "P) Play when done?.....................["$PlayWhenDone"]" echo "A) Alert when done (pick one)..........["$AlertType"]" echo "T) Show files in Tracker when done?....["$OpenTracker"]" echo echo "M) Return to main menu" echo echo -n "Enter choice: "; read OPTIONS case $OPTIONS in n|N) # Naming convention echo echo "Choose a naming convention." echo "\".ogg\" will be substituted for \".mp3\" if Ogg is enabled in Options." echo "No extension will be used if they're turned off in Setup." echo echo "1) TrackNumber - Artist Name - Track Name.mp3" echo "2) TrackNumber - Artist Name - Album - Track Name.mp3" echo "3) TrackNumber - Track Name.mp3" echo "4) [TrackNumber] Track Name.mp3" echo echo "5) Artist Name - Track Name.mp3" echo "6) Artist_Name--Track_Name.mp3" echo "7) Artist Name - Album - Track Name.mp3" echo "8) Artist Name - Track Name - TrackNumber.mp3" echo "9) Artist Name - TrackNumber - Track Name.mp3" echo echo "10) Album - Artist Name - Track Name.mp3" echo "11) Album - Track Name.mp3" echo echo "12) Track Name.mp3" echo "13) track name.mp3" echo "14) track_name.mp3" echo echo "15) artist-album-tracknum-trackname.mp3" echo "16) Artist Name - Album Name - [TrackNumber] - Track Name.mp3" echo "17) Artist Name - Album Name - TrackNumber - Track Name.mp3" echo echo -n Enter number for choice: ; read NamingConvention ;; e|E) # Encode entire CD? echo "Encode entire album? (y/n)" echo "If you choose \"n\" here, you'll be able to" echo "choose individual tracks to encode." read AllTracks ;; v|V) # Is this a various artists disc? echo echo -n "Is this a various artists / compilation CD? (y/n): "; read VariousArtists echo until [ "$VariousArtists" == "y" ] || [ "$VariousArtists" == "Y" ] || [ "$VariousArtists" == "n" ] || [ "$VariousArtists" == "N" ]; do echo echo "Invalid response." echo -n "Is this a various artists / compilation CD? (y/n): "; read VariousArtists echo done # Check to see if artist name or track name comes first in the wav directory if [ "$VariousArtists" == "y" ] || [ "$VariousArtists" == "Y" ]; then echo echo "Compilation CDs are typically registered in compact disc databases" echo "with one of the following formats. Look in the \"wav\" folder" echo "on the mounted CD and choose one of these formats:" echo echo "1) Artist Name - Track Name" echo "2) Track Name - Artist Name" echo echo -n "Enter number for choice: " ; read ArtistFirst until [ "$ArtistFirst" == "1" ] || [ "$ArtistFirst" == "2" ]; do echo echo "Invalid response." echo -n "Enter number for choice: " ; read ArtistFirst echo done fi ;; l|L) # Save playlist? echo echo "Create playlist when done?" echo echo "Playlists will be saved to the playlist folder" echo "specifed in Setup and can be launched automatically" echo "when encoding is complete." echo echo -n "Create playlist when done? (y/n): "; read SavePlaylist ;; p|P) # Play when done? echo echo "Play all tracks when done encoding?" echo "You must have the Save Playlist" echo "option enabled for this to work." echo echo -n "(y/n) : " read PlayWhenDone ;; a|A) # Alert when done echo echo Choose an "alert when done" option: echo echo "1) None" echo "2) Audible beep" echo "3) Pop up alert box" echo "4) Beep and alert box" echo echo -n Enter number for choice: ; read AlertType ;; o|O) # Output type echo echo "Output MP3 or Ogg/Vorbis files?" echo echo "If you don't know what Ogg/Vorbis is, see" echo "http://www.vorbis.com. You must have the Vorbis" echo "encoder or a link to it installed in ~/config/bin" echo "if you want to output Ogg files. Download" echo "Vorbis tools from http://www.bebits.com/app/1058." echo echo "1) MP3" echo "2) Ogg/Vorbis" echo echo -n Enter number for choice: ; read OutputType if [ "$OutputType" == "2" ]; then OutputType="Ogg" else OutputType="MP3" fi ;; t|T) # Show files in Tracker when done? echo echo -n "Show files in Tracker when done? (y/n): "; read OpenTracker ;; m|M) BuildMenu ;; esac done # End Options submenu ################# ;; l|L) ################# # Start Query-based playlist generator clear echo echo "-+- Query-based playlist generator -+-" echo echo "This tool lets you query your filesystem for MP3s" echo "matching specific criteria. Query results can be" echo "saved to playlists for future use." echo echo "In this version, only era and genre searches are supported." echo "More will come in the future. Note that you can" echo "also do this from the Tracker -- just drag Tracker's" echo "query results into your MP3 player and save the" echo "playlist from there." echo echo "Remember, you must have MP3 filesystem indexes for" echo "each volume you intend to query." echo "Be sure to set the query volume in Setup." echo echo "G) Search by genre" echo "Y) Search by era" echo "M) Return to main menu" read continue # Search by Genre if [ "$continue" == "g" ] || [ "$continue" == "G" ]; then id3ren -showgen echo -n "Enter number of genre to search on: "; read GenID SearchGen=$(id3ren -searchgen $GenID) # Run query for this genre on specified volume. # Bash replaces all spaces with backslashes, we have to remove them. # Save results to a temp file query -v "$QueryVolume" "((Audio:Genre=="$SearchGen")&&(BEOS:TYPE=="audio/x-mpeg"))" | sed s/\\\\//g > /tmp/templist # Show user the list cat /tmp/templist echo echo Query complete. echo "Enter a name for this playlist. To discard this list, hit Enter." read ListName if [ "$ListName" == "" ]; then BuildMenu else cp /tmp/templist "$PlaylistDir/$ListName" settype -t $PlaylistMIME "$PlaylistDir/$ListName" echo echo Playlist saved to "$PlaylistDir/$ListName" echo Hit Enter to continue read continue fi # Search by year elif [ "$continue" == "y" ] || [ "$continue" == "Y" ]; then echo -n "Enter earliest recording date (e.g. 1964): "; read StartYear echo -n "Enter latest recording date (e.g. 1975): "; read EndYear # Run query for this era on specified volume. # Bash replaces all spaces with backslashes, we have to remove them. # Save results to a temp file query -v "$QueryVolume" "(((Audio:Year>=$StartYear)&&(Audio:Year<=$EndYear))&&(BEOS:TYPE=="audio/x-mpeg"))" | sed s/\\\\//g > /tmp/templist # Show user the list cat /tmp/templist echo echo Query complete. echo "Enter a name for this playlist. To discard this list, hit Enter." read ListName if [ "$ListName" == "" ]; then BuildMenu else cp /tmp/templist "$PlaylistDir/$ListName" settype -t $PlaylistMIME "$PlaylistDir/$ListName" echo echo Playlist saved to "$PlaylistDir/$ListName" echo Hit Enter to continue read continue fi else BuildMenu fi # Clean up rm /tmp/templist # End Query-based playlist generator ################# ;; esac done } BuildMenu