From aaca1c3ef0fa07a9a8178d3001a0c681e374d448 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 20 Sep 2011 21:00:05 +0100 Subject: Fix up getabook; basically working now --- TODO | 6 +++--- getabook.c | 58 ++++++++++++++++++++-------------------------------------- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/TODO b/TODO index 4892b13..798a93d 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,10 @@ before 1.0: create other 2 utilities, fix http bugs, be unicode safe, package for osx & windows -# other utils +# getabook -getabook +parse jumboImageUrls in getBookData -getbnbook +# getbnbook # other todos diff --git a/getabook.c b/getabook.c index dd7eec7..7f205d9 100644 --- a/getabook.c +++ b/getabook.c @@ -62,7 +62,11 @@ int getpageurls(int pagenum) { if(!get("www.amazon.com", url, NULL, NULL, &buf)) return 1; - s = strstr(buf, "\"jumboImageUrls\":{") + strlen("\"jumboImageUrls\":{"); + if(!(s = strstr(buf, "\"jumboImageUrls\":{"))) { + free(buf); + return 1; + } + s += strlen("\"jumboImageUrls\":{"); for(i=0; *s && iurl)) + if(!sscanf(c, "\"//sitb-images.amazon.com%[^\"]\"", pages[i]->url)) continue; } @@ -88,19 +92,18 @@ int getpageurls(int pagenum) { return 0; } -/* int getpage(Page *page) { char path[STRMAX]; snprintf(path, STRMAX, "%04d.png", page->num); if(page->url[0] == '\0') { - fprintf(stderr, "%s not found\n", page->name); + fprintf(stderr, "%d not found\n", page->num); return 1; } - if(gettofile("books.google.com", page->url, page->cookie, NULL, path)) { - fprintf(stderr, "%s failed\n", page->name); + if(gettofile("sitb-images.amazon.com", page->url, NULL, NULL, path)) { + fprintf(stderr, "%d failed\n", page->num); return 1; } @@ -108,17 +111,13 @@ int getpage(Page *page) fflush(stdout); return 0; } -*/ int main(int argc, char *argv[]) { - /*char *tmp; char buf[BUFSIZ], pgpath[STRMAX]; char in[16]; int a, i, n; - FILE *f;*/ - - int i; + FILE *f; if(argc < 2 || argc > 3 || (argc == 3 && (argv[1][0]!='-' || argv[1][1] != 'n')) @@ -135,15 +134,6 @@ int main(int argc, char *argv[]) return 1; } - for(i=0; iurl[0] == '\0') - getpageurls(pages[i]->num); - printf("page %d is %s\n", pages[i]->num, pages[i]->url); - } - - return 0; - -/* if(argc == 2) { for(i=0; inum); @@ -151,38 +141,30 @@ int main(int argc, char *argv[]) fclose(f); continue; } - searchpage(pages[i]); + if(pages[i]->url[0] == '\0') + getpageurls(pages[i]->num); getpage(pages[i]); } - } else if(argv[1][0] == '-') { + } else if(argv[1][0] == '-' && argv[1][1] == 'n') { while(fgets(buf, BUFSIZ, stdin)) { sscanf(buf, "%15s", in); i = -1; - if(argv[1][1] == 'c') { - for(a=0; aname, in, STRMAX) == 0) { - i = a; - break; - } - } - } else if(argv[1][1] == 'n') { - sscanf(in, "%d", &n); - for(a=0; anum == n) { - i = a; - break; - } + sscanf(in, "%d", &n); + for(a=0; anum == n) { + i = a; + break; } } if(i == -1) { fprintf(stderr, "%s not found\n", in); continue; } - searchpage(pages[i]); + if(pages[i]->url[0] == '\0') + getpageurls(pages[i]->num); getpage(pages[i]); } } -*/ for(i=0; i