Subversion Repositories programming

Rev

Blame | Last modification | View Log | RSS feed

#!/bin/zsh

################## CONFIG OPTIONS ##############################################
DLDIR="/home/irasnyd/downloads/usenet"              # "global" download dir  ###
GLOGDIR="/home/irasnyd/downloads/usenet/logs"       # "global" logdir        ###
################################################################################

### Clean up temp files ###
cleanup_temp() {
rm -f parfiles;
rm -f goodfiles;
rm -f completefiles;
rm -f currentset;
rm -f badfiles;
};

### Set/Clean up the Environment ###
cleanup_temp

### Repair everything, and sort it into "goodfiles" and "badfiles" ###
find ./ -maxdepth 1 -iregex '.*\.par2$' \! -iregex  '.*\.vol[0-9]+\+[0-9]+\.par2$' -print0 | xargs -0 -n1 | xargs -I{} bash -c '( par2repair "{}" && echo "{}" >> goodfiles ) || echo "{}" >> /home/irasnyd/downloads/usenet/logs/badfiles'
   
### Extract files, and delete the set if it extracted correctly ###
sed 's/.par2//' goodfiles | sed 's/.PAR2//' > completefiles

while read filename; 
# get a good working set, sans nfo,jpg,ape,flac,mp3,ogg,avi,ogm,mkv
    #do ls ${filename}* | grep -vi "nfo\|jpg\|ape\|flac\|mp3\|ogg\|avi\|ogm\|mkv" > currentset;

    if [ -z "${filename}" ]; then break; fi;

    do ls ${filename}* | grep -i "rar$\|r00$\|001$\|par2$" > currentset;
    
    # remove pars from currentset, then get the first thing that has "rar" or "001" at the END only
    # store above result in EXFILE (file to extract)
    EXFILE=`grep -vi "par2$" currentset | grep -m1 "rar$\|r00$\|001$"`;
    
    if [ ! -z "${EXFILE}" ]; then 
        # (extract the file AND remove the current set) OR save the filename to "unextractable"
        ( rar e ${EXFILE} && while read j; do rm $j; done < currentset ) || echo $filename >> ${GLOGDIR}/unextractable;
    else
        echo "No File to extract, removing currentset";
        while read k; do rm $k; done < currentset;
    fi;
done < completefiles

###############################################################################

### Clean up temp files ###
cleanup_temp

### Print Parting Message ###
echo
echo "All Finished. Good Bye!"