summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <hg@njw.me.uk>2011-07-16 16:33:21 +0100
committerNick White <hg@njw.me.uk>2011-07-16 16:33:21 +0100
commitf495ecbddcf5f5ad884c0510363411b4460c77bd (patch)
treedeeef4058573e6f8b4be0522d787d8363af139df
parent8e575d280946f1188f578fcf02b4ba4491a4308c (diff)
Add basic page turning
-rw-r--r--getgbook.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/getgbook.c b/getgbook.c
index de600d8..fa69db9 100644
--- a/getgbook.c
+++ b/getgbook.c
@@ -104,7 +104,7 @@ char *getpageurl(char *bookid, char *pg)
int main(int argc, char *argv[])
{
char *bookid, *url, pg[16];
- int totalpages;
+ int totalpages, i;
if(argc < 2 || argc > 3)
die(usage);
@@ -118,15 +118,22 @@ int main(int argc, char *argv[])
if(!(totalpages = gettotalpages(bookid)))
die("Book has no pages\n");
- printf("Book has %d pages\n", totalpages);
-
- strncpy(pg, "PA2", 12);
- if((url = getpageurl(bookid, pg)) == NULL)
- fprintf(stderr, "Could not find page %s\n", pg);
- else {
- strncat(pg, ".png", 16);
- gettofile(url, pg);
- printf("Downloaded page %s\n", pg);
+
+ /* note this isn't the best way, not least because it misses the
+ * non PA pages. best is to crawl around the json grabbing everything
+ * available, by starting on PP1, and filling in by going through
+ * all pages in totalpages. then crawl through the pages struct. */
+ for(i=1; i<totalpages; i++) {
+ snprintf(pg, 16, "%s%d", "PA", i);
+ if((url = getpageurl(bookid, pg)) == NULL)
+ continue;
+
+ if(argv[1][1] == 'a') {
+ strncat(pg, ".png", 16);
+ gettofile(url, pg);
+ printf("Downloaded page %d\n", i);
+ } else
+ printf("%d\n", i);
}
free(bookid);
free(url);