commit 357c896b6fba688ace87d630e0a538cd517fd858 Author: Michael Nolan Date: Sun Apr 17 06:39:48 2022 -0500 12-26-2019 (wasnt in git) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5d5dfa5 --- /dev/null +++ b/Makefile @@ -0,0 +1,160 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +include $(DEVKITPPC)/wii_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- + +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) +CXXFLAGS = $(CFLAGS) + +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +# the order can-be/is critical +#--------------------------------------------------------------------------------- +LIBS := -lgrrlib -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lwiisocket +LIBS += -lfreetype -lbz2 +LIBS += -lpngu -lpng -ljpeg -lz -lntfs -lfat +LIBS += -lwiiuse +#LIBS += -lmodplay -laesnd +LIBS += -lbte -logc -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) + +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol + +#--------------------------------------------------------------------------------- +run: + wiiload $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .jpg extension +#--------------------------------------------------------------------------------- +%.jpg.o : %.jpg +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .png extension +#--------------------------------------------------------------------------------- +%.png.o : %.png +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .ttf extension +#--------------------------------------------------------------------------------- +%.ttf.o : %.ttf +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/data/FreeMonoBold.ttf b/data/FreeMonoBold.ttf new file mode 100644 index 0000000..9332a5a Binary files /dev/null and b/data/FreeMonoBold.ttf differ diff --git a/source/colors.c b/source/colors.c new file mode 100644 index 0000000..5b7dccc --- /dev/null +++ b/source/colors.c @@ -0,0 +1,113 @@ +#include "colors.h" +u32 colors[TOTALCOLORS]; +int s=5; +void Green(){ + SetColor(RGBA(0,128,0,255),DOWNLOAD_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_TEXTBOX_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_FOREGROUND_NO_SELECTOR); +SetColor(RGBA(0,0,255,255),DOWNLOAD_FOREGROUND_SELECTOR); +SetColor(RGBA(0,0,255,255),DOWNLOAD_KEYBOARD_UNSELECT); + +SetColor(RGBA(0,0,0,255),DOWNLOAD_TEXTBOX_FOREGROUND); +SetColor(RGBA(255,12,255,255),DOWNLOAD_CURSOR); +SetColor(RGBA(127,0,127,255),DOWNLOAD_PROGRESSBAR_FOREGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_PROGRESSBAR_BACKGROUND); +SetColor(RGBA(0,0,255,255),DOWNLOAD_PROGRESSVAL); +SetColor(RGBA(255,0,0,255),DOWNLOAD_SELECTOR); +SetColor(RGBA(128,0,128,255),DOWNLOAD_KEYBOARD_OUTLINE); +} +void DefaultColors(){ + SetColor(RGBA(255,0,0,255),DOWNLOAD_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_TEXTBOX_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_FOREGROUND_NO_SELECTOR); +SetColor(RGBA(0,0,255,255),DOWNLOAD_FOREGROUND_SELECTOR); +SetColor(RGBA(0,0,255,255),DOWNLOAD_KEYBOARD_UNSELECT); + +SetColor(RGBA(0,0,0,255),DOWNLOAD_TEXTBOX_FOREGROUND); +SetColor(RGBA(255,12,255,255),DOWNLOAD_CURSOR); +SetColor(RGBA(127,0,127,255),DOWNLOAD_PROGRESSBAR_FOREGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_PROGRESSBAR_BACKGROUND); +SetColor(RGBA(0,0,255,255),DOWNLOAD_PROGRESSVAL); +SetColor(RGBA(0,255,0,255),DOWNLOAD_SELECTOR); +SetColor(RGBA(128,0,128,255),DOWNLOAD_KEYBOARD_OUTLINE); +} +void Yellow(){ + SetColor(RGBA(128,128,0,255),DOWNLOAD_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_TEXTBOX_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_FOREGROUND_NO_SELECTOR); +SetColor(RGBA(0,0,255,255),DOWNLOAD_FOREGROUND_SELECTOR); +SetColor(RGBA(0,0,255,255),DOWNLOAD_KEYBOARD_UNSELECT); + +SetColor(RGBA(0,0,0,255),DOWNLOAD_TEXTBOX_FOREGROUND); +SetColor(RGBA(255,12,255,255),DOWNLOAD_CURSOR); +SetColor(RGBA(127,0,127,255),DOWNLOAD_PROGRESSBAR_FOREGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_PROGRESSBAR_BACKGROUND); +SetColor(RGBA(0,0,255,255),DOWNLOAD_PROGRESSVAL); +SetColor(RGBA(255,0,0,255),DOWNLOAD_SELECTOR); +SetColor(RGBA(128,0,128,255),DOWNLOAD_KEYBOARD_OUTLINE); +} + +void ShiftL1(){ + SetColor(RGBA(0,0,255,255),DOWNLOAD_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_TEXTBOX_BACKGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_FOREGROUND_NO_SELECTOR); +SetColor(RGBA(0,255,0,255),DOWNLOAD_FOREGROUND_SELECTOR); +SetColor(RGBA(0,255,0,255),DOWNLOAD_KEYBOARD_UNSELECT); + +SetColor(RGBA(0,0,0,255),DOWNLOAD_TEXTBOX_FOREGROUND); +SetColor(RGBA(12,255,255,255),DOWNLOAD_CURSOR); +SetColor(RGBA(0,127,127,255),DOWNLOAD_PROGRESSBAR_FOREGROUND); + SetColor(RGBA(255,255,255,255),DOWNLOAD_PROGRESSBAR_BACKGROUND); +SetColor(RGBA(0,255,0,255),DOWNLOAD_PROGRESSVAL); +SetColor(RGBA(255,0,0,255),DOWNLOAD_SELECTOR); +SetColor(RGBA(0,128,128,255),DOWNLOAD_KEYBOARD_OUTLINE); +} +void InvertedColors(){ + SetColor(RGBA(0,255,255,255),DOWNLOAD_BACKGROUND); + SetColor(RGBA(0,0,0,255),DOWNLOAD_TEXTBOX_BACKGROUND); + SetColor(RGBA(0,0,0,255),DOWNLOAD_FOREGROUND_NO_SELECTOR); +SetColor(RGBA(255,255,0,255),DOWNLOAD_FOREGROUND_SELECTOR); +SetColor(RGBA(255,255,255,255),DOWNLOAD_KEYBOARD_UNSELECT); + +SetColor(RGBA(255,255,255,255),DOWNLOAD_TEXTBOX_FOREGROUND); +SetColor(RGBA(0,243,0,255),DOWNLOAD_CURSOR); +SetColor(RGBA(128,255,128,255),DOWNLOAD_PROGRESSBAR_FOREGROUND); + SetColor(RGBA(0,0,0,255),DOWNLOAD_PROGRESSBAR_BACKGROUND); +SetColor(RGBA(255,255,0,255),DOWNLOAD_PROGRESSVAL); +SetColor(RGBA(255,0,255,255),DOWNLOAD_SELECTOR); +SetColor(RGBA(127,255,127,255),DOWNLOAD_KEYBOARD_OUTLINE); +} +u32 GetColor(int component){ + return colors[component]; +} +void SetColor(u32 color,int component){ + colors[component] = color; +} + +void InitColor(int scheme){ + //Type Colors + switch(scheme){ + case 0: + DefaultColors(); + break; + + case 1: + InvertedColors(); + break; +case 2: + Green(); + break; +case 3: + Yellow(); + break; + default: + ShiftL1(); + break; + } +} +int AddScheme(int val){ + if (val<(s-1)){ + return val+1; + } + return 0; +} diff --git a/source/colors.h b/source/colors.h new file mode 100644 index 0000000..0d03cbe --- /dev/null +++ b/source/colors.h @@ -0,0 +1,22 @@ +#ifndef COLORS_H +#define COLORS_H +#include "settings.h" +u32 GetColor(int component); +static const int DOWNLOAD_BACKGROUND=0; // Originaly Red +static const int DOWNLOAD_TEXTBOX_BACKGROUND=1; //Originaly White +static const int DOWNLOAD_FOREGROUND_NO_SELECTOR=2; // Originaly White +static const int DOWNLOAD_FOREGROUND_SELECTOR=3; // Originaly Blue +static const int DOWNLOAD_KEYBOARD_UNSELECT=4; // Originaly Blue +static const int DOWNLOAD_KEYBOARD_SELECT=5; // Originaly Yellow +static const int DOWNLOAD_TEXTBOX_FOREGROUND=6; // Originaly Black +static const int DOWNLOAD_CURSOR = 7; // Originaly Violet +static const int DOWNLOAD_PROGRESSBAR_FOREGROUND=8; //Originaly Violet +static const int DOWNLOAD_PROGRESSBAR_BACKGROUND=9; //Originaly White +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 +void SetColor(u32 color,int component); +void InitColor(int scheme); +int AddScheme(int val); +#endif diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..44cc60d --- /dev/null +++ b/source/main.c @@ -0,0 +1,1392 @@ + +#include "colors.h" +void ChannelNew(char* channel,int isuser,int download,char* date); +void Channel(char* channel,int isuser,int download); +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 coldate=0;//0 is month 1 is day 2 is year +GRRLIB_ttfFont* myFont; + +int willtry=0; +int videos=-1; +ir_t ir; +char videoitems[500][1001]; +int keyboard = 0; +int Download(char*, char*); +char history[2000][40]; +int historyobjs = 0; +int historyobj = -1; +int mustadd=0; +void AddHistory(); +void LoadHistory(); +char url[40]; +void PlaylistEx(char*,char*); +void Playlist(char* pl){ + PlaylistEx(pl,"Playlist"); +} +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++; +} +} +#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 + +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]==' '){ + sprintf(code,"%s%%20",code); + }else{ + sprintf(code,"%s%c",code,src[i]); + + } + } +return code; +} +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]='_'; + } +} +static int older_progress(void* p, + double dltotal, double dlnow, + double ultotal, double ulnow) +{ + 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)); + int x = 320-(((int)GRRLIB_WidthTTF (myFont, what2,72)) / 2); + 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_Render(); + 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)); + + + } + 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--; + 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() { + 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){ + if(!ThumbnailExists(id)){ + if(!Download(ThumbnailURL(id),ThumbnailFileName(id))){ + unlink(ThumbnailFileName(id)); + } + } + if(ThumbnailExists(id)){ + GRRLIB_texImg *tex = GRRLIB_LoadTextureFromFile (ThumbnailFileName(id)); + + 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 + ------------------------------------------------------------------------- + */ + + } + + + + +int files=0; +int iswad=0; + +void WPAD_ONMENU(u32 key){ + + 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 (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); + + + + } + } + if (UsingIRFeatures() && (key & WPAD_BUTTON_A)){ + if(pos>-1){ + + 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); + Download(idTool,OpenVideoFile(filename)); +} + + }else if(clickedtype==1){ + if(pos-5>=0){ + pos-=5; + + }else{ + pos=0; + } + }else if(clickedtype==2){ + if(pos+5-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); + Download(idTool,OpenVideoFile(filename)); + + }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); +} + } + + +}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); +}} + } +} + + +//BROKEN BUT MAY GET FIXED use +//fixed +void LoadQuery(char *file){ + + FILE *f = PlaylistTXT(file); + 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); + } + } + }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); + + Download(idTool,OpenVideoFile(filenamez)); + }else if(strcmp("pl",type)==0){ + //playlist on url2 + PlaylistEx(url2,data); + }else if(strcmp("dl",type)==0){ + //playlist on url2 + + Download(url2,OpenFile(data)); + } + } + + } + fclose(f); +} +void WPAD_KEYBOARD(u32 key) { + +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<6){ + 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 + if(mustadd==1){ + AddHistory(); + mustadd=0; + keyboard=0; + } + if(keyboard==1){ + Search(url); + keyboard=0; + } + if(keyboard==3){ + Playlist(url); + keyboard=0; + } + if(keyboard==2){ + + 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); + + char idTool[500]; + sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); + + Download(idTool,OpenVideoFile(filenamez)); +keyboard=0; + } + if(keyboard==4){ + LoadQuery(url); + keyboard=0; + } + if(keyboard==6){ + channelsetting=0; + + return; + } + if(keyboard==5){ + 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==3){ + Playlist(url); + } + if(keyboard==2){ + + + + 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); + + char idTool[500]; + sprintf(idTool,"https://stark-shelf-08981.herokuapp.com/Grabber/Video/%s",url); + + Download(idTool,OpenVideoFile(filenamez)); + } + if(keyboard==4){ + LoadQuery(url); + } + keyboard=0; + }else{ + + if (GoingBack() == 0) { + snprintf(url, 40, "%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, 40, "%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; + } +} +} + +} +int netclose_callback (void *clientp, curl_socket_t item) { + return net_close(item); +} +int Download(char* url, char* file) { + CURL* curl; + curl = curl_easy_init(); +int ret=1; + FILE *f = fopen(file,"wb"); + + +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_WRITEDATA,f); +curl_easy_setopt(curl,CURLOPT_FAILONERROR,1L); +curl_easy_perform(curl); +long int bytes =ftell(f); +fclose(f); +if(bytes==0){ + unlink(file); + ret=0; +} + + +curl_easy_cleanup(curl); +return ret; +} +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,Temp())){ + FILE *f = fopen(Temp(),"r"); + char download[1001]; + videos=-1; + while(fgets(download,1001,f)!=NULL && videos<499){ + + videos++; + sprintf(videoitems[videos],"%s",download); + + + } + fclose(f); + DeleteTemp(); + + + } + +} +} +void PLSearch(char* search) { + char output2[600]; + + char* output = ConvertString(search); + if (output) { + sprintf(output2,"https://stark-shelf-08981.herokuapp.com/Grabber/playlistinfo/%s",output); + + if(Download(output2,Temp())){ + FILE *f = fopen(Temp(),"r"); + char download[1001]; + videos=-1; + while(fgets(download,1001,f)!=NULL && videos<499){ + + videos++; + sprintf(videoitems[videos],"%s",download); + + + } + fclose(f); + DeleteTemp(); + + + } + } + + +} +void PlaylistEx(char* search,char* nm) { +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,Temp())){ + FILE *f = fopen(Temp(),"r"); + char download[1001]; + + while(fgets(download,1001,f)!=NULL ){ + + 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); + Download(idTool,OpenPlaylistVideoFile(ssname,filename)); + + + } + DeleteTemp(); + } + } + + +} +int running = 1; +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; +}*/ +int main() { + + char options[6][50]={"Input Search Term","Input Youtube URL","Input Playlist URL","Input Playlist Text File","Playlist As Search","Channel"}; + 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(); + } +FileSystemDrivers(); +CreateFolders(); + net_init(); + + + + // 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"); +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(150,224,340,32, GetColor(DOWNLOAD_TEXTBOX_BACKGROUND),1); + } + + //draw keyboard + if(keyboard>0){ + WPAD_KEYBOARD(ke); + + 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; +} + + + + + +void Channel(char* channel,int isuser,int downlo){ + +char output2[600]; + + 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,Temp())){ + FILE *f = fopen(Temp(),"r"); + char downloa[1001]; + if(!downlo) videos=-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); + Download(idTool,OpenVideoFile(filename)); + + }else{ + videos++; + sprintf(videoitems[videos],"%s",downloa); + + } + } + DeleteTemp(); + + + } + } + + + + + +void ChannelNew(char* channel,int isuser,int downlo,char* date){ + 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,Temp())){ + FILE *f = fopen(Temp(),"r"); + char downloa[1001]; + if(!downlo) videos=-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); + Download(idTool,OpenVideoFile(filename)); + + }else{ + videos++; + sprintf(videoitems[videos],"%s",downloa); + + } + } + DeleteTemp(); + + } + +} + diff --git a/source/settings.c b/source/settings.c new file mode 100644 index 0000000..0c3feec --- /dev/null +++ b/source/settings.c @@ -0,0 +1,101 @@ +#include "settings.h" + +int irmode=0; +int UsingIRFeatures(){ + return irmode; +} +void SwitchIR(){ + if(irmode==0){irmode=1;}else{irmode=0;} +} + + +FILE* HistoryRead(){ + return fopen("/TYTD/history.txt","r"); +} +FILE* HistoryAppend(){ + return fopen("/TYTD/history.txt","aw"); +} + +FILE* PlaylistTXT(char* fil){ + char file2[500]; + sprintf(file2,"/TYTD/PLTXT/%s.txt",fil); + return fopen(file2,"r"); +} +int FileSystemDrivers(){ + fatInitDefault(); + USBStorage_Initialize(); + return 0; +} +char* OpenVideoFile(char* filename){ + + char *yt = malloc(sizeof(char)*530); +snprintf(yt,530,"/TYTD/Videos/%s.mp4",filename); + + return yt; +} +void OpenPlaylistFile(char* playlist){ + + char yt[820]; +snprintf(yt,820,"/TYTD/Videos/%s",playlist); +mkdir(yt,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,"/TYTD/Downloads/%s",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); + + return yt; +} +char* ThumbnailFileName(char* filename){ + + char *yt = malloc(sizeof(char) *530); +snprintf(yt,530,"/TYTD/Thumbnails/%s.jpg",filename); + + return yt; +} + + +int ThumbnailExists(char* filename){ + char yt[530]; +snprintf(yt,530,"/TYTD/Thumbnails/%s.jpg",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; +} +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 + + return 0; +} + +char* Temp(){ + char *yt = malloc(sizeof(char)*530); +snprintf(yt,530,"/TYTD/~TMP"); + + return yt; + +} + +void DeleteTemp(){ + unlink("/TYTD/~TMP"); +} diff --git a/source/settings.h b/source/settings.h new file mode 100644 index 0000000..155b84d --- /dev/null +++ b/source/settings.h @@ -0,0 +1,35 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FreeMonoBold_ttf.h" +void OpenPlaylistFile(char* playlist); + char* OpenFile(char* fname); + char* OpenPlaylistVideoFile(char* playlist,char* video); + +FILE* HistoryRead(); +FILE* HistoryAppend(); +int UsingIRFeatures(); +int FileSystemDrivers(); +char* OpenVideoFile(char* filename); +char* ThumbnailFileName(char* filename); +int ThumbnailExists(char* id); +int CreateFolders(); +char* ThumbnailURL(char* id); +FILE* PlaylistTXT(char* fil); +char* Temp(); + +void DeleteTemp(); +void SwitchIR(); +#endif