#include "settings.h" 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; yt[ind] = path[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; //if(bytesnow >= (size_t)4294967000){ // dl->fileid++; //char nam[1008]; // sprintf(nam,"%s.%i",dl->fnam,dl->fileid); // freopen(nam,"wb",dl->fp); // } } int UsingIRFeatures(){ return irmode; } void SwitchIR(){ if(irmode==0){irmode=1;}else{irmode=0;} } FILE* HistoryRead(){ char history[38]; sprintf(history,"%s:/TYTD/history.txt",root); return fopen(history,"r"); } FILE* HistoryAppend(){ char history[38]; sprintf(history,"%s:/TYTD/history.txt",root); return fopen(history,"aw"); } FILE* PlaylistTXT(char* fil){ char file2[500]; sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil); return fopen(file2,"r"); } void CreatePL(char* fil){ char file2[500]; 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,"%s:/TYTD/PLTXT/%s",root,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); } /* 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(); 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,"%s:/TYTD/Videos/%s.mp4",root,filename); return yt; } void OpenPlaylistFile(char* playlist){ char yt[820]; 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){ char filename[720]; char *yt = malloc(sizeof(char)*820); char timein[20]; 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,"%s:/TYTD/Downloads/%s",root,filename); return yt; } char* OpenPlaylistVideoFile(char* playlist,char* video){ char *yt = malloc(sizeof(char)*820); 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,"%s:/TYTD/Thumbnails/%s.jpg",root,filename); return yt; } int ThumbnailExists(char* filename){ char yt[530]; snprintf(yt,530,"%s:/TYTD/Thumbnails/%s.jpg",root,filename); struct stat buffer; return (stat(yt,&buffer)==0); } char* ThumbnailURL(char* id){ char *yt = malloc(sizeof(char) *530); 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(){ 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,"%s:/TYTD/~TMP",root); return yt; } char* PLTXTDIR() { char *yt = malloc(sizeof(char)*530); snprintf(yt,530,"%s:/TYTD/PLTXT/",root); return yt; } void DeleteTemp(){ unlink(Temp()); }