| 1 | #!/bin/bash |
| 2 | # ra2ogg.sh: Convert streaming audio files (*.ra) to ogg. |
| 3 | |
| 4 | # Uses the "mplayer" media player program: |
| 5 | # http://www.mplayerhq.hu/homepage |
| 6 | # Uses the "ogg" library and "oggenc": |
| 7 | # http://www.xiph.org/ |
| 8 | # |
| 9 | # This script may need appropriate codecs installed, such as sipr.so ... |
| 10 | # Possibly also the compat-libstdc++ package. |
| 11 | |
| 12 | |
| 13 | OFILEPREF=${1%%ra} # Strip off the "ra" suffix. |
| 14 | OFILESUFF=wav # Suffix for wav file. |
| 15 | OUTFILE="$OFILEPREF""$OFILESUFF" |
| 16 | E_NOARGS=85 |
| 17 | |
| 18 | if [ -z "$1" ] # Must specify a filename to convert. |
| 19 | then |
| 20 | echo "Usage: `basename $0` [filename]" |
| 21 | exit $E_NOARGS |
| 22 | fi |
| 23 | |
| 24 | |
| 25 | ########################################################################## |
| 26 | mplayer "$1" -ao pcm:file=$OUTFILE |
| 27 | oggenc "$OUTFILE" # Correct file extension automatically added by oggenc. |
| 28 | ########################################################################## |
| 29 | |
| 30 | rm "$OUTFILE" # Delete intermediate *.wav file. |
| 31 | # If you want to keep it, comment out above line. |
| 32 | |
| 33 | exit $? |
| 34 | |
| 35 | # Note: |
| 36 | # ---- |
| 37 | # On a Website, simply clicking on a *.ram streaming audio file |
| 38 | #+ usually only downloads the URL of the actual *.ra audio file. |
| 39 | # You can then use "wget" or something similar |
| 40 | #+ to download the *.ra file itself. |
| 41 | |
| 42 | |
| 43 | # Exercises: |
| 44 | # --------- |
| 45 | # As is, this script converts only *.ra filenames. |
| 46 | # Add flexibility by permitting use of *.ram and other filenames. |
| 47 | # |
| 48 | # If you're really ambitious, expand the script |
| 49 | #+ to do automatic downloads and conversions of streaming audio files. |
| 50 | # Given a URL, batch download streaming audio files (using "wget") |
| 51 | #+ and convert them on the fly. |