#!/bin/bash # Download .ram audio into an ogg file # Depends on oggenc and xine with the proper codec available... # perl should be installed for the documentation stuff, which is in POD format ############################################################################### # basename and full path of program THISSCRIPT=${0##*/} THISSCRIPT_FULL="$0" # Debugging level. Set this with the -D option: # -ve = ERROR # 0 = WARNING # +ve = DEBUG DBLEV_S=${DBLEV_S:-0} errex () { echo "$1" exit ${2:-1} } # Some useful function definitions usage () { pod2usage $THISSCRIPT_FULL exit ${1:-0} } # usage example (warning): db_out 0 "a warning message" db_out () { meslev="${1:-1}" shift message="$@" if [ $meslev -le ${DBLEV_S:-0} ]; then if [ $meslev -lt 0 ]; then mestyp="$THISSCRIPT ERROR[$meslev]:" elif [ $meslev -eq 0 ]; then mestyp="$THISSCRIPT WARNING:" else mestyp="$THISSCRIPT DEBUG[$meslev]:" fi print -u2 "$mestyp $message" fi } # # End of generic functions and the like ############################################################################### # Start Main Program PROGNAME="Real Audio download/ogg encoder" VERSION="0.01" AUTHOR="Matthew Gates, Nov 2005" quality=3 output="" if [ "$1" = "--help" ] || [ "$1" = "-help" ]; then usage 0 fi set -- `getopt vhD:q:o: $@` if [ $? -ne 0 ]; then usage 2 fi while [ $# -gt 0 ]; do case $1 in -D) DBLEV_S=$2 shift 2 ;; -h) usage 0 shift ;; -v) echo "$PROGNAME; version $VERSION" echo "$AUTHOR" shift ;; -q) quality=$2 shift 2 ;; -o) output="$2" shift 2 ;; --) shift break ;; esac done db_out 3 "command line parsed, parameters now: $@" if [ "$1" = "" ]; then echo "You have to specify some URL..." exit 1 fi if [ "$output" = "" ]; then output="$(basename "$1")" output="${output%.ram}.ogg" fi tdir=$(mktemp -d -p.) mkfifo "$tdir/xine-out.wav" oggenc --quiet -q $quality "$tdir/xine-out.wav" -o "$output" & pushd "$tdir" xine --video-driver none \ --audio-driver file \ --auto-play=wq \ --hide-gui \ --no-logo \ --no-splash \ "$1" > /dev/null echo "xine done, waiting for oggenc to complete..." wait popd rm "$tdir/xine-out.wav" rmdir "$tdir" echo "all done..." exit 0 __END__ =head1 NAME ram2ogg - download the audio from a .ram URL =head1 SYNOPSIS ram2ogg [options] =head1 DESCRIPTION ram2ogg uses xine to download the audio from a real audio URL and uses oggenc to convert this to a ogg vorvis audio file. =head1 OPTIONS =over =item B<-D> I Print diagnostic messages while executing. The value of I must be an integer. The higher the number, the more verbose the diagnostic output will be. =item B<--help> or B<-h> Print the command line syntax an option details. =item B<-v> Print the program description and version. =item B<-o> I Save the results in I. By default the basename of the requested URL is use with ".ram" turned into ".ogg". =item B<-q> I Set the ogg quality. This is a value between 0 and 10, where 10 is the best quality/largest files, and 0 is the worst quality/smallest files. The default is 3. Note that using higher values isn't going to help very much -- real audio compression is typically pretty aggressive and the quality isn't that great. =back =head1 ENVIRONMENT =over =item DBLEV_S Debugging level. 0 means warnings and errors only, more positive numbers mean more and more debugging =back =head1 FILES N/A =head1 EXAMPLE ram2ogg -o fun.ogg http://porpoisehead.net/not_a_real_url.ram =head1 LICENSE ram2ogg is released under the GNU GPL (version 2, June 1991). A copy of the license should have been provided in the distribution of the software in a file called "LICENSE". If you can't find this, then try here: http://www.gnu.org/copyleft/gpl.html =head1 AUTHOR Matthew Gates http://porpoisehead.net/ =head1 CHANGELOG =over =item Date:2005-11-17 Created, Author MNG Original version. =back =head1 BUGS Please report bugs to the author. =head1 SEE ALSO xine(1), oggenc(1) =cut