diff --git a/Makefile b/Makefile index 5d5dfa5..facdb7f 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map LIBS := -lgrrlib -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lwiisocket LIBS += -lfreetype -lbz2 LIBS += -lpngu -lpng -ljpeg -lz -lntfs -lfat -LIBS += -lwiiuse +LIBS += -lwiikeyboard -lwiiuse #LIBS += -lmodplay -laesnd LIBS += -lbte -logc -lm diff --git a/source/main.c b/source/main.c index 0da955a..4889de6 100644 --- a/source/main.c +++ b/source/main.c @@ -1,15 +1,36 @@ #include "colors.h" +#include + void ChannelNew(char* channel,int isuser,int download,char* date); -void Channel(char* channel,int isuser,int download); +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 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); + } +} static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { @@ -38,18 +59,26 @@ int videos=-1; ir_t ir; char videoitems[500][1001]; int keyboard = 0; -int Download(char*, char*); +int Download2(char*, char*,int); +int Download(char* url, char* file){ + return Download2(url,file,1); +} 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[40]; -void PlaylistEx(char*,char*); +char url[2048]; +void PlaylistEx(char*,char*,int*); void Playlist(char* pl){ - PlaylistEx(pl,"Playlist"); + int i=1; + PlaylistEx(pl,"Playlist",&i); } + void Search(char*); void PLSearch(char*); @@ -84,18 +113,46 @@ fclose(f); historyobjs++; } } -#define KEYBOARD_MOVELEFT 180 -#define KEYBOARD_MOVERIGHT 0 -#define KEYBOARD_MOVEUP 90 -#define KEYBOARD_MOVEDOWN 270 -char keys[4][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[4][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; - -//draw function +#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; +//draw function +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; +} char* ConvertString(char*src) { char* code=malloc((strlen(src)*3)+1); @@ -115,9 +172,39 @@ char* ConvertString(char*src) sprintf(code,"%s%%5D",code); }else if(src[i]==';'){ sprintf(code,"%s%%3B",code); - }else if(src[i]==' '){ + }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{ +} + 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]); } @@ -133,67 +220,75 @@ void PatchString(char*src) if(src[i]=='*')src[i]=' '; if(src[i]>=128)src[i]='_'; } -} +} 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; +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); + } + + + sprintf(what2,"%i%%",realp); GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); char filenamersr[1008]; - sprintf(filenamersr,"%s",ser->fnam); + sprintf(filenamersr,"%s",ser->fnam2); if(ser->fileid > 0){ sprintf(filenamersr,"%s.%i",filenamersr,ser->fileid); } - int x = 320-(((int)GRRLIB_WidthTTF (myFont, what2,72)) / 2); +char numb[2048]; +sprintf(numb,"Item: %i",ser->fileindex); + int x = 320-(((int)GRRLIB_WidthTTF (myFont, what2,72)) / 2); GRRLIB_PrintfTTF(x, 192, myFont, what2, 72, GetColor(DOWNLOAD_PROGRESSVAL)); - GRRLIB_PrintfTTF(32, 32, myFont, filenamersr, 24, 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(); - return 0; -} + + GRRLIB_Render(); + WPAD_ScanPads(); // Scan the Wii Remotes + u32 ke=WPAD_ButtonsDown(0); + if(ke & WPAD_BUTTON_HOME){ + return 1; + } + return 0; +} void DrawKeyBoard(int posx, int posy) { - - for (int y = 0; y < 4; 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)); - - + + 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++) { @@ -207,69 +302,85 @@ void SetKeyFromCord(ir_t irs,int posx,int posy){ } } - - -//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--; - break; - case KEYBOARD_MOVERIGHT: - if (charx < 10)charx++; - break; - case KEYBOARD_MOVEUP: - if (chary > 0)chary--; - break; - case KEYBOARD_MOVEDOWN: - if (chary < 3)chary++; - break; - } - } - -void DrawList() { + + +//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; + } + } + +void DrawList(){ +if(listtype==1){ +DrawListSearch(); +}else if(listtype==2){ +FileList(); +} +} +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)); +}} +} +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]; + 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); + 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); @@ -278,14 +389,14 @@ void DrawList() { 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)); + 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){ if(!ThumbnailExists(id)){ if(!Download(ThumbnailURL(id),ThumbnailFileName(id))){ @@ -298,27 +409,38 @@ void DrawList() { GRRLIB_DrawImg (32, 32 + (90 * i) + 9, tex, 0, 0.2, 0.2, RGBA(255,255,255,255)); GRRLIB_FreeTexture(tex); }} - } - } - - /* - ------------------------------------------------------------------------ - TITLE UPLOAD DATE - UPLOADER LENGTH - VIEWS L D - ------------------------------------------------------------------------- - */ - - } - - + } + } + + /* + ------------------------------------------------------------------------ + TITLE UPLOAD DATE + UPLOADER LENGTH + VIEWS L D + ------------------------------------------------------------------------- + */ + + } + + int files=0; int iswad=0; 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(); } @@ -379,7 +501,7 @@ void WPAD_ONMENU(u32 key){ } } if (UsingIRFeatures() && (key & WPAD_BUTTON_A)){ - if(pos>-1){ + if(pos>-1 && listtype !=2){ int clickid=0; int clickedtype=-1;//-1 no click 0 item 1 page up 2 page down @@ -418,6 +540,7 @@ void WPAD_ONMENU(u32 key){ } if(GRRLIB_PtInRect(32,32+(90*4),576,90,ir.x,ir.y)){ clickid=2; + clickedtype=0; } @@ -466,6 +589,7 @@ void WPAD_ONMENU(u32 key){ if (key & WPAD_BUTTON_A) { if(pos>-1){ +if(listtype==1){ //download char id[13]; char title[500]; @@ -480,7 +604,12 @@ void WPAD_ONMENU(u32 key){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); Download(idTool,OpenVideoFile(filename)); - +}else if(listtype==2){ + //load pltxt and DoIT + sprintf(pltxt,"%s",videoitems[pos]); +pltxtselected=1; + LoadQuery(pltxt); +} }else if(pos==-1){ keyboard=1; } @@ -588,13 +717,79 @@ if(UsingIRFeatures() && (key & WPAD_BUTTON_1)){ GRRLIB_FreeTexture (tex); }} } -} +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 void LoadQuery(char *file){ - + int filesr=1; FILE *f = PlaylistTXT(file); if(f){ while(1){ @@ -631,15 +826,16 @@ void LoadQuery(char *file){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url2); - Download(idTool,OpenVideoFile(filenamez)); + Download2(idTool,OpenVideoFile(filenamez),filesr); }else if(strcmp("pl",type)==0){ //playlist on url2 - PlaylistEx(url2,data); + PlaylistEx(url2,data,&filesr); }else if(strcmp("dl",type)==0){ //playlist on url2 - Download(url2,OpenFile(data)); + Download2(url2,OpenFile(data),filesr); } +filesr++; } } @@ -647,6 +843,28 @@ void LoadQuery(char *file){ } 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(); } @@ -659,7 +877,7 @@ if (key & WPAD_BUTTON_2) { if (key & WPAD_BUTTON_1) { //change keyboard if keyboard<4 instead of 3 LoadQuery Enabled - if(keyboard<6){ + if(keyboard<9){ keyboard++; }else{ keyboard=1; @@ -676,23 +894,32 @@ if (key & WPAD_BUTTON_2) { } } if(channelsetting==-1){ + if (key & WPAD_BUTTON_PLUS) { //apply + plus: if(mustadd==1){ AddHistory(); mustadd=0; - keyboard=0; + //keyboard=0; } if(keyboard==1){ Search(url); keyboard=0; } - if(keyboard==3){ + 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); @@ -701,15 +928,9 @@ if(channelsetting==-1){ char idTool2[500]; sprintf(idTool2,"https://stark-shelf-08981.herokuapp.com/Grabber/info/%s",url); - if(Download(idTool2,Temp())){ - FILE *f = fopen(Temp(),"r"); - fgets(title,300,f); - fclose(f); - DeleteTemp(); - PatchString(title); - }else{ + sprintf(title,"NOTITLE"); - } + sprintf(filenamez,"%s(%s)",title,timein); @@ -717,18 +938,55 @@ if(channelsetting==-1){ sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); Download(idTool,OpenVideoFile(filenamez)); +} keyboard=0; } - if(keyboard==4){ - LoadQuery(url); + if(keyboard==5){ + //LoadQuery(url); + pltxtselected = 1; +snprintf(pltxt,40,"%s.txt",url); + CreatePL(pltxt); + keyboard=0; } - if(keyboard==6){ + if(keyboard==7){ + channelsetting=0; return; } - if(keyboard==5){ + if(keyboard==8){ + if (addtopltxt==1){ +addtopltxt=0; +}else{ +addtopltxt=1; +} +} + if(keyboard==9){ + DL_IMAGES(url); +} + 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); + + Download(url,OpenFile(filenamez));} +keyboard=0; + } + if(keyboard==6){ PLSearch(url); keyboard=0; } @@ -850,30 +1108,23 @@ keyboard=0; if(keyboard==1){ Search(url); } - if(keyboard==3){ + 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]; - - char idTool2[500]; - sprintf(idTool2,"https://stark-shelf-08981.herokuapp.com/Grabber/info/%s",url); - if(Download(idTool2,Temp())){ - FILE *f = fopen(Temp(),"r"); - fgets(title,300,f); - fclose(f); - DeleteTemp(); - PatchString(title); - }else{ + sprintf(title,"NOTITLE"); - } + sprintf(filenamez,"%s(%s)",title,timein); @@ -881,15 +1132,41 @@ keyboard=0; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); Download(idTool,OpenVideoFile(filenamez)); +}keyboard=0; } - if(keyboard==4){ - LoadQuery(url); + 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); + + Download(url,OpenFile(filenamez));} +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, 40, "%s%c", url, Place()); + snprintf(url, 2048, "%s%c", url, Place()); } else { @@ -903,7 +1180,7 @@ keyboard=0; if (key & WPAD_BUTTON_A) { if (GoingBack() == 0) { - snprintf(url, 40, "%s%c", url, Place()); + snprintf(url, 2048, "%s%c", url, Place()); } else { @@ -929,15 +1206,18 @@ keyboard=0; int netclose_callback (void *clientp, curl_socket_t item) { return net_close(item); } -int Download(char* url, char* file) { + +int Download2(char* url, char* file,int plid) { CURL* curl; curl = curl_easy_init(); int ret=1; dlf dr; dr.fp =fopen(file,"wb"); sprintf(dr.fnam,"%s",file); + + sprintf(dr.fnam2,"%s",FileNameParse(file)); 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); @@ -965,6 +1245,7 @@ curl_easy_cleanup(curl); return ret; } void Search(char* search) { + char output2[600]; char* output = ConvertString(search); @@ -974,6 +1255,7 @@ void Search(char* search) { if(Download(output2,Temp())){ FILE *f = fopen(Temp(),"r"); char download[1001]; + listtype=1; videos=-1; while(fgets(download,1001,f)!=NULL && videos<499){ @@ -991,6 +1273,7 @@ void Search(char* search) { } } void PLSearch(char* search) { +listtype=1; char output2[600]; char* output = ConvertString(search); @@ -1017,12 +1300,13 @@ void PLSearch(char* search) { } -void PlaylistEx(char* search,char* nm) { +void PlaylistEx(char* search,char* nm,int* ptrs) { + 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]; + char ssname[300]; sprintf(ssname,"%s(%s)",nm,timeins); OpenPlaylistFile(ssname); char* output = ConvertString(search); @@ -1047,9 +1331,9 @@ char timeins[20]; char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download(idTool,OpenPlaylistVideoFile(ssname,filename)); + Download2(idTool,OpenPlaylistVideoFile(ssname,filename),*ptrs); - + (*ptrs)++; } DeleteTemp(); } @@ -1112,7 +1396,7 @@ void keyPress_cb( char sym) { }*/ int main() { - char options[6][50]={"Input Search Term","Input Youtube URL","Input Playlist URL","Input Playlist Text File","Playlist As Search","Channel"}; + 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","Google Images"}; char optionsforChannel[4][50]={"Channel New Videos","ChannelUser New Videos","Channel Videos","ChannelUser Videos"}; char listingmode[2][9]={"List","Download"}; WPAD_Init(); @@ -1181,12 +1465,12 @@ FileSystemDrivers(); CreateFolders(); net_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"); @@ -1194,6 +1478,7 @@ LoadHistory(); //early testing //sprintf(url,"Demi Lovato"); +char pltxtadds[2][50] ={"Add To PLTXT: OFF","Add To PLTXT: ON"}; pos=-1; //keyboard=1; while (running) { @@ -1238,13 +1523,16 @@ pos=-1; //draw white rectangle if(channelsetting<0){ - GRRLIB_Rectangle(150,224,340,32, GetColor(DOWNLOAD_TEXTBOX_BACKGROUND),1); + 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)); @@ -1334,7 +1622,7 @@ pos=-1; 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{ @@ -1346,7 +1634,7 @@ char output2[600]; if(Download(output2,Temp())){ FILE *f = fopen(Temp(),"r"); char downloa[1001]; - if(!downlo) videos=-1; + if(!downlo) {videos=-1;listtype=1;} while(fgets(downloa,1001,f)!=NULL && (videos<499 || downlo==1)){ if(downlo){ char id[13]; @@ -1361,8 +1649,8 @@ if(downlo){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download(idTool,OpenVideoFile(filename)); - + Download2(idTool,OpenVideoFile(filename),idn); +idn++; }else{ videos++; sprintf(videoitems[videos],"%s",downloa); @@ -1380,6 +1668,7 @@ if(downlo){ void ChannelNew(char* channel,int isuser,int downlo,char* date){ +int idn=1; char output2[600]; if(isuser){ @@ -1393,7 +1682,7 @@ void ChannelNew(char* channel,int isuser,int downlo,char* date){ if(Download(output2,Temp())){ FILE *f = fopen(Temp(),"r"); char downloa[1001]; - if(!downlo) videos=-1; + if(!downlo){ videos=-1; listtype=1;} while(fgets(downloa,1001,f)!=NULL && (videos<499 || downlo==1)){ if(downlo){ @@ -1409,8 +1698,8 @@ if(downlo){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download(idTool,OpenVideoFile(filename)); - + Download2(idTool,OpenVideoFile(filename),idn); +idn++; }else{ videos++; sprintf(videoitems[videos],"%s",downloa); @@ -1423,3 +1712,104 @@ if(downlo){ } +void PLTXTSearch(){ +videos=-1; +DIR *pdir; + struct dirent *pent; + + pdir=opendir("/TYTD/PLTXT/"); +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); + // + // + +} + +void DL_IMAGES(char* name){ + char url2222[3000]; + sprintf(url2222,"https://www.google.com/search?tbm=isch&q=%s",SString(name)); + Download(url2222,Temp()); + FILE *f = fopen(Temp(),"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;iefp) + real; @@ -30,9 +45,29 @@ FILE* HistoryAppend(){ FILE* PlaylistTXT(char* fil){ char file2[500]; - sprintf(file2,"/TYTD/PLTXT/%s.txt",fil); + sprintf(file2,"/TYTD/PLTXT/%s",fil); return fopen(file2,"r"); } +void CreatePL(char* fil){ + char file2[500]; + sprintf(file2,"/TYTD/PLTXT/%s",fil); + FILE *f =fopen(file2,"w"); + fclose(f); +} +void WriteFile2PL(char* fil,char* type,char* url,char* filename){ +char file2[500]; + sprintf(file2,"/TYTD/PLTXT/%s",fil); + + FILE *f =fopen(file2,"a"); + fseek(f,0,SEEK_END); + if(ftell(f) == 0L){ +fprintf(f,"%s %s %s",type,url,filename); +}else{ +fprintf(f,"\n%s %s %s",type,url,filename); +} +fclose(f); +} + int FileSystemDrivers(){ fatInitDefault(); USBStorage_Initialize(); diff --git a/source/settings.h b/source/settings.h index a005370..f868930 100644 --- a/source/settings.h +++ b/source/settings.h @@ -1,18 +1,20 @@ #ifndef SETTINGS_H #define SETTINGS_H +#include +#include +#include +#include +#include #include #include -#include #include #include #include -#include #include #include #include - #include #include #include "FreeMonoBold_ttf.h" @@ -20,9 +22,11 @@ typedef struct dlf{ FILE* fp; char fnam[1000]; + char fnam2[500]; int fileid; - + int fileindex; }dlf; +char* FileNameParse(char* path); void DLFhandler(dlf* dl,size_t real); void OpenPlaylistFile(char* playlist); char* OpenFile(char* fname); @@ -32,6 +36,8 @@ FILE* HistoryRead(); FILE* HistoryAppend(); int UsingIRFeatures(); int FileSystemDrivers(); +void WriteFile2PL(char* fil,char* type,char* url,char* filename); +void CreatePL(char* fil); char* OpenVideoFile(char* filename); char* ThumbnailFileName(char* filename); int ThumbnailExists(char* id);