bash script to convert ASF/ASX to MP3 using mplayer and lame

[ permalink ] [ download ]
#!/bin/bash
# Bram Borggreve (c) 2008. GPL Licensed
# Script to convert ASX to MP3. Needs mplayer & lame binaries

# Check if we received a parameter
if [ "$1" != "" ];
then
    FILENAME="$1"

    # Check if the parameter is a file that exists
    if [ -f "$FILENAME" ];
    then 
        # Make up the new names.
        SHORTNAME=${FILENAME%.*}
        WAVNAME="$SHORTNAME"".wav"
        MP3NAME="$SHORTNAME"".mp3"

        # First convert the ASX file to a WAV file
        mplayer -ao pcm:file="$WAVNAME" "$FILENAME"

        # Then convert the WAV file to a MP3 file
        lame "$WAVNAME" "$MP3NAME"
        
        # Remove the temp. wav file
        echo "Cleaning up $WAVNAME"
        rm -v "$WAVNAME"
        
        # Print summary
        echo "Converted $FILENAME to $MP3NAME"
    else
        # Print error
        echo "File does not exist."
    fi
else
    # Print error
    echo "Please enter a filename..."
fi
hits counter