1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
# proxy settings (same as in firebird) |
# proxy settings (same as in firebird) |
4 |
( ping proxy 2>&1 ) >/dev/null && export http_proxy=http://proxy:8080 |
fping proxy && export http_proxy=http://proxy:8080 |
5 |
# user agent (same as in firebird) |
# 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" |
ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040506 Firefox/0.8" |
7 |
|
cookie_file="cookie.txt" |
8 |
|
|
9 |
# wait between pages |
# wait between pages |
10 |
export wait=120 |
export wait=120 |
24 |
mv orig/* . |
mv orig/* . |
25 |
rm -Rf orig |
rm -Rf orig |
26 |
|
|
27 |
grep -l 'promo.asp' * | xargs -i rm -v {} |
grep -l 'promo.asp' * | xargs -i rm {} |
28 |
|
grep -l 'This is only a preview of the full book' * | xargs -i rm {} |
29 |
fi |
fi |
30 |
|
|
31 |
isbn=$1; |
isbn=`echo $1 | sed 's/-//g'` |
|
|
|
|
isbn2=`echo $isbn | sed 's/-//g'` |
|
32 |
|
|
33 |
function mirror() { |
function mirror() { |
34 |
|
|
37 |
file=`echo $url | sed -e s,http://[^?]*?,index.html?, -e s,#.*$,, -e s,/,%2F,g` |
file=`echo $url | sed -e s,http://[^?]*?,index.html?, -e s,#.*$,, -e s,/,%2F,g` |
38 |
if [ -e "$file" ] ; then |
if [ -e "$file" ] ; then |
39 |
# echo "skip $url" |
# echo "skip $url" |
40 |
|
echo -n "." |
41 |
return |
return |
42 |
fi |
fi |
43 |
|
|
44 |
|
cookie=" " |
45 |
if echo $url | grep '/index' >/dev/null ; then |
if echo $url | grep '/index' >/dev/null ; then |
|
cookies="" |
|
46 |
echo -n "no login (index) " |
echo -n "no login (index) " |
47 |
elif echo $url | grep 'mode=toc' >/dev/null ; then |
elif echo $url | grep 'mode=toc' >/dev/null ; then |
|
cookies="" |
|
48 |
echo -n "no login (toc) " |
echo -n "no login (toc) " |
49 |
else |
else |
50 |
cookies="--load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt" |
if [ ! -e $cookie_file ] ; then |
51 |
echo -n "with login " |
echo "cookies file $cookie_file doesn't exits! Please create it." |
52 |
|
echo "It should be in format:" |
53 |
|
echo "Cookie: Site=UICode=&Portal=oreilly&GUID=..." |
54 |
|
exit 1 |
55 |
|
fi |
56 |
|
read cookie < $cookie_file |
57 |
|
if [ -z "$cookie" ] ; then |
58 |
|
echo "Empty cookie file $cookie_file !" |
59 |
|
exit 1 |
60 |
|
fi |
61 |
fi |
fi |
|
echo $url |
|
62 |
|
|
63 |
wget -p -nH -nc -k \ |
if [ -z "$cookie" ] ; then |
64 |
-t 1 -U "$ua" \ |
echo "$url [no cookie]" |
65 |
$cookies $url |
else |
66 |
|
echo "$url [with cookie]" |
67 |
|
fi |
68 |
|
|
69 |
# -D safari.oreilly.com \ |
wget -q -p -nH -nc -k -t 1 -U "$ua" --cookies=off --header="$cookie" $url |
|
# -A 0-201-41975-0 \ |
|
70 |
|
|
71 |
perl -e '$t=rand($ENV{wait} || 30);print "sleep for $t sec.\n"; sleep($t);' |
perl -e '$t=rand($ENV{wait} || 30);print "sleep for $t sec.\n"; sleep($t);' |
72 |
} |
} |
76 |
sed -e 's/^.*<a.*href="//i' \ |
sed -e 's/^.*<a.*href="//i' \ |
77 |
-e 's/".*//' -e 's/amp;//g' \ |
-e 's/".*//' -e 's/amp;//g' \ |
78 |
-e 's,^[^\?]*\?,http://safari.oreilly.com/,' \ |
-e 's,^[^\?]*\?,http://safari.oreilly.com/,' \ |
79 |
-e 's/#$//' \ |
-e 's/#.*$//' \ |
80 |
-e 's/\&srchText=//' \ |
-e 's/\&srchText=//' \ |
81 |
-e 's/open=false/open=true/' | \ |
-e 's/open=false/open=true/' | \ |
82 |
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' | \ |
89 |
mv in in.tmp |
mv in in.tmp |
90 |
grep -v 'view=[A-Z]' in.tmp | sort -u > in |
grep -v 'view=[A-Z]' in.tmp | sort -u > in |
91 |
grep 'view=[A-Z].*/index' in.tmp | sort -u >> in |
grep 'view=[A-Z].*/index' in.tmp | sort -u >> in |
92 |
|
links=`wc -l in | cut -d" " -f1` |
93 |
|
echo "found $links unique links" |
94 |
} |
} |
95 |
|
|
96 |
function mirror_in() { |
function mirror_in() { |
112 |
echo "WARNING: your safari session is disabled. Aborting." |
echo "WARNING: your safari session is disabled. Aborting." |
113 |
exit 1 |
exit 1 |
114 |
fi |
fi |
115 |
|
|
116 |
|
if grep -i 'This is only a preview of the full book' `ls -t index.html* | head -3` >/dev/null ; then |
117 |
|
echo "WARNING: you didn't add this book to your bookshelf!" |
118 |
|
exit 1 |
119 |
|
fi |
120 |
done |
done |
121 |
|
echo |
122 |
} |
} |
123 |
|
|
124 |
echo -n > in |
echo -n > in |
125 |
mirror "http://safari.oreilly.com/?XmlId=$isbn" |
mirror "http://safari.oreilly.com/?XmlId=$isbn" |
126 |
|
echo |
127 |
|
|
128 |
echo "extract URLs from first page..." |
echo "extract URLs from first page..." |
129 |
geturl "index.html?XmlId=$isbn" $isbn |
geturl "index.html?XmlId=$isbn" $isbn |