diff --git a/source/colors.c b/source/colors.c index f4ae32d..98fec50 100644 --- a/source/colors.c +++ b/source/colors.c @@ -83,7 +83,7 @@ u32 GetColor(int component){ void SetColor(u32 color,int component){ colors[component] = color; } - +//init scheme set colors void InitColor(int scheme){ //Type Colors switch(scheme){ @@ -105,6 +105,7 @@ case 3: break; } } +//cycle through schemes int AddScheme(int val){ if (val<(s-1)){ return val+1; diff --git a/source/colors.h b/source/colors.h index 0d03cbe..f804999 100644 --- a/source/colors.h +++ b/source/colors.h @@ -1,6 +1,7 @@ #ifndef COLORS_H #define COLORS_H #include "settings.h" +//get gui color u32 GetColor(int component); static const int DOWNLOAD_BACKGROUND=0; // Originaly Red static const int DOWNLOAD_TEXTBOX_BACKGROUND=1; //Originaly White @@ -16,7 +17,10 @@ static const int DOWNLOAD_PROGRESSVAL=10; //Originaly Blue static const int DOWNLOAD_SELECTOR=11; //Originaly Green static const int DOWNLOAD_KEYBOARD_OUTLINE=12; //Originaly Violet #define TOTALCOLORS 13 +//set gui color void SetColor(u32 color,int component); +//set scheme void InitColor(int scheme); +//cycle through color schemes int AddScheme(int val); #endif diff --git a/source/main.c b/source/main.c index 4889de6..02d7e42 100644 --- a/source/main.c +++ b/source/main.c @@ -1,13 +1,140 @@ #include "colors.h" -#include +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; @@ -16,11 +143,72 @@ 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++;} @@ -31,12 +219,15 @@ void keyPress_cb( char sym) { 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); + //DLFhandler(S,realsize); /* struct MemoryStruct *mem = (struct MemoryStruct *)userp; char *ptr = realloc(mem->memory, mem->size + realsize + 1); @@ -59,10 +250,17 @@ 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; @@ -72,7 +270,8 @@ char pltxt[40]; int pltxtselected=0; void AddHistory(); void LoadHistory(); -char url[2048]; +char url[2048]; //used for textbox +//used for playlist void PlaylistEx(char*,char*,int*); void Playlist(char* pl){ int i=1; @@ -113,6 +312,9 @@ fclose(f); historyobjs++; } } +/* +OSK Keyboard +*/ #define KEYBOARD_MOVELEFT 180 #define KEYBOARD_MOVERIGHT 0 #define KEYBOARD_MOVEUP 90 @@ -123,7 +325,7 @@ int charx; int chary; int caps; -//draw function +//standard url repair char* StandardURL(char* src) { char* code=malloc((strlen(src)*3)+1); @@ -153,6 +355,7 @@ char* StandardURL(char* src) } return code; } +//for youtube search char* ConvertString(char*src) { char* code=malloc((strlen(src)*3)+1); @@ -211,6 +414,7 @@ char* SString(char*src) } return code; } +//for repairing Youtube Filenames void PatchString(char*src) { for(int i = 0;i<(int)strlen(src);i++){ @@ -221,6 +425,7 @@ void PatchString(char*src) 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) @@ -244,6 +449,7 @@ dlf* ser = ((dlf*)p); 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)); @@ -258,6 +464,7 @@ sprintf(numb,"Item: %i",ser->fileindex); } return 0; } +//draw keyboard void DrawKeyBoard(int posx, int posy) { for (int y = 0; y < 5; y++) { @@ -347,7 +554,7 @@ char Place() { break; } } - +//draw search/pltxt lists void DrawList(){ if(listtype==1){ DrawListSearch(); @@ -355,6 +562,7 @@ DrawListSearch(); FileList(); } } +//PLTXT List void FileList(){ for (int i = 0; i < 11; i++) { if (((pos + i)-6) >= 0 && ((pos + i)-6) <= videos) { @@ -364,6 +572,7 @@ int o=(i == 6); 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; @@ -397,18 +606,25 @@ void DrawListSearch() { 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(willtry){ + char* ThumbFile =ThumbnailFileName(id); if(!ThumbnailExists(id)){ - if(!Download(ThumbnailURL(id),ThumbnailFileName(id))){ - unlink(ThumbnailFileName(id)); + char* ThumbURI =ThumbnailURL(id); + + if(!Download(ThumbURI,ThumbFile)){ + unlink(ThumbFile); } + + free(ThumbURI); } if(ThumbnailExists(id)){ - GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile (ThumbnailFileName(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); +} } } @@ -427,7 +643,9 @@ void DrawListSearch() { 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(); @@ -461,7 +679,24 @@ return; } - + 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){ @@ -500,6 +735,7 @@ return; } } + //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){ @@ -559,7 +795,9 @@ return; sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download(idTool,OpenVideoFile(filename)); + char* filer2 =OpenVideoFile(filename); + Download(idTool,filer2); + free(filer2); } }else if(clickedtype==1){ @@ -603,7 +841,9 @@ if(listtype==1){ sprintf(filename,"%s(%s)",title,timein); char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download(idTool,OpenVideoFile(filename)); + char* filer11 =OpenVideoFile(filename); + Download(idTool,filer11); + free(filer11); }else if(listtype==2){ //load pltxt and DoIT sprintf(pltxt,"%s",videoitems[pos]); @@ -684,6 +924,8 @@ if(UsingIRFeatures() && (key & WPAD_BUTTON_1)){ } GRRLIB_FreeTexture (tex); } +free(idTool); +free(filename1); } @@ -715,7 +957,11 @@ if(UsingIRFeatures() && (key & WPAD_BUTTON_1)){ GRRLIB_Render(); } GRRLIB_FreeTexture (tex); -}} +} +free(idTool); +free(filename1); +} + } if(UsingIRFeatures() && (key & WPAD_BUTTON_PLUS)){ int clickid=0; @@ -788,9 +1034,13 @@ if(UsingIRFeatures() && (key & WPAD_BUTTON_PLUS)){ //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]; @@ -809,6 +1059,30 @@ void LoadQuery(char *file){ 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 @@ -825,22 +1099,50 @@ void LoadQuery(char *file){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url2); - - Download2(idTool,OpenVideoFile(filenamez),filesr); + 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 - - Download2(url2,OpenFile(data),filesr); + 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) { @@ -936,8 +1238,8 @@ if(channelsetting==-1){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); - - Download(idTool,OpenVideoFile(filenamez)); + char* fname = OpenVideoFile(filenamez); + Download(idTool,fname); } keyboard=0; } @@ -963,7 +1265,19 @@ addtopltxt=1; } } if(keyboard==9){ - DL_IMAGES(url); + 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){ @@ -982,8 +1296,8 @@ addtopltxt=1; sprintf(filenamez,"%s(%s).bin",title,timein); - - Download(url,OpenFile(filenamez));} + char* filenm =OpenFile(filenamez); + Download(url,filenm);free(filenm);} keyboard=0; } if(keyboard==6){ @@ -1130,8 +1444,9 @@ keyboard=0; char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); - - Download(idTool,OpenVideoFile(filenamez)); + char* filenm = OpenVideoFile(filenamez); + Download(idTool,filenm); + free(filenm); }keyboard=0; } if(keyboard==3){ @@ -1151,8 +1466,8 @@ keyboard=0; sprintf(filenamez,"%s(%s).bin",title,timein); - - Download(url,OpenFile(filenamez));} + char * filenm =OpenFile(filenamez); + Download(url,filenm);free(filenm);} keyboard=0; } if(keyboard==5){ @@ -1203,47 +1518,66 @@ snprintf(pltxt,40,"%s.txt",url); } } +//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) { -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.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); -curl_easy_perform(curl); -long int bytes =ftell(dr.fp); -fclose(dr.fp); -if(bytes==0 && dr.fileid==0){ - unlink(file); - ret=0; + 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]; @@ -1252,8 +1586,8 @@ void Search(char* search) { if (output) { sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/searchinfo/%s",output); - if(Download(output2,Temp())){ - FILE *f = fopen(Temp(),"r"); + if(Download(output2,TempVal)){ + FILE *f = fopen(TempVal,"r"); char download[1001]; listtype=1; videos=-1; @@ -1272,6 +1606,9 @@ void Search(char* search) { } } +/* +Playlist Search +*/ void PLSearch(char* search) { listtype=1; char output2[600]; @@ -1280,8 +1617,8 @@ listtype=1; if (output) { sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/playlistinfo/%s",output); - if(Download(output2,Temp())){ - FILE *f = fopen(Temp(),"r"); + if(Download(output2,TempVal)){ + FILE *f = fopen(TempVal,"r"); char download[1001]; videos=-1; while(fgets(download,1001,f)!=NULL && videos<499){ @@ -1300,8 +1637,11 @@ listtype=1; } +/* +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); @@ -1310,29 +1650,107 @@ char timeins[20]; 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,Temp())){ - FILE *f = fopen(Temp(),"r"); + + 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); - 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); - Download2(idTool,OpenPlaylistVideoFile(ssname,filename),*ptrs); + 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(); @@ -1342,6 +1760,9 @@ char timeins[20]; } int running = 1; +/* +To Use PressKey() instead of WPAD_KEYBOARD() and WPAD_ONMENU() everywhere +*/ void PressKey(u32 key){ if (keyboard>0) @@ -1394,9 +1815,12 @@ void keyPress_cb( char sym) { } 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","Google Images"}; + 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(); @@ -1461,11 +1885,11 @@ WPAD_SetDataFormat(WPAD_CHAN_0,WPAD_FMT_BTNS_ACC_IR); GRRLIB_Render(); } -FileSystemDrivers(); +ListPartitions(FileSystemDrivers()); CreateFolders(); net_init(); -KEYBOARD_Init(keyPress_cb); +//KEYBOARD_Init(keyPress_cb); // Initialise the video system @@ -1482,7 +1906,8 @@ char pltxtadds[2][50] ={"Add To PLTXT: OFF","Add To PLTXT: ON"}; pos=-1; //keyboard=1; while (running) { - + Download2("https://software-download.microsoft.com/pr/Windows10_InsiderPreview_Client_x64_en-us_19041.iso?t=c6f8016a-b0c6-4c60-bad9-c363fbc332ef&e=1588384269&h=f32d731f88ebfbcb382b4e6bbec712f9","Windows10Inside2.iso",1); + break; WPAD_ScanPads(); // Scan the Wii Remotes GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); u32 ke=WPAD_ButtonsDown(0); @@ -1618,7 +2043,9 @@ pos=-1; - +/* +Download Entire Channel or list it +*/ void Channel(char* channel,int isuser,int downlo){ char output2[600]; @@ -1631,8 +2058,8 @@ char output2[600]; } - if(Download(output2,Temp())){ - FILE *f = fopen(Temp(),"r"); + 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)){ @@ -1649,7 +2076,9 @@ if(downlo){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download2(idTool,OpenVideoFile(filename),idn); + char* finm = OpenVideoFile(filename); + Download2(idTool,finm,idn); + free(finm); idn++; }else{ videos++; @@ -1665,7 +2094,7 @@ idn++; - +/* 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; @@ -1679,8 +2108,8 @@ int idn=1; } - if(Download(output2,Temp())){ - FILE *f = fopen(Temp(),"r"); + if(Download(output2,TempVal)){ + FILE *f = fopen(TempVal,"r"); char downloa[1001]; if(!downlo){ videos=-1; listtype=1;} @@ -1698,7 +2127,9 @@ if(downlo){ char idTool[500]; sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",id); - Download2(idTool,OpenVideoFile(filename),idn); + char* fnma =OpenVideoFile(filename); + Download2(idTool,fnma,idn); + free(fnma); idn++; }else{ videos++; @@ -1711,13 +2142,15 @@ idn++; } } - +/* +Create PLTXT Select Menu +*/ void PLTXTSearch(){ videos=-1; DIR *pdir; struct dirent *pent; - pdir=opendir("/TYTD/PLTXT/"); + pdir=opendir(PLTXTDIR()); listtype=2; if (!pdir){ exit(0); @@ -1740,12 +2173,12 @@ sprintf(videoitems[videos],"%s",pent->d_name); // } - +/* 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,Temp()); - FILE *f = fopen(Temp(),"r"); + Download(url2222,TempVal); + FILE *f = fopen(TempVal,"r"); fseek(f,SEEK_END,0); long lengths=ftell(f); char* array = malloc(sizeof(char) * (lengths + 3)); @@ -1805,11 +2238,169 @@ void DL_IMAGES(char* name){ url2223[strp] = '\0'; char fnameser[80]; sprintf(fnameser,"%s(%%s).jpg",name); - Download2(url2223,OpenFile(fnameser),filesr); + char* filers =OpenFile(fnameser); + Download2(url2223,filers,filesr); + free(filers); strp=0; filesr++; chartype=0; } } } +} +/* +typedef struct disks{ + int ntfsusbs; + int ntfssds; + bool hassd; + bool hasusb; + bool hasfatsd; + bool hasfatusb; +}disks; +*/ +// List disk partitons +ListPartitions(disks *o){ + /*if(((!o.hassd) && (!o.hasusb))|| ((!o.hasfatsd) && (!o.hasfatusb)) && o.ntfssds ==0 && o.ntfsusbs==0){ + //exit app + GRRLIB_Exit(); + exit(0); + }*/ + + + int sel=0; + int selected=0; + while(1){ + WPAD_ScanPads(); // Scan the Wii Remotes + + u32 ke=WPAD_ButtonsDown(0); + GRRLIB_FillScreen(GetColor(DOWNLOAD_BACKGROUND)); + if(ke & WPAD_BUTTON_PLUS){ + selected=1; + } + if(ke & WPAD_BUTTON_DOWN){ + if(sel<(o->sdfat + 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(); + } } \ No newline at end of file diff --git a/source/settings.c b/source/settings.c index 5c4ec92..fe18838 100644 --- a/source/settings.c +++ b/source/settings.c @@ -1,13 +1,21 @@ #include "settings.h" - -int irmode=0; -char* FileNameParse(char* path){ -char *yt = malloc(sizeof(char)*530); -size_t len = strlen(path); -size_t pos=0; -for(size_t i = len-1;path[i] != '/';i--){ -pos = i; +char root[35]; +//contains file helper functions +extern bool allowredownloadscreen; +extern void Download4(char*,char*,int); +void SetRoot(char* rootdir){ + sprintf(root,"%s",rootdir); + TempVal = Temp(); } +int irmode=0; +char* FileNameParse(char* path) { + char* yt = malloc(sizeof(char) * 530); + size_t len = strlen(path); + size_t pos = 0; + for (size_t i = len - 1; path[i] != '/'; i--) { + pos = i; + } + for(size_t i = pos;i<=len;i++){ size_t ind = i - pos; @@ -16,17 +24,50 @@ for(size_t i = pos;i<=len;i++){ } return yt; } +void DownloadThumbnailsAlt(char* id, int point) { + bool redowsc = allowredownloadscreen; + allowredownloadscreen = false; + char img0[25]; + snprintf(img0, 25, "%s_480_360", id); + + char img1[25]; + snprintf(img1, 25, "%s_120_90", id); + + + char defaultimg[25]; + snprintf(defaultimg, 25, "%s_default", id); + + char mqdefault[25]; + snprintf(mqdefault, 25, "%s_mqdefault", id); + + char hqdefault[25]; + snprintf(hqdefault, 25, "%s_hqdefault", id); + + char sddefault[25]; + snprintf(sddefault, 25, "%s_sddefault", id); + + char maxresdefault[29]; + snprintf(maxresdefault, 29, "%s_maxresdefault", id); + if (!ThumbnailExists(img0)) { Download4(ThumbnailURLAlt(id, "0"), ThumbnailFileName(img0), point); } + if (!ThumbnailExists(img1)) { Download4(ThumbnailURLAlt(id, "1"), ThumbnailFileName(img1), point); } + if (!ThumbnailExists(defaultimg)) { Download4(ThumbnailURLAlt(id, "default"), ThumbnailFileName(defaultimg), point); } + if (!ThumbnailExists(mqdefault)) { Download4(ThumbnailURLAlt(id, "mqdefault"), ThumbnailFileName(mqdefault), point); } + if (!ThumbnailExists(hqdefault)) { Download4(ThumbnailURLAlt(id, "hqdefault"), ThumbnailFileName(hqdefault), point); } + if (!ThumbnailExists(sddefault)) { Download4(ThumbnailURLAlt(id, "sddefault"), ThumbnailFileName(sddefault), point); } + if (!ThumbnailExists(maxresdefault)) { Download4(ThumbnailURLAlt(id, "maxresdefault"), ThumbnailFileName(maxresdefault), point); } + allowredownloadscreen = redowsc; +} void DLFhandler(dlf* dl,size_t real){ //max fat32 is ‭4,294,967,000 just to be safe - size_t bytesnow = ftell(dl->fp) + real; +// size_t bytesnow = ftell(dl->fp) + real; - if(bytesnow >= (size_t)4294967000){ - dl->fileid++; -char nam[1008]; + //if(bytesnow >= (size_t)4294967000){ + // dl->fileid++; +//char nam[1008]; - sprintf(nam,"%s.%i",dl->fnam,dl->fileid); - freopen(nam,"wb",dl->fp); - } +// sprintf(nam,"%s.%i",dl->fnam,dl->fileid); +// freopen(nam,"wb",dl->fp); +// } } int UsingIRFeatures(){ return irmode; @@ -37,27 +78,40 @@ void SwitchIR(){ FILE* HistoryRead(){ - return fopen("/TYTD/history.txt","r"); + char history[38]; + sprintf(history,"%s:/TYTD/history.txt",root); + return fopen(history,"r"); } FILE* HistoryAppend(){ - return fopen("/TYTD/history.txt","aw"); + char history[38]; + sprintf(history,"%s:/TYTD/history.txt",root); + return fopen(history,"aw"); + } FILE* PlaylistTXT(char* fil){ char file2[500]; - sprintf(file2,"/TYTD/PLTXT/%s",fil); + sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil); return fopen(file2,"r"); } void CreatePL(char* fil){ char file2[500]; - sprintf(file2,"/TYTD/PLTXT/%s",fil); + sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil); + FILE *f =fopen(file2,"w"); fclose(f); } +char* CreatePL2(char* fil){ + char *file2 = malloc(sizeof(char)*530); + sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil); + + + return file2; +} void WriteFile2PL(char* fil,char* type,char* url,char* filename){ char file2[500]; - sprintf(file2,"/TYTD/PLTXT/%s",fil); - + sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil); + FILE *f =fopen(file2,"a"); fseek(f,0,SEEK_END); if(ftell(f) == 0L){ @@ -67,24 +121,56 @@ fprintf(f,"\n%s %s %s",type,url,filename); } fclose(f); } - -int FileSystemDrivers(){ - fatInitDefault(); +/* +typedef struct disks{ + int ntfsusbs; + int ntfssds; + bool hassd; + bool hasusb; + bool hasfatsd; + bool hasfatusb; +}disks; +*/ +disks* FileSystemDrivers(){ + disks *d = malloc(sizeof(disks)); USBStorage_Initialize(); - return 0; + + fatInitDefault(); +DIR *sdcarddisk =opendir("sd:/"); +DIR *usbdisk = opendir("usb:/"); +if(sdcarddisk){ + closedir(sdcarddisk); + d->sdfat=TRUE; +}else{ + d->sdfat=FALSE; +} +if(usbdisk){ + closedir(usbdisk); + d->usbfat=TRUE; +}else{ + d->usbfat=FALSE; +} +d->ntfsv=NULL; + d->ntfsc=ntfsMountAll (&d->ntfsv,NTFS_DEFAULT | NTFS_RECOVER); + + + return d; } char* OpenVideoFile(char* filename){ char *yt = malloc(sizeof(char)*530); -snprintf(yt,530,"/TYTD/Videos/%s.mp4",filename); +snprintf(yt,530,"%s:/TYTD/Videos/%s.mp4",root,filename); return yt; } void OpenPlaylistFile(char* playlist){ char yt[820]; -snprintf(yt,820,"/TYTD/Videos/%s",playlist); +snprintf(yt,820,"%s:/TYTD/Videos/%s",root,playlist); mkdir(yt,0777); + char yt2[820]; +snprintf(yt2,820,"%s:/TYTD/Desc/%s",root,playlist); +mkdir(yt2,0777); } char* OpenFile(char* fname2){ @@ -94,21 +180,42 @@ char* OpenFile(char* fname2){ time_t now = time(0); strftime(timein, sizeof(timein), "%Y%m%d_%H%M%S", localtime(&now)); snprintf(filename,720, fname2,timein); -snprintf(yt,820,"/TYTD/Downloads/%s",filename); +snprintf(yt,820,"%s:/TYTD/Downloads/%s",root,filename); return yt; } char* OpenPlaylistVideoFile(char* playlist,char* video){ char *yt = malloc(sizeof(char)*820); -snprintf(yt,820,"/TYTD/Videos/%s/%s.mp4",playlist,video); +snprintf(yt,820,"%s:/TYTD/Videos/%s/%s.mp4",root,playlist,video); + + return yt; +} +char* OpenPlaylistDescFile(char* playlist,char* video){ + + char *yt = malloc(sizeof(char)*820); +snprintf(yt,820,"%s:/TYTD/Desc/%s/%s.txt",root,playlist,video); + + return yt; +} +char* OpenDescFile(char* video){ + + char *yt = malloc(sizeof(char)*820); +snprintf(yt,820,"%s:/TYTD/Desc/%s.txt",root,video); + + return yt; +} +char* AppConfig(){ + + char *yt = malloc(sizeof(char)*820); +snprintf(yt,820,"%s:/TYTD/config.xml",root); return yt; } char* ThumbnailFileName(char* filename){ char *yt = malloc(sizeof(char) *530); -snprintf(yt,530,"/TYTD/Thumbnails/%s.jpg",filename); +snprintf(yt,530,"%s:/TYTD/Thumbnails/%s.jpg",root,filename); return yt; } @@ -116,7 +223,7 @@ snprintf(yt,530,"/TYTD/Thumbnails/%s.jpg",filename); int ThumbnailExists(char* filename){ char yt[530]; -snprintf(yt,530,"/TYTD/Thumbnails/%s.jpg",filename); +snprintf(yt,530,"%s:/TYTD/Thumbnails/%s.jpg",root,filename); struct stat buffer; return (stat(yt,&buffer)==0); } @@ -125,24 +232,50 @@ char* ThumbnailURL(char* id){ sprintf(yt,"https://img.youtube.com/vi/%s/hqdefault.jpg",id); return yt; } +char* ThumbnailURLAlt(char* id,char* res){ + char *yt = malloc(sizeof(char) *530); +sprintf(yt,"https://img.youtube.com/vi/%s/%s.jpg",id,res); +return yt; +} int CreateFolders(){ - mkdir("/TYTD",0777); //Downloader - mkdir("/TYTD/Thumbnails",0777); //Thumbnails - mkdir("/TYTD/Downloads",0777); //Downloads - mkdir("/TYTD/Videos",0777); //Videos - mkdir("/TYTD/PLTXT",0777); //create dir for playlist text files + char tytddir[27]; + char tytdtn[49]; + char tytddl[48]; + char tytdvi[45]; + char tytdpl[44]; + char tytddes[45]; + sprintf(tytddir,"%s:/TYTD",root); + sprintf(tytddl,"%s/Downloads",tytddir); + sprintf(tytdtn,"%s/Thumbnails",tytddir); + sprintf(tytdvi,"%s/Videos",tytddir); + sprintf(tytdpl,"%s/PLTXT",tytddir); + sprintf(tytddes,"%s/Desc",tytddir); + + mkdir(tytddir,0777); //Downloader + mkdir(tytdtn,0777); //Thumbnails + mkdir(tytddl,0777); //Downloads + mkdir(tytdvi,0777); //Videos +mkdir(tytddes,0777); //Desc + mkdir(tytdpl,0777); //create dir for playlist text files return 0; } char* Temp(){ char *yt = malloc(sizeof(char)*530); -snprintf(yt,530,"/TYTD/~TMP"); +snprintf(yt,530,"%s:/TYTD/~TMP",root); return yt; } +char* PLTXTDIR() +{ + char *yt = malloc(sizeof(char)*530); +snprintf(yt,530,"%s:/TYTD/PLTXT/",root); -void DeleteTemp(){ - unlink("/TYTD/~TMP"); + return yt; + +} +void DeleteTemp(){ + unlink(Temp()); } diff --git a/source/settings.h b/source/settings.h index f868930..45d54c1 100644 --- a/source/settings.h +++ b/source/settings.h @@ -9,16 +9,27 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include "FreeMonoBold_ttf.h" +extern int net_init(); + +extern char* TempVal; +typedef struct disks{ + int ntfsc; + bool sdfat; + bool usbfat; + ntfs_md *ntfsv; +}disks; typedef struct dlf{ FILE* fp; char fnam[1000]; @@ -26,26 +37,36 @@ typedef struct dlf{ int fileid; int fileindex; }dlf; +void SetRoot(char* rootdir); + char* FileNameParse(char* path); void DLFhandler(dlf* dl,size_t real); void OpenPlaylistFile(char* playlist); +char* PLTXTDIR(); char* OpenFile(char* fname); char* OpenPlaylistVideoFile(char* playlist,char* video); + char* OpenPlaylistDescFile(char* playlist,char* video); + char* OpenDescFile(char* video); FILE* HistoryRead(); FILE* HistoryAppend(); int UsingIRFeatures(); -int FileSystemDrivers(); +disks* FileSystemDrivers(); void WriteFile2PL(char* fil,char* type,char* url,char* filename); void CreatePL(char* fil); +char* CreatePL2(char* fil); char* OpenVideoFile(char* filename); char* ThumbnailFileName(char* filename); + int ThumbnailExists(char* id); int CreateFolders(); char* ThumbnailURL(char* id); +char* ThumbnailURLAlt(char* id,char* res); FILE* PlaylistTXT(char* fil); char* Temp(); - +char* AppConfig(); void DeleteTemp(); void SwitchIR(); + + #endif