/*************************************************************************** * Copyright (C) 2008 by CaptainCrunch * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include #include typedef char u8; typedef short u16; typedef long u32; char *getURL(char *); //strip gif url from junk char *getTITLE(char *); //strip title from junk u32 getFileSize(const char *); //get filesize const char src[] = "tmp.txt"; //temporary storage int main(int argc, char *argv[]) { char *title = NULL,*gif = NULL; FILE *fd; char buffer[4096]; char *list[2048] = {NULL}; short found = 0; u8 istitle = 0; u16 urlen = strlen(argv[1]); char url[256],tmpurl[256]; int i; CURL *curl; CURLcode res; u32 page = 1; u32 maxpages = (u32)atoi(argv[2]); if(argc!=3 || maxpages <=0 || !strstr(argv[1],"http://")) { printf("Wrong parameter use neogif.exe URL PAGES\n"); printf("e.g. neogif.exe http://www.neogaf.com/forum/showthread.php?t=1337 8\n"); printf("Will fetch gifs from the first 8 pages of given url\n"); return 0; } curl = curl_easy_init(); if(!curl) { printf("Couldn't initialize libcurl!\n"); return 0; } //check url validity strncpy(url,argv[1],sizeof(url)); for(i = urlen;i>0;i--) if(url[i]=='&') { url[i]=0x00; break; } printf("|-------------------------------------------------|\n"); printf("| NEOGIF - get gifs from the mighty neogaf forums |\n"); printf("| CaptainCrunch (c)2008 |\n"); printf("|-------------------------------------------------|\n"); printf("Fetching GIF's from:\n"); printf(" ->%s\n",url); strncpy(tmpurl,url,256); for(;;) { //download html page fd = fopen(src,"w"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,NULL); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) fd); res = curl_easy_perform(curl); if(res) { printf("Error malformed url!\n"); remove(src); return 0; } fclose(fd); fd = fopen(src,"r+t"); if(!fd) { printf("Problem fetching GIF's!\n"); return 0; } while(!feof(fd)) { fgets(buffer,sizeof(buffer),fd); if(page==1) { if(!istitle) { title = getTITLE(buffer); if(title) { istitle = 1; printf(" ->%s\n\n",title); } } } gif = getURL(buffer); if(gif) { int i,exists=0; for(i=0;imaxpages) { printf("\nDone!\n"); page--; break; } } if(!title) { printf("Couldn't locate title!\n"); printf("Will use \"neogif\" as folder!\n"); strcpy(title,"neogif"); } //make dir and strip special characters for(i=0;i' ||title[i]=='|') title[i]=' '; char path[512]; strncpy(path,title,512); strcat(path,"\\neogif.html"); //remove old entry remove(path); rmdir(title); if(mkdir(title)) { printf("Error creating directory!\n"); return 0; } fd = fopen(path,"w+t"); fprintf(fd,"

%s


\n",title); for(i=0;i%s
",list[i],list[i]); } printf(" Found %d GIF's in %d pages\n",found,page); fclose(fd); curl_easy_cleanup(curl); free(list); remove(src); return 0; } char *getURL(char *buffer) { char *gif,*start,*end; short len = 0; gif = strstr(buffer,".gif"); if(!gif) return NULL; //skip avatar gifs if(strstr(buffer," Avatar\"")) return NULL; end = start = gif+3; start--; int i; for(i=0;i"); if(!title) return NULL; start = end = title+7; int i; for(i=0;i