I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox.
Example of data:
$SORTEDTMP= it is a file created using find that contain all the movies (200+) on my drive. ex:
/USB/movies/science-fiction/alien/alien.avi
/USB/movies/comedy/funnymovie/funnymovie.avi
....etc
$MOVIESPATH= string = "/USB/movies/science-fiction/"
Movieinfo = Just an xml file containing data about the movie; I only care about extracting the movie title if the file exist vs using the filename as the movie title which may or may not be accurate.
All the other jpg, bmp may or may not exist and appropriate action are taken based on their existence.
Currently the created xml file is being appended for every movies that match the grep MOVIESPATH which could include all the movies. This part of the code is called up many times to create an xml files for all the different movie category including "All movies". I am not sure if I can store all the data in a temporary place in memory and before I leave this loop write the file would be faster ????? I don't know and do not have much experience.
So I'll ask again does anyone sees anything there that could be optimized that would significantly increase the running speed of this piece of code.
grep "$MOVIESPATH" $SORTEDTMP | while read plik
do
MovieName=`basename "$plik" | sed 's/\(.*\)\..*/\1/'`
DirectoryPath=`dirname "$plik"`
if [ -e "$DirectoryPath/MovieInfo.nfo" ];
then
MOVIEINFO="$DirectoryPath/MovieInfo.nfo"
MOVIETITLE=`grep "<title>.*<.title>" "$MOVIEINFO" | sed -e "s/^.*<title/<title/" | cut -f2 -d">"| cut -f1 -d"<"`
else
MOVIETITLE=$MovieName
fi
if [ -e "$DirectoryPath/folder.jpg" ];
then
MOVIEPOSTER=$DirectoryPath/folder.jpg
elif [ -e "$DirectoryPath/${MovieName}.jpg" ];
then
MOVIEPOSTER=$DirectoryPath/${MovieName}.jpg
else
MOVIEPOSTER=/usr/local/etc/srjg/nofolder.bmp
fi
if [ -e "$DirectoryPath/about.jpg" ];
then
MOVIESHEET=$DirectoryPath/about.jpg
elif [ -e "$DirectoryPath/0001.jpg" ];
then
MOVIESHEET=$DirectoryPath/0001.jpg
elif [ -e "$DirectoryPath/${MovieName}_sheet.jpg" ];
then
MOVIESHEET=$DirectoryPath/${MovieName}_sheet.jpg
else
MOVIESHEET=/usr/local/etc/srjg/NoMovieinfo.bmp
fi
echo -e '<Movie>
<title>'$MOVIETITLE'</title>
<poster>'$MOVIEPOSTER'</poster>
<info>'$MOVIESHEET'</info>
<file>'$plik'</file>
</Movie>' >> $RSS
done
Any help appreciated. Thank you.