View Javadoc

1   package org.paneris.bibliomania.metasearch.amazon;
2   
3   import java.io.FileInputStream;
4   
5   import org.melati.util.IoUtils;
6   import org.paneris.bibliomania.metasearch.util.HackParser;
7   
8   public class BookPage extends HackParser {
9     public String publisher;
10    public String image;
11  
12    private static final byte[] isbnColon = "ISBN:".getBytes();
13  
14    public BookPage(byte[] text, String isbn) {
15      super(text);
16  
17      try {
18        skipTo(isbnColon);
19        while (text[here] != ';')
20          --here;
21        int end = here;
22        while (text[here] != '\n')
23          --here;
24        ++here;
25        while (text[here] == ' ')
26          ++here;
27        publisher = new String(text, here, end - here);
28  
29        here = 0;
30  
31        skipTo(("src=\"http://images.amazon.com/images/P/" + isbn).getBytes());
32        image = quotedStringFromBack(20);
33      } catch (Exception e) {
34      }
35    }
36  
37    public static void main(String[] args) throws Exception {
38      BookPage p =
39        new BookPage(IoUtils.slurp(new FileInputStream(args[0]), 1000), args[1]);
40      System.out.println(p.publisher);
41      System.out.println(p.image);
42    }
43  }