From 3afe70f3cd0a19465ef9f8bbaf6a0961d9eb6d3a Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 17 Aug 2011 18:57:02 +0100 Subject: Started rewrite (not there yet) --- TODO | 2 ++ getgbook.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 558b8d8..8a1deb7 100644 --- a/TODO +++ b/TODO @@ -4,6 +4,8 @@ getabook getbnbook +use "" rather than "\0" in headermax + # other todos use HTTP/1.1 with "Connection: close" header diff --git a/getgbook.c b/getgbook.c index 5f0a0ae..52eb82a 100644 --- a/getgbook.c +++ b/getgbook.c @@ -5,15 +5,15 @@ #include "util.h" #define usage "getgbook " VERSION " - a google books downloader\n" \ - "usage: getgbook [-p|-a] bookid\n" \ - " -p print all available pages\n" \ - " -a download all available pages\n" \ - " otherwise, all pages in stdin will be downloaded\n" + "usage: getgbook [-] bookid\n" \ + " - download pages from stdin\n" \ + " otherwise, all available pages will be downloaded\n" #define URLMAX 1024 #define STRMAX 1024 #define PGCODELEN 3 #define RETRYNUM 5 +#define COOKIENUM 5 typedef struct { int num; @@ -23,6 +23,13 @@ typedef struct { char pagecodes[][PGCODELEN] = { "PP", "PR", "PA", "PT", "\0" }; +int getpagelist(char *bookid, Page *pages) +{ + /* TODO */ + /*http://books.google.com/books?id=h3DSQ0L10o8C&printsec=frontcover*/ + return 1; +} + Page *getpagedetail(char *bookid, char *pg, char *cookie) { char url[URLMAX], m[STRMAX]; @@ -71,20 +78,48 @@ Page *getpagedetail(char *bookid, char *pg, char *cookie) int main(int argc, char *argv[]) { - char *bookid, *tmp, *code; + char *bookid, *tmp, *code, cookies[COOKIENUM][COOKIEMAX]; char pg[STRMAX], buf[BUFSIZ], n[STRMAX], cookie[COOKIEMAX] = ""; int i, c, retry; - Page *page; - if(argc < 2 || argc > 3 || - (argv[1][0]=='-' && ((argv[1][1]!='p' && argv[1][1]!='a') || argc < 3))) { + if(argc < 2 || argc > 3 || (argc == 3 && argv[1][0]!='-')) { fputs(usage, stdout); return 1; } + /* get cookies */ + for(i=0;i