You are not logged in.
Pages: 1
Allright, I'm trying to make a nice alias for extracting DVD, XViD, etc, and this is what it looks like right now:
find -name "*.r[0-9][0-9]" -exec unrar x -vy {} /mnt/TV/temp \;
The problem is, because I am using [0-9], it will keep on trying to extract the same file over and over again, cause unrar and rar seems to extract the file wheather *.r*-file you choose.
If I'll do it like this "*.rar" , it works for directories where there's only 1 *.rar. I want it to work no matter if the dir's looks like this;
blabla-part001.rar
blabla-part002.rar
..
blabla.r00
blabla.r01
..
blabla.rar
blabla.r01
..
Anyone know what to do?
Offline
Is each multi-part archive in a different directory?
Offline
You should only issue unrar for one of the rar files, not all of them.
I've written a script which does exactly what I think you want. I give it a directory as argument, and it would locate the sfv file (if there is any), and the proper rar file to launch unrar on. I can't post it in it's entirety here, but here are some pointers. "$DIR" below is the directory I've fed the script with (DIR="$1").
To find the sfv file I do like this:
SFVFILE=$(find "$DIR" -maxdepth 1 -iname '*.sfv' -printf '%f\n')
if [ $(echo "$SFVFILE" | grep -c .) -gt 1 ] ; then
die 1 "Found several .sfv files. \n$SFVFILE \nI'm confused."
fi
die is a function that prints the error message and exits with the given exitcode.
To find the correct rar file to start with I do like this:
RARFILE=$(find "$DIR" -maxdepth 1 -iname '*.part*.rar' -printf '%f\n' | sort | head -1)
if [ "x$RARFILE" == "x" ] ; then
RARFILE=$(find "$DIR" -maxdepth 1 -iname '*.rar' -printf '%f\n')
if [ $(echo "$RARFILE" | grep -c .) -gt 1 ] ; then
die 1 "Found several .rar files. \n$RARFILE \nI'm confused."
fi
fi
if [ "x$RARFILE" == "x" ] ; then
RARFILE=$(find "$DIR" -maxdepth 1 -iname '*.r00' -printf '%f\n')
if [ $(echo "$RARFILE" | grep -c .) -gt 1 ] ; then
die 1 "Found several .r00 files. \n$RARFILE \nI'm confused."
fi
fi
if [ "x$RARFILE" == "x" ] ; then
RARFILE=$(find "$DIR" -maxdepth 1 -iname '*.r01' -printf '%f\n')
if [ $(echo "$RARFILE" | grep -c .) -gt 1 ] ; then
die 1 "Found several .r01 files. \n$RARFILE \nI'm confused."
fi
fi
if [ "x$RARFILE" == "x" ] ; then
die 1 "Found no files ending with .rar, .r00 or .r01."
fi
To identify the archived file (iso/img/avi/whatever):
IMGFILE=$(unrar lb "$DIR/$RARFILE")
if [ $(echo "$IMGFILE" | grep -c .) -gt 1 ] ; then
die 1 "Found several image files in rar archive. \n$IMGFILE \nI'm confused."
fi
For the sfv check and subsequent unrar:ing I do like this:
if [ "x$SFVFILE" == "x" ] || $SKIPSFV ; then
unrar e "$DIR/$RARFILE" || exit $?
else
cksfv -C "$DIR" -f "$DIR/$SFVFILE" && unrar e "$DIR/$RARFILE" || exit $?
fi
Since there usually is only one file in the archive it is safe to use "unrar e" instead of "unrar x". unrar e will put the resulting file in the current directory.
Offline
Thanks bebo, I'll have a look at this one, looks nice! Tack.
Offline
Nevermind
Last edited by SiC (2008-11-29 17:18:20)
Offline
Pages: 1