diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | getabook.c | 1 | ||||
-rw-r--r-- | getbnbook.c | 1 | ||||
-rw-r--r-- | getgbook.c | 1 | ||||
-rw-r--r-- | util.c | 24 | ||||
-rw-r--r-- | util.h | 1 |
6 files changed, 28 insertions, 2 deletions
@@ -2,8 +2,6 @@ before 1.0: fix http bugs, package for osx & windows # other todos -use the correct file extension depending on the image type (for google and amazon the first page is a jpg, all the others are png) - bug in get() & post(): if the \r\n\r\n after http headers is cut off between recv buffers package for osx - https://github.com/kennethreitz/osx-gcc-installer @@ -136,6 +136,7 @@ int getpage(Page *page) fprintf(stderr, "%d failed\n", page->num); return 1; } + renameifjpg(path); printf("%d downloaded\n", page->num); fflush(stdout); diff --git a/getbnbook.c b/getbnbook.c index 76e3e0e..5254f14 100644 --- a/getbnbook.c +++ b/getbnbook.c @@ -83,6 +83,7 @@ int getpage(int pagenum) fprintf(stderr, "%d failed\n", pagenum); return 1; } + renameifjpg(path); printf("%d downloaded\n", pagenum); fflush(stdout); @@ -136,6 +136,7 @@ int getpage(Page *page) fprintf(stderr, "%s failed\n", page->name); return 1; } + renameifjpg(path); printf("%d downloaded\n", page->num); fflush(stdout); @@ -161,3 +161,27 @@ int post(char *host, char *path, char *data, char **buf) { return l; } + +int renameifjpg(char *path) { + FILE *f; + char *newpath, *c; + + if((f = fopen(path, "rb")) == NULL) + return 1; + + if(fgetc(f) == 255) { + if((newpath = malloc(strlen(path) + 1)) == NULL) + return 1; + strncpy(newpath, path, strlen(path)); + c = strrchr(newpath, '.'); + strncpy(c+1, "jpg\0", 4); + + if(rename(path, newpath)) + return 1; + free(newpath); + } + + fclose(f); + + return 0; +} @@ -5,3 +5,4 @@ int dial(char *host, char *port); int get(char *host, char *path, char *sendcookie, char *savecookie, char **buf); int gettofile(char *host, char *url, char *sendcookie, char *savecookie, char *savepath); int post(char *host, char *path, char *data, char **buf); +int renameifjpg(char *path); |