1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
|
# proxy settings (same as in firebird) |
4 |
export http_proxy=http://proxy:8080 |
export http_proxy=http://proxy:8080 |
5 |
|
# user agent (same as in firebird) |
6 |
|
ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031225 Firebird/0.7" |
7 |
|
|
8 |
|
# wait between pages |
9 |
|
export wait=120 |
10 |
|
|
11 |
|
|
12 |
if [ -z "$1" ] ; then |
if [ -z "$1" ] ; then |
13 |
echo "Usage: $0 ISBN" |
echo "Usage: $0 ISBN" |
14 |
exit 1 |
exit 1 |
15 |
fi |
fi |
16 |
|
|
17 |
isbn=$1; |
if [ -e orig ] ; then |
18 |
|
echo "orig directory found. Resume download? [Y/n]" |
19 |
|
read ans |
20 |
|
if [ "$ans" = "n" ] ; then |
21 |
|
exit 1; |
22 |
|
fi |
23 |
|
mv orig/* . |
24 |
|
rm -Rf orig |
25 |
|
|
26 |
|
grep -l 'promo.asp' * | xargs -i rm -v {} |
27 |
|
fi |
28 |
|
|
29 |
wait=10 |
isbn=$1; |
30 |
|
|
31 |
isbn2=`echo $isbn | sed 's/-//g'` |
isbn2=`echo $isbn | sed 's/-//g'` |
32 |
|
|
33 |
function mirror() { |
function mirror() { |
34 |
|
|
35 |
|
url="$1" |
36 |
|
|
37 |
|
file=`echo $url | sed -e s,http://[^?]*?,index.html?, -e s,#.*$,, -e s,/,%2F,g` |
38 |
|
if [ -e "$file" ] ; then |
39 |
|
# echo "skip $url" |
40 |
|
return |
41 |
|
fi |
42 |
|
|
43 |
|
if echo $url | grep '/index' >/dev/null ; then |
44 |
|
cookies="" |
45 |
|
echo -n "no login (index) " |
46 |
|
elif echo $url | grep 'mode=toc' >/dev/null ; then |
47 |
|
cookies="" |
48 |
|
echo -n "no login (toc) " |
49 |
|
else |
50 |
|
cookies="--load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt" |
51 |
|
echo -n "with login " |
52 |
|
fi |
53 |
|
echo $url |
54 |
|
|
55 |
wget -p -nH -nc -k \ |
wget -p -nH -nc -k \ |
56 |
--random-wait --wait=$wait -t 0 \ |
-t 1 -U "$ua" \ |
57 |
--load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt \ |
$cookies $url |
|
-U "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031206 Firebird/0.7" \ |
|
|
$1 |
|
58 |
|
|
59 |
# -D safari.oreilly.com \ |
# -D safari.oreilly.com \ |
60 |
# -A 0-201-41975-0 \ |
# -A 0-201-41975-0 \ |
61 |
|
|
62 |
|
perl -e '$t=rand($ENV{wait} || 30);print "sleep for $t sec.\n"; sleep($t);' |
63 |
} |
} |
64 |
|
|
65 |
function geturl() { |
function geturl() { |
72 |
-e 's/open=false/open=true/' | \ |
-e 's/open=false/open=true/' | \ |
73 |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
74 |
grep $2 | \ |
grep $2 | \ |
75 |
|
grep -v "$2/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" | \ |
76 |
sort -u >> in |
sort -u >> in |
77 |
} |
} |
78 |
|
|
85 |
function mirror_in() { |
function mirror_in() { |
86 |
cat in | while read url ; do |
cat in | while read url ; do |
87 |
mirror "$url" |
mirror "$url" |
88 |
|
#sleep $wait |
89 |
|
|
90 |
if grep 'promo.asp' `ls -t index.html* | head -3` >/dev/null ; then |
if grep 'promo.asp' `ls -t index.html* | head -3` >/dev/null ; then |
91 |
echo "WARNING: safari seems to logunt you as user. Aborting." |
echo "WARNING: safari seems to logout you as user. Aborting." |
92 |
|
exit 1 |
93 |
|
fi |
94 |
|
|
95 |
|
if grep -i '>Account locked<' `ls -t index.html* | head -3` >/dev/null ; then |
96 |
|
echo "WARNING: your safari account is locked. Aborting." |
97 |
|
exit 1 |
98 |
|
fi |
99 |
|
|
100 |
|
if grep -i 'session disabled' `ls -t index.html* | head -3` >/dev/null ; then |
101 |
|
echo "WARNING: your safari session is disabled. Aborting." |
102 |
exit 1 |
exit 1 |
103 |
fi |
fi |
104 |
done |
done |