Movie Converter - bash/Zenity/Autoglade Version
This is the revised bash script that uses Autoglade, bash, and Zenity for the GUI.
#! /bin/bash
# Set a few variables we will need later.
ZENITY="zenity --window-icon=$SHOME/$ICON"
MENCODER="/opt/mplayer/bin/mencoder"
AUTOGLADE="/usr/bin/autoglade"
# Check for mencoder and autoglade. Warn if
# they are not installed.
if [ -e $MENCODER ]
then
echo "Proceeding..."
else
$ZENITY --error --text="Could not find mencoder at the defined location. Install mencoder or change the MENCODER variable in the MOMC shell script to point to the proper location."
exit
fi
if [ -e $AUTOGLADE ]
then
echo "Proceeding..."
else
$ZENITY --error --text="Could not find autoglade at the defined location. Install autoglade or change the AUTOGLADE variable in the MOMC shell script to point to the proper location."
exit
fi
# The function that runs autoglade and the user the main menu GUI. Then
# it makes a couple of checks.
runAutoGlade() {
DUMP=$($AUTOGLADE $0.glade)
if [ $? -eq 0 ]
then
eval $DUMP
if [ "$NewFileName" = "" ]
then
$ZENITY --error --text="You didn't give your new file a name."
runAutoGlade
fi
if [ "$OpenFile" = 'None' ]
then
$ZENITY --error --text="You didn't select a file to convert."
runAutoGlade
else
# Check to see if the file we're transcoding is actually a video file.
EXT=`echo $OpenFile | awk -F. '{print $2}'`
if [ $EXT = "mov" ] || [ $EXT = "mp4" ] || [ $EXT = "mpg" ] || [ $EXT = "mpeg" ] || [ $EXT = "vob" ] || [ $EXT = "avi" ] || [ $EXT = "wmv" ] || [ $EXT = "asf" ]
then
reSize
else
$ZENITY --error --text="That file is not a video file format!"
runAutoGlade
fi
fi
else
exit
fi
}
reSize() {
# Check what size user chose and set aspect ratio accordingly.
if [ "$Size" = 'Normal' ]
then
ASPECT=""
elif [ "$Size" = 'Palm-TX' ]
then
ASPECT="480:320"
elif [ "$Size" = 'Palm-Tungsten-T' ]
then
ASPECT="150:114"
elif [ "$Size" = 'Blackberry' ]
then
ASPECT="480:360"
else
$ZENITY --error --text="Whoops! Not sure how I got here."
runAutoGlade
fi
# lowercase the new file extension
LFormat=`echo $Format| tr “[:upper:]” “[:lower:]”`
# Put the path to the new file, the new file name and the extension together
FILENAME="$SaveTo/$NewFileName.$LFormat"
# Check to see if the file already exists. If it does, ask user what to do about it?
if [ -e $FILENAME ]
then
OVWR=`$ZENITY --question --title="Overwrite file?" --text="A file by that name already exists! Overwrite it?"`
if [ "$?" == "0" ]
then
echo "Proceeding...";
# Cludge.
else
runAutoGlade
fi
fi
# If the user is trying to overwrite the original
# file, tell them they can't.
if [ $FILENAME == $OpenFile ]
then
$ZENITY --error --text="You are attempting to overwrite the source file. You can't do that."
runAutoGlade
fi
# Do the actual transcoding. We have to
# handle vob files a little differently from
# normal video files so we check to see which
# one we're using for input.
if [ $EXT == "vob" ]
then
$MENCODER $OpenFile -oac lavc -ovc lavc -lavcopts vcodec=mpeg4 -vf spp,scale -o $FILENAME
else
if [ "$Size" == 'Normal' ]
then
$MENCODER $OpenFile -oac pcm -ovc lavc -lavcopts vcodec=mpeg4 -o $FILENAME
else
$MENCODER $OpenFile -oac pcm -ovc lavc -lavcopts vcodec=mpeg4 -vf scale=$ASPECT -o $FILENAME
fi
fi
# Check to see how mencoder exited. If 0, all is well. If 1, an error occurred.
if [ $? -eq 0 ]
then
$ZENITY --info --title="Transcode Complete" --text="The file completed transcoding."
else
$ZENITY --error --title="Error!" --text="An error occurred during transcoding."
fi
runAutoGlade
}
runAutoGlade