2022-04-17 11:39:48 +00:00
|
|
|
|
#include "settings.h"
|
2022-04-17 11:46:26 +00:00
|
|
|
|
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();
|
2022-04-17 11:44:32 +00:00
|
|
|
|
}
|
2022-04-17 11:46:26 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 11:44:32 +00:00
|
|
|
|
|
|
|
|
|
for(size_t i = pos;i<=len;i++){
|
|
|
|
|
size_t ind = i - pos;
|
|
|
|
|
yt[ind] = path[i];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return yt;
|
|
|
|
|
}
|
2022-04-17 11:46:26 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-04-17 11:41:25 +00:00
|
|
|
|
void DLFhandler(dlf* dl,size_t real){
|
|
|
|
|
//max fat32 is 4,294,967,000 just to be safe
|
2022-04-17 11:46:26 +00:00
|
|
|
|
// size_t bytesnow = ftell(dl->fp) + real;
|
2022-04-17 11:41:25 +00:00
|
|
|
|
|
2022-04-17 11:46:26 +00:00
|
|
|
|
//if(bytesnow >= (size_t)4294967000){
|
|
|
|
|
// dl->fileid++;
|
|
|
|
|
//char nam[1008];
|
2022-04-17 11:41:25 +00:00
|
|
|
|
|
2022-04-17 11:46:26 +00:00
|
|
|
|
// sprintf(nam,"%s.%i",dl->fnam,dl->fileid);
|
|
|
|
|
// freopen(nam,"wb",dl->fp);
|
|
|
|
|
// }
|
2022-04-17 11:41:25 +00:00
|
|
|
|
}
|
2022-04-17 11:39:48 +00:00
|
|
|
|
int UsingIRFeatures(){
|
|
|
|
|
return irmode;
|
|
|
|
|
}
|
|
|
|
|
void SwitchIR(){
|
|
|
|
|
if(irmode==0){irmode=1;}else{irmode=0;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FILE* HistoryRead(){
|
2022-04-17 11:46:26 +00:00
|
|
|
|
char history[38];
|
|
|
|
|
sprintf(history,"%s:/TYTD/history.txt",root);
|
|
|
|
|
return fopen(history,"r");
|
2022-04-17 11:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
FILE* HistoryAppend(){
|
2022-04-17 11:46:26 +00:00
|
|
|
|
char history[38];
|
|
|
|
|
sprintf(history,"%s:/TYTD/history.txt",root);
|
|
|
|
|
return fopen(history,"aw");
|
|
|
|
|
|
2022-04-17 11:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FILE* PlaylistTXT(char* fil){
|
|
|
|
|
char file2[500];
|
2022-04-17 11:46:26 +00:00
|
|
|
|
sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
return fopen(file2,"r");
|
|
|
|
|
}
|
2022-04-17 11:44:32 +00:00
|
|
|
|
void CreatePL(char* fil){
|
|
|
|
|
char file2[500];
|
2022-04-17 11:46:26 +00:00
|
|
|
|
sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil);
|
|
|
|
|
|
2022-04-17 11:44:32 +00:00
|
|
|
|
FILE *f =fopen(file2,"w");
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
2022-04-17 11:46:26 +00:00
|
|
|
|
char* CreatePL2(char* fil){
|
|
|
|
|
char *file2 = malloc(sizeof(char)*530);
|
|
|
|
|
sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return file2;
|
|
|
|
|
}
|
2022-04-17 11:44:32 +00:00
|
|
|
|
void WriteFile2PL(char* fil,char* type,char* url,char* filename){
|
|
|
|
|
char file2[500];
|
2022-04-17 11:46:26 +00:00
|
|
|
|
sprintf(file2,"%s:/TYTD/PLTXT/%s",root,fil);
|
|
|
|
|
|
2022-04-17 11:44:32 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2022-04-17 11:46:26 +00:00
|
|
|
|
/*
|
|
|
|
|
typedef struct disks{
|
|
|
|
|
int ntfsusbs;
|
|
|
|
|
int ntfssds;
|
|
|
|
|
bool hassd;
|
|
|
|
|
bool hasusb;
|
|
|
|
|
bool hasfatsd;
|
|
|
|
|
bool hasfatusb;
|
|
|
|
|
}disks;
|
|
|
|
|
*/
|
|
|
|
|
disks* FileSystemDrivers(){
|
|
|
|
|
disks *d = malloc(sizeof(disks));
|
2022-04-17 11:39:48 +00:00
|
|
|
|
USBStorage_Initialize();
|
2022-04-17 11:46:26 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2022-04-17 11:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
char* OpenVideoFile(char* filename){
|
|
|
|
|
|
|
|
|
|
char *yt = malloc(sizeof(char)*530);
|
2022-04-17 11:46:26 +00:00
|
|
|
|
snprintf(yt,530,"%s:/TYTD/Videos/%s.mp4",root,filename);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
return yt;
|
|
|
|
|
}
|
|
|
|
|
void OpenPlaylistFile(char* playlist){
|
|
|
|
|
|
|
|
|
|
char yt[820];
|
2022-04-17 11:46:26 +00:00
|
|
|
|
snprintf(yt,820,"%s:/TYTD/Videos/%s",root,playlist);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
mkdir(yt,0777);
|
2022-04-17 11:46:26 +00:00
|
|
|
|
char yt2[820];
|
|
|
|
|
snprintf(yt2,820,"%s:/TYTD/Desc/%s",root,playlist);
|
|
|
|
|
mkdir(yt2,0777);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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);
|
2022-04-17 11:46:26 +00:00
|
|
|
|
snprintf(yt,820,"%s:/TYTD/Downloads/%s",root,filename);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
return yt;
|
|
|
|
|
}
|
|
|
|
|
char* OpenPlaylistVideoFile(char* playlist,char* video){
|
|
|
|
|
|
|
|
|
|
char *yt = malloc(sizeof(char)*820);
|
2022-04-17 11:46:26 +00:00
|
|
|
|
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);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
return yt;
|
|
|
|
|
}
|
|
|
|
|
char* ThumbnailFileName(char* filename){
|
|
|
|
|
|
|
|
|
|
char *yt = malloc(sizeof(char) *530);
|
2022-04-17 11:46:26 +00:00
|
|
|
|
snprintf(yt,530,"%s:/TYTD/Thumbnails/%s.jpg",root,filename);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
return yt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ThumbnailExists(char* filename){
|
|
|
|
|
char yt[530];
|
2022-04-17 11:46:26 +00:00
|
|
|
|
snprintf(yt,530,"%s:/TYTD/Thumbnails/%s.jpg",root,filename);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-04-17 11:46:26 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-04-17 11:39:48 +00:00
|
|
|
|
int CreateFolders(){
|
2022-04-17 11:46:26 +00:00
|
|
|
|
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
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* Temp(){
|
|
|
|
|
char *yt = malloc(sizeof(char)*530);
|
2022-04-17 11:46:26 +00:00
|
|
|
|
snprintf(yt,530,"%s:/TYTD/~TMP",root);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
return yt;
|
|
|
|
|
|
|
|
|
|
}
|
2022-04-17 11:46:26 +00:00
|
|
|
|
char* PLTXTDIR()
|
|
|
|
|
{
|
|
|
|
|
char *yt = malloc(sizeof(char)*530);
|
|
|
|
|
snprintf(yt,530,"%s:/TYTD/PLTXT/",root);
|
2022-04-17 11:39:48 +00:00
|
|
|
|
|
2022-04-17 11:46:26 +00:00
|
|
|
|
return yt;
|
|
|
|
|
|
|
|
|
|
}
|
2022-04-17 11:39:48 +00:00
|
|
|
|
void DeleteTemp(){
|
2022-04-17 11:46:26 +00:00
|
|
|
|
unlink(Temp());
|
2022-04-17 11:39:48 +00:00
|
|
|
|
}
|