/[safari]/get_book.sh
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /get_book.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by dpavlin, Mon Dec 15 09:33:29 2003 UTC revision 1.5 by dpavlin, Thu Jan 15 12:39:37 2004 UTC
# Line 1  Line 1 
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() {
# Line 34  function geturl() { Line 72  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    
# Line 46  function uniqurl() { Line 85  function uniqurl() {
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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26