Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
89 irasnyd 1
#!/bin/zsh
2
 
3
################## CONFIG OPTIONS ##############################################
4
DLDIR="/home/irasnyd/downloads/usenet"              # "global" download dir  ###
5
GLOGDIR="/home/irasnyd/downloads/usenet/logs"       # "global" logdir        ###
6
################################################################################
7
 
8
### Clean up temp files ###
9
cleanup_temp() {
10
rm -f parfiles;
11
rm -f goodfiles;
12
rm -f completefiles;
13
rm -f currentset;
14
rm -f badfiles;
15
};
16
 
17
### Set/Clean up the Environment ###
18
cleanup_temp
19
 
20
### Repair everything, and sort it into "goodfiles" and "badfiles" ###
21
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'
22
 
23
### Extract files, and delete the set if it extracted correctly ###
24
sed 's/.par2//' goodfiles | sed 's/.PAR2//' > completefiles
25
 
26
while read filename; 
27
# get a good working set, sans nfo,jpg,ape,flac,mp3,ogg,avi,ogm,mkv
28
    #do ls ${filename}* | grep -vi "nfo\|jpg\|ape\|flac\|mp3\|ogg\|avi\|ogm\|mkv" > currentset;
29
 
30
    if [ -z "${filename}" ]; then break; fi;
31
 
32
    do ls ${filename}* | grep -i "rar$\|r00$\|001$\|par2$" > currentset;
33
 
34
    # remove pars from currentset, then get the first thing that has "rar" or "001" at the END only
35
    # store above result in EXFILE (file to extract)
36
    EXFILE=`grep -vi "par2$" currentset | grep -m1 "rar$\|r00$\|001$"`;
37
 
38
    if [ ! -z "${EXFILE}" ]; then 
39
        # (extract the file AND remove the current set) OR save the filename to "unextractable"
40
        ( rar e ${EXFILE} && while read j; do rm $j; done < currentset ) || echo $filename >> ${GLOGDIR}/unextractable;
41
    else
42
        echo "No File to extract, removing currentset";
43
        while read k; do rm $k; done < currentset;
44
    fi;
45
done < completefiles
46
 
47
###############################################################################
48
 
49
### Clean up temp files ###
50
cleanup_temp
51
 
52
### Print Parting Message ###
53
echo
54
echo "All Finished. Good Bye!"