#include "colors.h" char* TempVal; //#include /* i cant figure out usbkeyboard */ bool allowredownloadscreen = true; // defined in settings.c extern void DownloadThumbnailsAlt(char*,int); typedef struct pltxtSettings{ bool pltxting; //Within void LoadQuery(char*) function bool DownloadSDVideo; //Download Standard Definition Video bool DownloadHDVideo; //Download High Definition Video Might Only Contain Video Stream bool DownloadAudio; //Download Audio File bool DownloadThumbnail; //Download Thumbnail .jpg (size used when thumbnails are downloaded) bool DownloadDescription; //Download Video Description bool DownloadAllKindsOfThumbnail; //Download Every Thumbnail Resolution For Video int starting; //First Video In Playlist as an index int ending; //Last Video In Playlist as an index bool havestarting; //Start At certain offset in Playlist bool haveending; //End at a particular place in Playlist }pltxtSettings; pltxtSettings pltxtsett; /* Init Playlist For Begining and end of LoadQuery Function */ void PLTXTInit(bool pltxter){ pltxtsett.pltxting=pltxter; pltxtsett.DownloadSDVideo=true; pltxtsett.DownloadHDVideo=false; pltxtsett.DownloadAudio=false; pltxtsett.DownloadDescription=false; pltxtsett.DownloadAllKindsOfThumbnail=false; pltxtsett.starting=0; pltxtsett.ending=0; pltxtsett.havestarting=false; pltxtsett.haveending=false; } /* Parse PLTXT Settings Line In PLTXT (id=url2 in LoadQuery function and name=) */ void ParsePLTXTSettings(char* id,char* name){ pltxtsett.DownloadSDVideo=true; pltxtsett.DownloadHDVideo=false; pltxtsett.DownloadAudio=false; pltxtsett.DownloadThumbnail=false; pltxtsett.DownloadDescription=false; //ps yyyyy s=100:e=200 //po jared.txt NONEED if(strlen(id)>=1){ if(id[0]=='y' || id[0]=='Y'){ pltxtsett.DownloadSDVideo=true; }else{ { pltxtsett.DownloadSDVideo=false; } } } if(strlen(id)>=6){ if(id[5]=='y' || id[5]=='Y'){ pltxtsett.DownloadAllKindsOfThumbnail=true; }else{ { pltxtsett.DownloadAllKindsOfThumbnail=false; } } } if(strlen(id)>=2){ if(id[1]=='y' || id[1]=='Y'){ pltxtsett.DownloadHDVideo=true; }else{ { pltxtsett.DownloadHDVideo=false; } } } if(strlen(id)>=3){ if(id[2]=='y' || id[2]=='Y'){ pltxtsett.DownloadAudio=true; }else{ { pltxtsett.DownloadAudio=false; } } } if(strlen(id)>=4){ if(id[3]=='y' || id[3]=='Y'){ pltxtsett.DownloadThumbnail=true; }else{ { pltxtsett.DownloadThumbnail=false; } } } if(strlen(id)>=5){ if(id[4]=='y' || id[4]=='Y'){ pltxtsett.DownloadDescription=true; }else{ { pltxtsett.DownloadDescription=false; } } } char* token; token =strtok(name,":"); pltxtsett.starting=0; pltxtsett.ending=0; pltxtsett.havestarting=false; pltxtsett.haveending=false; while(token !=NULL){ switch(token[0]){ case 'e': pltxtsett.ending=atoi(token+2); pltxtsett.haveending=true; break; case 'x': break; case 's': pltxtsett.starting=atoi(token+2); pltxtsett.havestarting=true; break; } token = strtok(NULL,":"); } } void ChannelNew(char* channel,int isuser,int download,char* date); void Channel(char* channel,int isuser,int download); void PLTXTSearch(); void FileList(); void DrawList(); void DrawListSearch(); int pos = 0; int daycap=31; int monthcap=12; int channelsetting=-1;//-1 not enabled 0 for channel new 1 for user new 2 for channel 3 for user int monthnew=11;int daynew=15;int yearnew=2019; int downloadnotlist=1; //1 download 0 list int listtype=0;//0 none 1 searchtype 2 pltxt select int coldate=0;//0 is month 1 is day 2 is year GRRLIB_ttfFont* myFont; void LoadQuery(char *file); int keysleft =0; char buffer2[15]; void DL_IMAGES(char* name); void ListPartitions(disks *o); int redodownload=1; /* Error Window When Download Fails For Any Reason */ int ErrorWindow(){ int timeleft=420; int decrementval=1; while(timeleft >= 0){ //File Could Not Be Grabbed char what2[256]; double percent = ((double)timeleft / 420.0) * 100; int realp = (int)percent; if(realp>100||realp <0){ realp=0; } char isdown[200]; if(redodownload==1){sprintf(isdown,"Redownload Video is on (<-) to turn off");}else{sprintf(isdown,"Redownload Video is off (<-) to turn on");} sprintf(what2,"%is Left",timeleft); int x = 320-(((int)GRRLIB_WidthTTF (myFont, what2,72)) / 2); GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); GRRLIB_PrintfTTF(x, 192, myFont, what2, 72, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_Rectangle(268,192+120,104,32, GetColor(DOWNLOAD_PROGRESSBAR_BACKGROUND),1); GRRLIB_Rectangle(270,192+125,realp,22, GetColor(DOWNLOAD_PROGRESSBAR_FOREGROUND),1); GRRLIB_PrintfTTF(32,32, myFont, "Press (A) To Pause timer, Home cancel 1", 24, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_PrintfTTF(32,64, myFont, "Press (B) to return to downloading", 24, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_PrintfTTF(32,64+32, myFont,isdown , 24, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_Render(); WPAD_ScanPads(); // Scan the Wii Remotes u32 ke=WPAD_ButtonsDown(0); if(ke & WPAD_BUTTON_A){ if(decrementval == 0){ decrementval=1; }else{ decrementval=0; } } if(ke & WPAD_BUTTON_B){ break; } if(ke & WPAD_BUTTON_HOME){ return 0; } if(ke & WPAD_BUTTON_LEFT){ if(redodownload==0){redodownload=1;}else{redodownload=0;} } sleep(1); timeleft -= decrementval; } return redodownload; } /* Not Used (tried with wii keyboard but i could not figure it out */ void keyPress_cb( char sym) { if (sym > 31 ) {buffer2[keysleft]=sym;keysleft++;} if (sym == 13) {buffer2[keysleft]='\n';keysleft++;} if (sym == 8) {buffer2[keysleft]='\r';keysleft++;} if ( sym == 0x1b) { GRRLIB_Exit(); exit(0); } } /* WriteMemoryCallback */ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { dlf* S=((dlf*)userp); size_t realsize = size * nmemb; //DLFhandler(S,realsize); /* struct MemoryStruct *mem = (struct MemoryStruct *)userp; char *ptr = realloc(mem->memory, mem->size + realsize + 1); if(ptr == NULL) { printf("not enough memory (realloc returned NULL)\n"); return 0; } mem->memory = ptr; memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; */ fwrite(contents,size,nmemb,S->fp); return realsize; } int willtry=0; int videos=-1; ir_t ir; char videoitems[500][1001]; int keyboard = 0; int Download2(char*, char*,int); //Download2 Without PLTXT Position Number int Download(char* url, char* file){ return Download2(url,file,1); } //Download2 but returns void void Download4(char* url22223,char* file,int plid){ Download2(url22223,file,plid); } //used for left right history with textbox char history[2000][40]; int historyobjs = 0; int historyobj = -1; int mustadd=0; int addtopltxt=0; char pltxt[40]; int pltxtselected=0; void AddHistory(); void LoadHistory(); char url[2048]; //used for textbox //used for playlist void PlaylistEx(char*,char*,int*); void Playlist(char* pl){ int i=1; PlaylistEx(pl,"Playlist",&i); } void Search(char*); void PLSearch(char*); void LoadHistory(){ FILE *f =HistoryRead(); char download[40]; if (!f)return; while(fgets(download,40,f)!=NULL && historyobjs<2000){ for(int i = 0;i<41;i++){ if(download[i]=='\n'){ download[i]='\0'; break; } } sprintf(history[historyobjs],"%s",download); historyobjs++; } fclose(f); } void AddHistory(){ if(historyobjs<2000){ sprintf( history[historyobjs],"%s",url); char urls[42]; sprintf(urls,"%s\n",url); FILE *f =HistoryAppend(); fputs(urls,f); fclose(f); historyobjs++; } } /* OSK Keyboard */ #define KEYBOARD_MOVELEFT 180 #define KEYBOARD_MOVERIGHT 0 #define KEYBOARD_MOVEUP 90 #define KEYBOARD_MOVEDOWN 270 char keys[5][11] = {{'\\','.','?','<','{','}','`','&','>','%','<'}, {'0','1','2','3','4','5','6','7','8','9','~'},{'q','w','e','r','t','y','u','i','o','p','+'},{'a','s','d','f','g','h','j','k','l','(',')'},{'z','x','c','v','b','n','m','_','-',':',' '} }; char capkey[5][11] = {{'{','}','[',']','"','|','@','$','!','#','<'}, {'0','1','2','3','4','5','6','7','8','9','/'},{'Q','W','E','R','T','Y','U','I','O','P',','},{'A','S','D','F','G','H','J','K','L','[',']'},{'Z','X','C','V','B','N','M','_','-',';',' '} }; int charx; int chary; int caps; //standard url repair char* StandardURL(char* src) { char* code=malloc((strlen(src)*3)+1); code[0]='\0'; for(int i = 0;i<(int)strlen(src);i++){ if(src[i]=='+'){ sprintf(code,"%s%%2B",code); }else if(src[i]==','){ sprintf(code,"%s%%2C",code); }else if(src[i]=='('){ sprintf(code,"%s%%28",code); }else if(src[i]==')'){ sprintf(code,"%s%%29",code); }else if(src[i]=='['){ sprintf(code,"%s%%5B",code); }else if(src[i]==']'){ sprintf(code,"%s%%5D",code); }else if(src[i]==';'){ sprintf(code,"%s%%3B",code); }else if(src[i]==' ' || src[i]=='\\' ||src[i]=='<'|| src[i]=='{'|| src[i]=='}'||src[i]=='`'||src[i]=='>'||src[i]=='|' ||src[i]=='@' || src[i]== '$' || src[i]== '!' || src[i]=='#'){ sprintf(code,"%s%%20",code); } else{ sprintf(code,"%s%c",code,src[i]); } } return code; } //for youtube search char* ConvertString(char*src) { char* code=malloc((strlen(src)*3)+1); code[0]='\0'; for(int i = 0;i<(int)strlen(src);i++){ if(src[i]=='+'){ sprintf(code,"%s%%2B",code); }else if(src[i]==','){ sprintf(code,"%s%%2C",code); }else if(src[i]=='('){ sprintf(code,"%s%%28",code); }else if(src[i]==')'){ sprintf(code,"%s%%29",code); }else if(src[i]=='['){ sprintf(code,"%s%%5B",code); }else if(src[i]==']'){ sprintf(code,"%s%%5D",code); }else if(src[i]==';'){ sprintf(code,"%s%%3B",code); }else if(src[i]==' ' || src[i]=='\\' || src[i]=='?'||src[i]=='<'|| src[i]=='{'|| src[i]=='}'||src[i]=='`'||src[i]=='&'||src[i]=='>'|| src[i]=='%' ||src[i]=='|' ||src[i]=='@' || src[i]== '$' || src[i]== '!' || src[i]=='#' || src[i]=='~' || src[i]=='/'){ sprintf(code,"%s%%20",code); } else{ sprintf(code,"%s%c",code,src[i]); } } return code; } char* SString(char*src) { char* code=malloc((strlen(src)*3)+1); code[0]='\0'; for(int i = 0;i<(int)strlen(src);i++){ if(src[i]=='+'){ sprintf(code,"%s+",code); }else if(src[i]==','){ sprintf(code,"%s+",code); }else if(src[i]=='('){ sprintf(code,"%s+",code); }else if(src[i]==')'){ sprintf(code,"%s+",code); }else if(src[i]=='['){ sprintf(code,"%s+",code); }else if(src[i]==']'){ sprintf(code,"%s+",code); }else if(src[i]==';'){ sprintf(code,"%s+",code); }else if(src[i]==' ' || src[i]=='\\' || src[i]=='?'||src[i]=='<'|| src[i]=='{'|| src[i]=='}'||src[i]=='`'||src[i]=='&'||src[i]=='>'|| src[i]=='%' ||src[i]=='|' ||src[i]=='@' || src[i]== '$' || src[i]== '!' || src[i]=='#' || src[i]=='~' || src[i]=='/'){ sprintf(code,"%s+",code); } else{ sprintf(code,"%s%c",code,src[i]); } } return code; } //for repairing Youtube Filenames void PatchString(char*src) { for(int i = 0;i<(int)strlen(src);i++){ if(src[i]=='\n')src[i]=' '; if(src[i]=='\r')src[i]=' '; if(src[i]=='*')src[i]=' '; if(src[i]>=128)src[i]='_'; } } //Progress Screen With Percentage and purple progress static int older_progress(void* p, double dltotal, double dlnow, double ultotal, double ulnow) { dlf* ser = ((dlf*)p); char what2[256]; double percent = (dlnow / dltotal) * 100; int realp = (int)percent; if(realp>100||realp <0){ realp=0; } sprintf(what2,"%i%%",realp); GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); char filenamersr[1008]; sprintf(filenamersr,"%s",ser->fnam2); if(ser->fileid > 0){ sprintf(filenamersr,"%s.%i",filenamersr,ser->fileid); } char numb[2048]; sprintf(numb,"Item: %i",ser->fileindex); int x = 320-(((int)GRRLIB_WidthTTF (myFont, what2,72)) / 2); //GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); GRRLIB_PrintfTTF(x, 192, myFont, what2, 72, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_PrintfTTF(32, 32, myFont, filenamersr, 18, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_PrintfTTF(32, 64, myFont, numb, 18, GetColor(DOWNLOAD_PROGRESSVAL)); GRRLIB_Rectangle(268,192+120,104,32, GetColor(DOWNLOAD_PROGRESSBAR_BACKGROUND),1); GRRLIB_Rectangle(270,192+125,realp,22, GetColor(DOWNLOAD_PROGRESSBAR_FOREGROUND),1); GRRLIB_Render(); WPAD_ScanPads(); // Scan the Wii Remotes u32 ke=WPAD_ButtonsDown(0); if(ke & WPAD_BUTTON_HOME){ return 1; } return 0; } //draw keyboard void DrawKeyBoard(int posx, int posy) { for (int y = 0; y < 5; y++) { for (int x = 0; x < 11; x++) { if (chary == y && charx == x) { char sw[3]; if (caps == 1) { sprintf(sw, "%c", capkey[y][x]); } else { sprintf(sw, "%c", keys[y][x]); } //normal highlight GRRLIB_PrintfTTF(posx + (x * 20), posy + (y * 20), myFont, sw, 16, GetColor(DOWNLOAD_KEYBOARD_SELECT)); }else { char sw[3]; if (caps == 1) { sprintf(sw, "%c", capkey[y][x]); } else { sprintf(sw, "%c", keys[y][x]); } //normal highlight GRRLIB_PrintfTTF(posx + (x * 20), posy + (y * 20), myFont, sw, 16, GetColor(DOWNLOAD_KEYBOARD_UNSELECT)); } if(UsingIRFeatures()){ GRRLIB_Rectangle(posx + (x*20),posy + (y * 20),20,20,GetColor(DOWNLOAD_KEYBOARD_OUTLINE),0); } } } } void SetKeyFromCord(ir_t irs,int posx,int posy){ for (int y = 0; y < 4; y++) { for (int x = 0; x < 11; x++) { if(GRRLIB_PtInRect(posx + (x*20),posy + (y * 20),20,20,irs.x,irs.y)){ charx=x; chary=y; } } } } //control char Place() { if (caps == 1) { //capital char ks = capkey[chary][charx]; return ks; } char ks = keys[chary][charx]; return ks; } int GoingBack() { if (charx == 10 && chary == 0) { return 1; } return 0; } void Caps() { //caps Lock caps = !caps; } void KeyMove(int Direction) { switch (Direction) { case KEYBOARD_MOVELEFT: if (charx > 0){charx--;}else{charx=10;} break; case KEYBOARD_MOVERIGHT: if (charx < 10){charx++;}else{charx=0;} break; case KEYBOARD_MOVEUP: if (chary > 0){chary--;}else{chary=4;} break; case KEYBOARD_MOVEDOWN: if (chary < 4){chary++;}else{chary=0;} break; } } //draw search/pltxt lists void DrawList(){ if(listtype==1){ DrawListSearch(); }else if(listtype==2){ FileList(); } } //PLTXT List void FileList(){ for (int i = 0; i < 11; i++) { if (((pos + i)-6) >= 0 && ((pos + i)-6) <= videos) { int o=(i == 6); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o); GRRLIB_PrintfTTF(32,32+(30*i), myFont,videoitems[(pos + i)-6] , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); }} } //Search List void DrawListSearch() { int movover=0; if(willtry) movover=98; for (int i = 0; i < 5; i++) { if (((pos + i)-2) >= 0 && ((pos + i)-2) <= videos) { char id[13]; char title[500]; char author[500]; char author2[46]; char title2[46]; char thumbsUP[20]; char thumbsDown[20]; char views[20]; char uploadDate[20]; char length[20]; sscanf(videoitems[(pos + i)-2], "%13s %500s %500s %20s %20s %20s %20s %20s", id, title, author, thumbsUP, thumbsDown, views, uploadDate, length); snprintf(title2,sizeof(title2),"%s",title); snprintf(author2,sizeof(author2),"%s",author); PatchString(title2); PatchString(author2); int o=(i == 2); if(UsingIRFeatures()){ o=GRRLIB_PtInRect(32+movover,32+(90*i) , 576, 90,ir.x,ir.y); } GRRLIB_Rectangle(32,32+(90*i) , 576, 90, GetColor(DOWNLOAD_SELECTOR), o); GRRLIB_PrintfTTF(32+movover,32+(90*i), myFont, title2, 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); GRRLIB_PrintfTTF(32+movover, 32 + (90 * i)+18, myFont, author2, 16 ,GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); GRRLIB_PrintfTTF(32+movover, 32 + (90 * i)+36, myFont, uploadDate, 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); GRRLIB_PrintfTTF(32+movover, 32 + (90 * i)+54, myFont, length, 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); char VLD[30]; snprintf(VLD,30,"V: %s L: %s D: %s",views,thumbsUP,thumbsDown); GRRLIB_PrintfTTF(32+movover, 32 + (90 * i) + 72, myFont, VLD, 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); if(willtry){ char* ThumbFile =ThumbnailFileName(id); if(!ThumbnailExists(id)){ char* ThumbURI =ThumbnailURL(id); if(!Download(ThumbURI,ThumbFile)){ unlink(ThumbFile); } free(ThumbURI); } if(ThumbnailExists(id)){ GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile (ThumbFile); GRRLIB_DrawImg (32, 32 + (90 * i) + 9, tex, 0, 0.2, 0.2, RGBA(255,255,255,255)); GRRLIB_FreeTexture(tex); } free(ThumbFile); } } } /* ------------------------------------------------------------------------ TITLE UPLOAD DATE UPLOADER LENGTH VIEWS L D ------------------------------------------------------------------------- */ } int files=0; int iswad=0; /* When Buttons Are Pressed On Wii Mote and the keyboard is not active */ void WPAD_ONMENU(u32 key){ if(key & WPAD_BUTTON_MINUS){ PLTXTSearch(); } if(key & WPAD_BUTTON_PLUS){ if(listtype==2 && pos >-1 ){ //load pltxt and DoIT sprintf(pltxt,"%s",videoitems[pos]); pltxtselected=1; return; } } if (key & WPAD_BUTTON_2) { SwitchIR(); } if (key & WPAD_BUTTON_UP) { if(pos>-2)pos--; } if (key & WPAD_BUTTON_LEFT) { if(pos==-1){ if(historyobj>0){ historyobj--; sprintf(url,"%s",history[historyobj]); }else{ if(historyobjs>0){ historyobj=0; sprintf(url,"%s",history[historyobj]); } } } if(pos > -1){ //when someone presses left when on search listing char id[13]; char title[500]; sscanf(videoitems[pos], "%13s %500s", id, title); PatchString(title); char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/VideoHigh/%s",id); char* filenm = OpenVideoFile(filename); Download(idTool,filenm); free(filenm); } } if (key & WPAD_BUTTON_RIGHT) { if(pos==-1){ if(historyobj0){ pos=0; }else{ pos=-1; } } if (key & WPAD_BUTTON_DOWN) { if(pos-1){ if(GRRLIB_PtInRect(0,0,31,480,ir.x,ir.y)){ GRRLIB_Rectangle(0,0,31,480,GetColor(DOWNLOAD_SELECTOR),1); } if(GRRLIB_PtInRect(609,0,31,480,ir.x,ir.y)){ GRRLIB_Rectangle(609,0,31,480,GetColor(DOWNLOAD_SELECTOR),1); } }else if(GRRLIB_PtInRect(0,416,640,64,ir.x,ir.y)){ GRRLIB_Rectangle(0,416,640,64,GetColor(DOWNLOAD_SELECTOR),1); } } //IR stuff that is not completely implemented and hince I dont know where I have a working sensorbar I dont know when this stuff will be stable if (UsingIRFeatures() && (key & WPAD_BUTTON_A)){ if(pos>-1 && listtype !=2){ int clickid=0; int clickedtype=-1;//-1 no click 0 item 1 page up 2 page down //check if selected is -2 //x is always at least 32 and no more then 576+32 //y is always at least 32 and no more than 32+90 if(GRRLIB_PtInRect(0,0,31,480,ir.x,ir.y)){ clickedtype=1; } if(GRRLIB_PtInRect(609,0,31,480,ir.x,ir.y)){ clickedtype=2; } if(GRRLIB_PtInRect(32,32,576,90,ir.x,ir.y)){ clickid=-2; clickedtype=0; } if(GRRLIB_PtInRect(32,32+90,576,90,ir.x,ir.y)){ clickid=-1; clickedtype=0; } if(GRRLIB_PtInRect(32,32+(90*2),576,90,ir.x,ir.y)){ clickid=0; clickedtype=0; } if(GRRLIB_PtInRect(32,32+(90*3),576,90,ir.x,ir.y)){ clickid=1; clickedtype=0; } if(GRRLIB_PtInRect(32,32+(90*4),576,90,ir.x,ir.y)){ clickid=2; clickedtype=0; } if(clickedtype==0){ if ((pos + clickid) >= 0 && (pos + clickid) < videos) { char id[13]; char title[500]; sscanf(videoitems[pos + clickid], "%13s %500s", id, title); PatchString(title); char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); char* filer2 =OpenVideoFile(filename); Download(idTool,filer2); free(filer2); } }else if(clickedtype==1){ if(pos-5>=0){ pos-=5; }else{ pos=0; } }else if(clickedtype==2){ if(pos+5-1){ if(listtype==1){ //download char id[13]; char title[500]; sscanf(videoitems[pos], "%13s %500s", id, title); PatchString(title); char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); char* filer11 =OpenVideoFile(filename); Download(idTool,filer11); free(filer11); }else if(listtype==2){ //load pltxt and DoIT sprintf(pltxt,"%s",videoitems[pos]); pltxtselected=1; LoadQuery(pltxt); } }else if(pos==-1){ keyboard=1; } } } if(UsingIRFeatures() && (key & WPAD_BUTTON_1)){ int clickid=0; int clickedtype=0; if(pos>-1){ //-1 no click 0 item 1 page up 2 page down //check if selected is -2 //x is always at least 32 and no more then 576+32 //y is always at least 32 and no more than 32+90 if(GRRLIB_PtInRect(32,32,576,90,ir.x,ir.y)){ clickid=-2; clickedtype=1; } if(GRRLIB_PtInRect(32,32+90,576,90,ir.x,ir.y)){ clickid=-1; clickedtype=1; } if(GRRLIB_PtInRect(32,32+(90*2),576,90,ir.x,ir.y)){ clickid=0; clickedtype=1; } if(GRRLIB_PtInRect(32,32+(90*3),576,90,ir.x,ir.y)){ clickid=1; clickedtype=1; } if(GRRLIB_PtInRect(32,32+(90*4),576,90,ir.x,ir.y)){ clickid=2; clickedtype=1; } }else{ if(GRRLIB_PtInRect(150,224,340,32,ir.x,ir.y)&&pos==-1){ clickedtype=2; //not 1 } } if(clickedtype!=0){ char id[13]; if (((pos + clickid) >= 0 && (pos + clickid) < videos) && clickedtype==1) { sscanf(videoitems[pos + clickid], "%13s", id); }else{ sprintf(id,"%s",url); } char* idTool = ThumbnailURL(id); char* filename1= ThumbnailFileName(id); if(!ThumbnailExists(id)){ if(!Download(idTool,filename1)){ unlink(filename1); } } if(ThumbnailExists(id)){ GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile (filename1); while(1){ WPAD_ScanPads(); // Scan the Wii Remotes u32 ke=WPAD_ButtonsDown(0); if(ke & WPAD_BUTTON_B) break; GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); GRRLIB_DrawImg (32, 24, tex, 0, 1.2, 1.2, RGBA(255,255,255,255)); GRRLIB_Render(); } GRRLIB_FreeTexture (tex); } free(idTool); free(filename1); } }else{ if(key & WPAD_BUTTON_1){ char id[13]; if (pos >= 0 && pos < videos) { sscanf(videoitems[pos], "%13s", id); }else{ sprintf(id,"%s",url); } char* idTool = ThumbnailURL(id); char* filename1= ThumbnailFileName(id); if(!ThumbnailExists(id)){ if(!Download(idTool,filename1)){ unlink(filename1); } } if(ThumbnailExists(id)){ GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile (filename1); while(1){ WPAD_ScanPads(); // Scan the Wii Remotes u32 ke=WPAD_ButtonsDown(0); if(ke & WPAD_BUTTON_B) break; GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); GRRLIB_DrawImg (32, 24, tex, 0, 1.2, 1.2, RGBA(255,255,255,255)); GRRLIB_Render(); } GRRLIB_FreeTexture (tex); } free(idTool); free(filename1); } } if(UsingIRFeatures() && (key & WPAD_BUTTON_PLUS)){ int clickid=0; int clickedtype=0; if(pos>-1){ //-1 no click 0 item 1 page up 2 page down //check if selected is -2 //x is always at least 32 and no more then 576+32 //y is always at least 32 and no more than 32+90 if(GRRLIB_PtInRect(32,32,576,90,ir.x,ir.y)){ clickid=-2; clickedtype=1; } if(GRRLIB_PtInRect(32,32+90,576,90,ir.x,ir.y)){ clickid=-1; clickedtype=1; } if(GRRLIB_PtInRect(32,32+(90*2),576,90,ir.x,ir.y)){ clickid=0; clickedtype=1; } if(GRRLIB_PtInRect(32,32+(90*3),576,90,ir.x,ir.y)){ clickid=1; clickedtype=1; } if(GRRLIB_PtInRect(32,32+(90*4),576,90,ir.x,ir.y)){ clickid=2; clickedtype=1; } }else{ if(GRRLIB_PtInRect(150,224,340,32,ir.x,ir.y)&&pos==-1){ clickedtype=2; //not 1 } } if(clickedtype!=0){ char id[13]; if (((pos + clickid) >= 0 && (pos + clickid) < videos) && clickedtype==1 && pltxtselected==1) { char id[13]; char title[500]; sscanf(videoitems[pos + clickid], "%13s %500s", id, title); WriteFile2PL(pltxt,"vi",id,title); } } }else{ if(key & WPAD_BUTTON_PLUS){ char id[13]; char title[500]; sscanf(videoitems[pos], "%13s %500s", id, title); if (pos >= 0 && pos < videos && pltxtselected==1) { WriteFile2PL(pltxt,"vi",id,title); }}}} //BROKEN BUT MAY GET FIXED use //fixed /* Reads Document From Selected Storage That contains Playlist Info aka The heart of PLTXT (location **yourdisk**:/TYTD/PLTXT/[namehere].txt) */ void LoadQuery(char *file){ int filesr=1; FILE *f = PlaylistTXT(file); PLTXTInit(true); if(f){ while(1){ char type[3]; char url2[500]; char data[256]; if(fscanf(f," %3s %500s %256s",type,url2,data)==EOF)break; PatchString(data); if (strcmp("tn",type)==0){ //video on url2 char* idTool = ThumbnailURL(url2); char* filename1= ThumbnailFileName(url2); if(!ThumbnailExists(url2)){ if(!Download(idTool,filename1)){ unlink(filename1); } } free(idTool); free(filename1); if (pltxtsett.DownloadAllKindsOfThumbnail == true) { DownloadThumbnailsAlt(url2, filesr); } }else if (strcmp("vo",type)==0){ //video on url2 char filenamez[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); sprintf(filenamez,"%s(%s)",data,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/VideoHigh/%s",url2); char* far =OpenVideoFile(filenamez); Download2(idTool,far,filesr); free(far); }else if (strcmp("vi",type)==0){ //video on url2 char filenamez[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); sprintf(filenamez,"%s(%s)",data,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url2); char* filer2= OpenVideoFile(filenamez); Download2(idTool,filer2,filesr); free(filer2); }else if(strcmp("pl",type)==0){ //playlist on url2 PlaylistEx(url2,data,&filesr); } else if (strcmp("ps", type) == 0) { //playlist on url2 ParsePLTXTSettings(url2, data); } else if (strcmp("pe", type) == 0) { char* pld = CreatePL2(data); Download2(url2, pld, 1); free(pld); LoadQuery(data); } else if (strcmp("po", type) == 0) { LoadQuery(url2); }else if(strcmp("pd",type)==0){ char *pld2 = CreatePL2(data); Download2(url2,pld2,1); free(pld2); }else if(strcmp("dl",type)==0){ //playlist on url2 char* newurl= OpenFile(data); Download2(url2,newurl,filesr); free(newurl); } filesr++; } } PLTXTInit(false); fclose(f); } /* Keyboard Active Wii Mote Controls */ void WPAD_KEYBOARD(u32 key) { if(keysleft >0 && channelsetting==-1){ keysleft--; char keyr = buffer2[keysleft]; if (!(keyr == '\r' || keyr == '\n')) { snprintf(url, 2048, "%s%c", url, keyr); } else if(keyr == '\r' && keyr != '\n'){ if (strlen(url) > 0) { url[strlen(url) - 1] = '\0'; } } else if(keyr == '\n' && keyr != '\r'){ goto plus; } mustadd=1; } if (key & WPAD_BUTTON_2) { SwitchIR(); } if ((key & WPAD_BUTTON_B )&& channelsetting==-1) { Caps(); } if(channelsetting==-1){ if (key & WPAD_BUTTON_1) { //change keyboard if keyboard<4 instead of 3 LoadQuery Enabled if(keyboard<9){ keyboard++; }else{ keyboard=1; } } }else{ if (key & WPAD_BUTTON_1) { if(channelsetting<3){ channelsetting++; }else{ channelsetting=0; } } } if(channelsetting==-1){ if (key & WPAD_BUTTON_PLUS) { //apply plus: if(mustadd==1){ AddHistory(); mustadd=0; //keyboard=0; } if(keyboard==1){ Search(url); keyboard=0; } if(keyboard==4){ if(addtopltxt==1 && pltxtselected==1){ WriteFile2PL(pltxt,"pl",url,"NOTITLE"); }else{ Playlist(url); } keyboard=0; } if(keyboard==2){ if(addtopltxt==1 && pltxtselected==1){ WriteFile2PL(pltxt,"vi",url,"NOTITLE"); }else{ char filenamez[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); char title[300]; char idTool2[500]; sprintf(idTool2,"https://stark-shelf-08981.herokuapp.com/Grabber/info/%s",url); sprintf(title,"NOTITLE"); sprintf(filenamez,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); char* fname = OpenVideoFile(filenamez); Download(idTool,fname); } keyboard=0; } if(keyboard==5){ //LoadQuery(url); pltxtselected = 1; snprintf(pltxt,40,"%s.txt",url); CreatePL(pltxt); keyboard=0; } if(keyboard==7){ channelsetting=0; return; } if(keyboard==8){ if (addtopltxt==1){ addtopltxt=0; }else{ addtopltxt=1; } } if(keyboard==9){ char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); sprintf(filename, "%s_Desc(%s)", url, timein); char idTool[500]; sprintf(idTool, "https://stark-shelf-08981.herokuapp.com/Grabber/Descript/%s", url); char* viname = OpenDescFile( filename); Download2(idTool, viname, 1); free(viname); } if(keyboard==3){ if(addtopltxt==1 && pltxtselected==1){ WriteFile2PL(pltxt,"dl",url,"NOTITLE(%s).bin"); }else{ char filenamez[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); char title[300]; sprintf(title,"NOTITLE"); sprintf(filenamez,"%s(%s).bin",title,timein); char* filenm =OpenFile(filenamez); Download(url,filenm);free(filenm);} keyboard=0; } if(keyboard==6){ PLSearch(url); keyboard=0; } } }else{ if (key & WPAD_BUTTON_PLUS) { if(channelsetting==0){ //-1 not enabled 0 for channel new 1 for user new 2 for channel 3 for user char dates[12]; sprintf(dates,"%i-%i-%i",yearnew,monthnew,daynew); ChannelNew(url,0,downloadnotlist,dates); }else if(channelsetting==1){ char dates[12]; sprintf(dates,"%i-%i-%i",yearnew,monthnew,daynew); ChannelNew(url,1,downloadnotlist,dates); }else if(channelsetting==2){ //-1 not enabled 0 for channel new 1 for user new 2 for channel 3 for user Channel(url,0,downloadnotlist); }else if(channelsetting==3){ Channel(url,1,downloadnotlist); } keyboard =0; channelsetting=-1; } } if (key & WPAD_BUTTON_MINUS) { //cancel keyboard=0; channelsetting=-1; } if(channelsetting==-1){ if (key & WPAD_BUTTON_LEFT) { KeyMove(KEYBOARD_MOVELEFT); } if (key & WPAD_BUTTON_RIGHT) { KeyMove(KEYBOARD_MOVERIGHT); } if (key & WPAD_BUTTON_UP) { KeyMove(KEYBOARD_MOVEUP); } if (key & WPAD_BUTTON_DOWN) { KeyMove(KEYBOARD_MOVEDOWN); }}else if(channelsetting==0 || channelsetting==1){ if (key & WPAD_BUTTON_LEFT) { if(coldate>0){ coldate--; }else{ coldate=2; } } if (key & WPAD_BUTTON_RIGHT) { if(coldate<2){ coldate++; }else{ coldate=0; } } if (key & WPAD_BUTTON_UP) { if(coldate==0){ //month if(monthnew < monthcap){ monthnew++; }else{ monthnew=1; } } if(coldate==1){ //day if(daynew < daycap){ daynew++; }else{ daynew=1; } } if(coldate==2){ yearnew++; } } if (key & WPAD_BUTTON_DOWN) { if(coldate==0){ //month if(monthnew > 1){ monthnew--; }else{ monthnew=monthcap; } } if(coldate==1){ //day if(daynew > 1){ daynew--; }else{ daynew=daycap; } } if(coldate==2){ yearnew--; } } } if(channelsetting==-1){ if(UsingIRFeatures()){ SetKeyFromCord(ir,230,224+126); if(key & WPAD_BUTTON_A){ if(GRRLIB_PtInRect(150+50,224+35,340-100,32,ir.x,ir.y)){ if(mustadd==1){ AddHistory(); mustadd=0; } if(keyboard==1){ Search(url); } if(keyboard==4){ Playlist(url); } if(keyboard==2){ if(addtopltxt==1 && pltxtselected==1){ WriteFile2PL(pltxt,"vi",url,"NOTITLE"); }else{ char filenamez[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); char title[300]; sprintf(title,"NOTITLE"); sprintf(filenamez,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); char* filenm = OpenVideoFile(filenamez); Download(idTool,filenm); free(filenm); }keyboard=0; } if(keyboard==3){ if(addtopltxt==1 && pltxtselected==1){ WriteFile2PL(pltxt,"dl",url,"NOTITLE(%s).bin"); }else{ char filenamez[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); char title[300]; sprintf(title,"NOTITLE"); sprintf(filenamez,"%s(%s).bin",title,timein); char * filenm =OpenFile(filenamez); Download(url,filenm);free(filenm);} keyboard=0; } if(keyboard==5){ pltxtselected = 1; snprintf(pltxt,40,"%s.txt",url); CreatePL(pltxt); keyboard=0; } keyboard=0; }else{ if (GoingBack() == 0) { snprintf(url, 2048, "%s%c", url, Place()); } else { if (strlen(url) > 0) { url[strlen(url) - 1] = '\0'; } } mustadd=1; }} }else{ if (key & WPAD_BUTTON_A) { if (GoingBack() == 0) { snprintf(url, 2048, "%s%c", url, Place()); } else { if (strlen(url) > 0) { url[strlen(url) - 1] = '\0'; } } mustadd=1; } } }else{ if(key & WPAD_BUTTON_A){ if(downloadnotlist==0){ downloadnotlist=1; }else{ downloadnotlist=0; } } } } //close net int netclose_callback (void *clientp, curl_socket_t item) { return net_close(item); } /* File Download */ int Download2(char* url, char* file, int plid) { CURL* curl; curl = curl_easy_init(); dlf dr; dr.fp = fopen(file, "wb"); sprintf(dr.fnam, "%s", file); char* fnp = FileNameParse(file); sprintf(dr.fnam2, "%s", fnp); free(fnp); dr.fileid = 0; dr.fileindex = plid; curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, netclose_callback); /* disable progress meter, set to 0L to enable and disable debug output */ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, older_progress); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_PRIVATE, (void*)&dr); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void*)&dr); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&dr); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); int res = curl_easy_perform(curl); fclose(dr.fp); int ret = 0; if (allowredownloadscreen == true) { if (res == CURLE_OK) { long response_code; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); if (response_code == 200) { ret = 1; } else { unlink(file); if (ErrorWindow() == 1) { Download2(url, file, plid); } } } else { unlink(file); if (ErrorWindow() == 1) { Download2(url, file, plid); } } } curl_easy_cleanup(curl); return ret; } /* Search Window */ void Search(char* search) { char output2[600]; char* output = ConvertString(search); if (output) { sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/searchinfo/%s",output); if(Download(output2,TempVal)){ FILE *f = fopen(TempVal,"r"); char download[1001]; listtype=1; videos=-1; while(fgets(download,1001,f)!=NULL && videos<499){ videos++; sprintf(videoitems[videos],"%s",download); } fclose(f); DeleteTemp(); } } } /* Playlist Search */ void PLSearch(char* search) { listtype=1; char output2[600]; char* output = ConvertString(search); if (output) { sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/playlistinfo/%s",output); if(Download(output2,TempVal)){ FILE *f = fopen(TempVal,"r"); char download[1001]; videos=-1; while(fgets(download,1001,f)!=NULL && videos<499){ videos++; sprintf(videoitems[videos],"%s",download); } fclose(f); DeleteTemp(); } } } /* Playlist Video Grabber */ void PlaylistEx(char* search,char* nm,int* ptrs) { int indexise = 0; char output2[600]; char timeins[20]; time_t nows = time(0); strftime(timeins, sizeof(timeins), "%Y%m%d_%H%M%S", localtime(&nows)); char ssname[300]; sprintf(ssname,"%s(%s)",nm,timeins); OpenPlaylistFile(ssname); char* output = ConvertString(search); if (output) { sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/playlistinfo/%s",output); free(output); if(Download(output2,TempVal)){ FILE *f = fopen(TempVal,"r"); char download[1001]; while(fgets(download,1001,f)!=NULL ){ if (pltxtsett.pltxting == true && ((pltxtsett.havestarting == true && indexise < pltxtsett.starting)||(pltxtsett.haveending==true && indexise > pltxtsett.ending))) { indexise++; (*ptrs)++; continue; } char id[13]; char title[500]; sscanf(download, " %13s %500s", id, title); if (pltxtsett.pltxting && (pltxtsett.DownloadThumbnail == true || pltxtsett.DownloadAllKindsOfThumbnail == true)) { char* idTool = ThumbnailURL(id); char* filename1 = ThumbnailFileName(id); if (!ThumbnailExists(id)) { if (!Download(idTool, filename1)) { unlink(filename1); } } free(idTool); free(filename1); if (pltxtsett.DownloadAllKindsOfThumbnail == true) { DownloadThumbnailsAlt(id, *(ptrs)); } } if (pltxtsett.pltxting == false || pltxtsett.DownloadSDVideo == true) { char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); PatchString(title); sprintf(filename, "%s(%s)", title, timein); char idTool[500]; sprintf(idTool, "https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s", id); char* viname = OpenPlaylistVideoFile(ssname, filename); Download2(idTool, viname, *ptrs); free(viname); } if (pltxtsett.pltxting == true && pltxtsett.DownloadAudio == true) { char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); PatchString(title); sprintf(filename, "%s_Audio(%s)", title, timein); char idTool[500]; sprintf(idTool, "https://stark-shelf-08981.herokuapp.com/Grabber/Audio/%s", id); char* viname = OpenPlaylistVideoFile(ssname, filename); Download2(idTool, viname, *ptrs); free(viname); } if (pltxtsett.pltxting ==true && pltxtsett.DownloadHDVideo == true) { char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); PatchString(title); sprintf(filename, "%s_HD_VO(%s)", title, timein); char idTool[500]; sprintf(idTool, "https://stark-shelf-08981.herokuapp.com/Grabber/VideoHigh/%s", id); char* viname = OpenPlaylistVideoFile(ssname, filename); Download2(idTool, viname, *ptrs); free(viname); } if (pltxtsett.pltxting == false || pltxtsett.DownloadDescription == true) { char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); PatchString(title); sprintf(filename, "%s_Desc(%s)", title, timein); char idTool[500]; sprintf(idTool, "https://stark-shelf-08981.herokuapp.com/Grabber/Descript/%s", id); char* viname = OpenPlaylistDescFile(ssname, filename); Download2(idTool, viname, *ptrs); free(viname); } indexise++; (*ptrs)++; } DeleteTemp(); } } } int running = 1; /* To Use PressKey() instead of WPAD_KEYBOARD() and WPAD_ONMENU() everywhere */ void PressKey(u32 key){ if (keyboard>0) { WPAD_KEYBOARD(key); }else{ WPAD_ONMENU(key); } }/* void keyPress_cb( char sym) { if (keyboard>0 && ((sym >= 'a' && sym <= 'z') || (sym>='A' && sym <='Z' ) || (sym>='0' && sym<='9') || sym=='_' || sym==' ' || sym=='+' || sym=='(' || sym==')' || sym=='[' || sym==']'||sym==','||sym=='-'||sym==':'||sym==';')) snprintf(url, 40, "%s%c", url, sym); if (sym == 13) {if(keyboard==0){PressKey(WPAD_BUTTON_A);}else{PressKey(WPAD_BUTTON_PLUS);}} if (sym & KS_Up){ if(keyboard==0){ PressKey(WPAD_BUTTON_UP); } } if (sym & KS_Down){ if(keyboard==0){ PressKey(WPAD_BUTTON_DOWN); } } if (sym & KS_F1 || sym & KS_f1){ if(keyboard==0){ if(pos>-2){ pos=-2; }else{ pos=-3; } } } if (sym & KS_F2 || sym & KS_f2){ if(keyboard>0){ PressKey(WPAD_BUTTON_1); } } if (sym & KS_F3 || sym & KS_f3){ if(keyboard==0){ PressKey(WPAD_BUTTON_B); }else{ PressKey(WPAD_BUTTON_MINUS); } } if ( sym & 0x1b) running=0; }*/ /* Main Function Contains main loop and other gui stuff */ int main() { char options[9][50]={"Input Search Term","Input Youtube URL","Input File URL","Input Playlist URL","Create PLTXT File","Playlist As Search","Channel","Add To PL","Description"}; char optionsforChannel[4][50]={"Channel New Videos","ChannelUser New Videos","Channel Videos","ChannelUser Videos"}; char listingmode[2][9]={"List","Download"}; WPAD_Init(); GRRLIB_Init(); myFont = GRRLIB_LoadTTF(FreeMonoBold_ttf, FreeMonoBold_ttf_size); WPAD_SetVRes(0,640,480); WPAD_SetDataFormat(WPAD_CHAN_0,WPAD_FMT_BTNS_ACC_IR); InitColor(0); int csch=0; while(1){ WPAD_ScanPads(); // Scan the Wii Remotes GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); if(UsingIRFeatures()){ WPAD_IR(0,&ir); GRRLIB_Rectangle(ir.x,ir.y,4,4,GetColor(DOWNLOAD_CURSOR),1); } u32 ke=WPAD_ButtonsDown(0); if (ke & WPAD_BUTTON_A) { break; } if (ke & WPAD_BUTTON_1) { csch = AddScheme(csch); InitColor(csch); } if (ke & WPAD_BUTTON_2) { SwitchIR(); } if(ke & WPAD_BUTTON_B){ if(willtry){ willtry=0; }else{ willtry=1; } } GRRLIB_PrintfTTF(50, 50, myFont,"Press (A) To Enter TYTD", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); char listimages[40]; if(willtry){ sprintf(listimages,"Download thumbnails is on Press (B) to change"); }else{ sprintf(listimages,"Download thumbnails is off press (B) to change"); } GRRLIB_PrintfTTF(50, 50+30, myFont,listimages , 18, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); char sensor[40]; if(UsingIRFeatures()){ sprintf(sensor,"IR is on press (2) to change anytime"); }else{ sprintf(sensor,"IR is off press (2) to change anytime"); } GRRLIB_PrintfTTF(50, 50+60, myFont,sensor, 18, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); char scl[40]; sprintf(scl,"press (1) for colorscheme, colorscheme=%i",csch); GRRLIB_PrintfTTF(50, 50+90, myFont,scl, 18, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); GRRLIB_Render(); } ListPartitions(FileSystemDrivers()); CreateFolders(); wiisocket_init(); //KEYBOARD_Init(keyPress_cb); // Initialise the video system // This function initialises the attached controllers LoadHistory(); //printf("\n\n\n\nwhats on your mind\n\n(-) Playlist URL (+) URL (2) Search"); //url[0]='\0'; //early testing //sprintf(url,"Demi Lovato"); char pltxtadds[2][50] ={"Add To PLTXT: OFF","Add To PLTXT: ON"}; pos=-1; //keyboard=1; while (running) { WPAD_ScanPads(); // Scan the Wii Remotes GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); u32 ke=WPAD_ButtonsDown(0); if (ke & WPAD_BUTTON_HOME) { break; } if(pos>-1){ WPAD_ONMENU(ke); DrawList(); }else if(pos==-2){ WPAD_ONMENU(ke); GRRLIB_PrintfTTF(32, 32, myFont,"Controls", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 64, myFont," (DPAD) MOVE (A) Place Letter", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 64+32, myFont,"if Letter is '<' then backspace", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 128, myFont,"(-) Cancel (+) Accept", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 128+32, myFont,"(B) Caps (1) Change Method", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256, myFont,"
(DPAD UP/DOWN) MOVE", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+32, myFont,"(A) Enable KB/Download", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+64, myFont,"UP ON LIST BRINGS YOU TO ", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+64+32, myFont,"SEARCH SCREEN (B) Advance To Top ", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+64+64, myFont,"THIS SCREEN/FIRST ELEMENT (B) Search Screen", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text }else if(pos==-3){ WPAD_ONMENU(ke); GRRLIB_PrintfTTF(32, 32, myFont,"Controls", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256, myFont,"
UP/DOWN MOVE", 24,GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+32, myFont,"ENTER Enable KB/Download", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+64, myFont,"UP ON LIST BRINGS YOU TO ", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+64+32, myFont,"SEARCH SCREEN Advance To Top ", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text GRRLIB_PrintfTTF(32, 256+64+64, myFont,"THIS SCREEN/FIRST ELEMENT Search Screen", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //white text }else{ //draw white rectangle if(channelsetting<0){ GRRLIB_Rectangle(0,223,640,34, GetColor(DOWNLOAD_TEXTBOX_FOREGROUND),0); GRRLIB_Rectangle(0,224,640,32, GetColor(DOWNLOAD_TEXTBOX_BACKGROUND),1); } //draw keyboard if(keyboard>0){ WPAD_KEYBOARD(ke); GRRLIB_PrintfTTF(12,223-30, myFont,pltxtadds[addtopltxt], 24,GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); if(channelsetting>-1){ GRRLIB_PrintfTTF(128+90+90, 227+30, myFont,listingmode[downloadnotlist], 24,GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); int offsetforstring2=(int)(GRRLIB_WidthTTF (myFont, optionsforChannel[channelsetting], 24))/2; int startx2=320-offsetforstring2; GRRLIB_PrintfTTF(startx2, 96, myFont,optionsforChannel[channelsetting], 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //black text if(channelsetting<2){ //draw date char mon[4]; char dat[4]; char yer[5]; sprintf(mon,"%i-",monthnew); sprintf(dat,"%i-",daynew); snprintf(yer,5,"%i",yearnew); if(coldate==0){ GRRLIB_PrintfTTF(128, 227, myFont,mon, 24,GetColor(DOWNLOAD_TEXTBOX_BACKGROUND)); }else{ GRRLIB_PrintfTTF(128, 227, myFont,mon, 24,GetColor(DOWNLOAD_TEXTBOX_FOREGROUND)); } if(coldate==1){ GRRLIB_PrintfTTF(128+90, 227, myFont,dat, 24,GetColor(DOWNLOAD_TEXTBOX_BACKGROUND)); }else{ GRRLIB_PrintfTTF(128+90, 227, myFont,dat, 24,GetColor(DOWNLOAD_TEXTBOX_FOREGROUND)); } if(coldate==2){ GRRLIB_PrintfTTF(128+90+90, 227, myFont,yer, 24,GetColor(DOWNLOAD_TEXTBOX_BACKGROUND)); }else{ GRRLIB_PrintfTTF(128+90+90, 227, myFont,yer, 24,GetColor(DOWNLOAD_TEXTBOX_FOREGROUND)); } } }else{ DrawKeyBoard(230,224+126); if(UsingIRFeatures()){ GRRLIB_Rectangle(150+50,224+35,340-100,32, GetColor(DOWNLOAD_SELECTOR),1); int offsetforstring=(int)(GRRLIB_WidthTTF (myFont, "Submit", 24))/2; int startx=320-offsetforstring; GRRLIB_PrintfTTF(startx, 227+35, myFont,"Submit", 24, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); //blue text } }}else{ GRRLIB_PrintfTTF(32, 400, myFont,"to access help Press Up", 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //black text WPAD_ONMENU(ke); } if(channelsetting<0){ //center text in white rectangle AKA textbox int offsetforstring=(int)(GRRLIB_WidthTTF (myFont, url, 24))/2; int startx=320-offsetforstring; GRRLIB_PrintfTTF(startx, 227, myFont,url, 24,GetColor(DOWNLOAD_TEXTBOX_FOREGROUND)); //black text //draw Option if(keyboard>0){ int offsetforstring2=(int)(GRRLIB_WidthTTF (myFont, options[keyboard-1], 24))/2; int startx2=320-offsetforstring2; GRRLIB_PrintfTTF(startx2, 96, myFont,options[keyboard-1], 24, GetColor(DOWNLOAD_FOREGROUND_NO_SELECTOR)); //black text } }} if(UsingIRFeatures()){ WPAD_IR(0,&ir); GRRLIB_Rectangle(ir.x,ir.y,4,4,GetColor(DOWNLOAD_CURSOR),1); } GRRLIB_Render(); } GRRLIB_FreeTTF(myFont); GRRLIB_Exit(); exit(0); return 0; } /* Download Entire Channel or list it */ void Channel(char* channel,int isuser,int downlo){ char output2[600]; int idn =1; if(isuser){ sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/User/%s",channel); }else{ sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/Channel/%s",channel); } if(Download(output2,TempVal)){ FILE *f = fopen(TempVal,"r"); char downloa[1001]; if(!downlo) {videos=-1;listtype=1;} while(fgets(downloa,1001,f)!=NULL && (videos<499 || downlo==1)){ if(downlo){ char id[13]; char title[500]; sscanf(downloa, " %13s %500s", id, title); char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); PatchString(title); sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); char* finm = OpenVideoFile(filename); Download2(idTool,finm,idn); free(finm); idn++; }else{ videos++; sprintf(videoitems[videos],"%s",downloa); } } DeleteTemp(); } } /* Download or View Videos on channel that came out on or after date */ void ChannelNew(char* channel,int isuser,int downlo,char* date){ int idn=1; char output2[600]; if(isuser){ sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/UserNew/%s/%s",date,channel); }else{ sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/ChannelNew/%s/%s",date,channel); } if(Download(output2,TempVal)){ FILE *f = fopen(TempVal,"r"); char downloa[1001]; if(!downlo){ videos=-1; listtype=1;} while(fgets(downloa,1001,f)!=NULL && (videos<499 || downlo==1)){ if(downlo){ char id[13]; char title[500]; sscanf(downloa, " %13s %500s", id, title); char filename[530]; char timein[20]; time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); PatchString(title); sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); char* fnma =OpenVideoFile(filename); Download2(idTool,fnma,idn); free(fnma); idn++; }else{ videos++; sprintf(videoitems[videos],"%s",downloa); } } DeleteTemp(); } } /* Create PLTXT Select Menu */ void PLTXTSearch(){ videos=-1; DIR *pdir; struct dirent *pent; pdir=opendir(PLTXTDIR()); listtype=2; if (!pdir){ exit(0); } while ((pent=readdir(pdir))!=NULL) { if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0) continue; if(pent->d_type == DT_REG){ videos++; sprintf(videoitems[videos],"%s",pent->d_name); } } closedir(pdir); // // } /* Unused DL Images Doesnt work */ void DL_IMAGES(char* name){ char url2222[3000]; sprintf(url2222,"https://www.google.com/search?tbm=isch&q=%s",SString(name)); Download(url2222,TempVal); FILE *f = fopen(TempVal,"r"); fseek(f,SEEK_END,0); long lengths=ftell(f); char* array = malloc(sizeof(char) * (lengths + 3)); array[lengths+1]; rewind(f); fread(array,sizeof(char),lengths,f); char url2223[2048]; int chartype = 0; //0 is no 1=s 2 = r 3 = c 4 = = 5 = " int strp = 0; int filesr=1; for(size_t ie=0;iesdfat + o->usbfat + o->ntfsc)-1){ sel++; } } if(ke & WPAD_BUTTON_UP){ if(sel>0){ sel--; } } int offset=o->sdfat + o->usbfat; for (int i = 0; i < (o->sdfat + o->usbfat + o->ntfsc); i++) { //sd sdntfs usb usbntfs if(i >= offset){ //sdntfs char usbid[20]; char *names =ntfsGetVolumeName (o->ntfsv[i-offset].name); if(names){ //volume int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,names , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); }else{ //usbid int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,o->ntfsv[i-offset].name , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); } if(selected){ if(sel == i){ SetRoot(o->ntfsv[i-offset].name); break; } } }else if(i == 0 && o->sdfat==TRUE){ //sd char names[50]; names[49]=0; fatGetVolumeLabel ("sd", names); if(((int)strlen(names))>0){ //volume int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,names , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); }else{ //usbid int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,"sd" , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); } if(selected){ if(sel == i){ SetRoot("sd"); break; } } }else if(i == 0 && o->sdfat==FALSE && o->usbfat==TRUE){ //sd char names[50]; names[49]=0; fatGetVolumeLabel ("usb", names); if(((int)strlen(names))>0){ //volume int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,names , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); }else{ //usbid int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,"usb" , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); } if(selected){ if(sel == i){ SetRoot("usb"); break; } } }else if(i == 1 && o->sdfat==TRUE && o->usbfat==TRUE){ //sd char names[50]; names[49]=0; fatGetVolumeLabel ("usb", names); if(((int)strlen(names))>0){ //volume int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,names , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); }else{ //usbid int o2=(i == sel); GRRLIB_Rectangle(32,32+(30*i) , 576, 30, GetColor(DOWNLOAD_SELECTOR), o2); GRRLIB_PrintfTTF(32,32+(30*i), myFont,"usb" , 16, GetColor(DOWNLOAD_FOREGROUND_SELECTOR)); } if(selected){ if(sel == i){ SetRoot("usb"); break; } } } } if(selected)break; GRRLIB_Render(); } }