summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <hg@njw.me.uk>2011-07-17 16:17:47 +0100
committerNick White <hg@njw.me.uk>2011-07-17 16:17:47 +0100
commit07fdb0adb5a3578f449902571b02a7faa4590d7d (patch)
tree8316d46d052a3f552a7d1ec81093a57e0897df7f
parentc19c8fbcdf22bb863e85a47c209c242c19c2b16c (diff)
Remove ip setting; only works for api, not pages, so useless
-rw-r--r--TODO2
-rw-r--r--getgbook.c28
-rw-r--r--util.c8
3 files changed, 17 insertions, 21 deletions
diff --git a/TODO b/TODO
index 903ab00..082526d 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+order is prob available even for pages that don't have src. check this, and if so rewrite getpagedetails to set it even if no src (rather than just bailing)
+
use order to be able to use real page numbers (getpagecode)
to find this advance through click3 letter by letter until either } (none found) or strcmp "order"
diff --git a/getgbook.c b/getgbook.c
index 37506c3..d89dcf2 100644
--- a/getgbook.c
+++ b/getgbook.c
@@ -5,10 +5,9 @@
#include "util.c"
#define usage "getgbook " VERSION " - a google books downloader\n" \
- "usage: getgbook [-i ip] [-p|-a] bookid\n" \
+ "usage: getgbook [-p|-a] bookid\n" \
" -p print all available pages\n" \
" -a download all available pages\n" \
- " -i appear from ip address\n" \
" otherwise, all pages in stdin will be downloaded\n"
#define URLMAX 1024
@@ -20,8 +19,6 @@ typedef struct {
char name[80];
} Page;
-char extrahdr[1024] = "\0";
-
int gettotalpages(char *bookid)
{
char url[URLMAX];
@@ -32,7 +29,7 @@ int gettotalpages(char *bookid)
bookid = malloc(sizeof(char *) * BOOKID_LEN);
- if(!get("books.google.com", url, extrahdr, &buf))
+ if(!get("books.google.com", url, &buf))
return 0;
if((c = strstr(buf," pages</dc:format>")) == NULL)
@@ -51,10 +48,11 @@ Page *getpagedetail(char *bookid, char *pg)
snprintf(url, URLMAX, "/books?id=%s&pg=%s&jscmd=click3", bookid, pg);
- if(!get("books.google.com", url, extrahdr, &buf))
+ if(!get("books.google.com", url, &buf))
return NULL;
snprintf(m, 80, "\"pid\":\"%s\"", pg);
+ printf("looking for the pid %s\n", m);
if((c = strstr(buf,m)) == NULL)
return NULL;
@@ -63,10 +61,12 @@ Page *getpagedetail(char *bookid, char *pg)
page->url[0] = '\0';
page->num = 0;
+ printf("looking for the src\n");
if(strncmp(c+strlen(m)+1, "\"src\"", 5) != 0) {
free(buf); return page;
}
+ printf("getting the order\n");
for(p=page->url, d=c+strlen(m)+8; *d && *d != '"'; d++, p++) {
if(!strncmp(d, "\\u0026", 6)) {
*p = '&';
@@ -96,16 +96,10 @@ int main(int argc, char *argv[])
int totalpages, i;
Page *page;
- if(argc < 2 || argc > 5 ||
- (argv[1][0]=='-' && ((argv[1][1]!='p' && argv[1][1]!='a' && argv[1][1] != 'i') || argc < 3)))
+ if(argc < 2 || argc > 3 ||
+ (argv[1][0]=='-' && ((argv[1][1]!='p' && argv[1][1]!='a') || argc < 3)))
die(usage);
- if(argv[1][0] == '-' && argv[1][1] == 'i') {
- snprintf(extrahdr, 1024, "X-Forwarded-For: %s\r\n", argv[2]);
- argv+=2;
- argc-=2;
- }
-
bookid = argv[argc-1];
if(argv[1][0] == '-') {
@@ -117,7 +111,7 @@ int main(int argc, char *argv[])
die("Book has no pages\n");
for(i=1; i<=totalpages; i++) {
- snprintf(pg, 16, "%s%d", "PA", i);
+ snprintf(pg, 16, "%s%d", "PT", i);
if((page = getpagedetail(bookid, pg)) == NULL || page->url[0] == '\0') {
fprintf(stderr, "%s failed\n", pg);
free(page);
@@ -125,7 +119,7 @@ int main(int argc, char *argv[])
}
if(argv[1][1] == 'a') {
snprintf(n, 80, "%05d.png", page->num);
- gettofile("books.google.com", page->url, extrahdr, n);
+ gettofile("books.google.com", page->url, n);
printf("Downloaded page %d\n", page->num);
} else
printf("%d\n", page->num);
@@ -142,7 +136,7 @@ int main(int argc, char *argv[])
continue;
}
snprintf(n, 80, "%05d.png", page->num);
- gettofile("books.google.com", page->url, extrahdr, n);
+ gettofile("books.google.com", page->url, n);
printf("Downloaded page %d\n", page->num);
free(page);
}
diff --git a/util.c b/util.c
index 68d1d72..a34dad3 100644
--- a/util.c
+++ b/util.c
@@ -33,7 +33,7 @@ static int dial(char *host, char *port) {
return srv;
}
-int get(char *host, char *path, char *extrahdr, char **buf) {
+int get(char *host, char *path, char **buf) {
size_t l, res;
int fd, i, p;
char h[1024] = "\0";
@@ -43,7 +43,7 @@ int get(char *host, char *path, char *extrahdr, char **buf) {
srv = fdopen(fd, "r+");
fprintf(srv, "GET %s HTTP/1.0\r\nUser-Agent: getgbook-"VERSION \
- " (not mozilla)\r\n%sHost: %s\r\n\r\n", path, extrahdr, host);
+ " (not mozilla)\r\nHost: %s\r\n\r\n", path, host);
fflush(srv);
while(h[0] != '\r') {
@@ -60,12 +60,12 @@ int get(char *host, char *path, char *extrahdr, char **buf) {
return l;
}
-int gettofile(char *host, char *url, char *extrahdr, char *savepath) {
+int gettofile(char *host, char *url, char *savepath) {
char *buf = 0;
FILE *f;
size_t i, l;
- if(!(l = get(host, url, extrahdr, &buf))) {
+ if(!(l = get(host, url, &buf))) {
fprintf(stderr, "Could not download %s\n", url);
return 1;
}