Skip to content

Commit

Permalink
Merge pull request #11 from StarDustCFW/master
Browse files Browse the repository at this point in the history
More changes & Speed up a lot
  • Loading branch information
darkxex authored Feb 22, 2021
2 parents 4b9120f + 443d62d commit d62d0fb
Show file tree
Hide file tree
Showing 7 changed files with 736 additions and 604 deletions.
Binary file added romfs/nop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
259 changes: 79 additions & 180 deletions source/Request.hpp → source/JKanime.hpp
Original file line number Diff line number Diff line change
@@ -1,107 +1,3 @@
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}

int progress_func(void* ptr, double TotalToDownload, double NowDownloaded,
double TotalToUpload, double NowUploaded)
{


// ensure that the file to be downloaded is not empty
// because that would cause a division by zero error later on
if (TotalToDownload <= 0.0) {
return 0;
}

// how wide you want the progress meter to be
int totaldotz = 20;
double fractiondownloaded = NowDownloaded / TotalToDownload;
// part of the progressmeter that's already "full"
int dotz = round(fractiondownloaded * totaldotz);

// create the "meter"
int ii = 0;
porcendown = fractiondownloaded * 100;
sizeestimated = TotalToDownload;
printf("%3.0f%% [", fractiondownloaded * 100);
// part that's full already
for (; ii < dotz; ii++) {
printf("=");
}
// remaining part (spaces)
for (; ii < 20; ii++) {
printf(" ");
}
// and back to line begin - do not forget the fflush to avoid output buffering problems!
printf("]\r");
fflush(stdout);
// if you don't return 0, the transfer will be aborted - see the documentation
if (cancelcurl == 1)
{
return 1;
}

return 0;

}

std::string gethtml(std::string enlace)
{

CURL *curl;
CURLcode res = CURLE_OK;
std::string Buffer;

curl = curl_easy_init();
if (curl) {

curl_easy_setopt(curl, CURLOPT_URL, enlace.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &Buffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));}
}
return Buffer;
}
void downloadfile(std::string enlace, std::string directorydown)
{

CURL *curl;
FILE *fp;
CURLcode res = CURLE_OK;

curl = curl_easy_init();
if (curl) {

fp = fopen(directorydown.c_str(), "wb");
curl_easy_setopt(curl, CURLOPT_URL, enlace.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
// Install the callback function
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));}
}
}

int downloadjkanimevideo(void* data)
{
Expand Down Expand Up @@ -187,6 +83,7 @@ int downloadjkanimevideo(void* data)

return 0;
}

void onlinejkanimevideo(std::string onlineenlace)
{
#ifdef __SWITCH__
Expand Down Expand Up @@ -277,31 +174,41 @@ int ydistance = 448;
void callimage()
{
#ifdef __SWITCH__
std::string directorydownloadimage = "sdmc:/RipJKAnime/";
directorydownloadimage.append(std::to_string(selectchapter));
std::string temp = arrayimages[selectchapter];
replace(temp,"https://cdn.jkanime.net/assets/images/animes/image/","");
replace(temp,".jpg0", "");
replace(temp,".jpg", "");

std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/";
directorydownloadimage.append(temp);
directorydownloadimage.append(".jpg");
#else
std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/";
directorydownloadimage.append(std::to_string(selectchapter));
directorydownloadimage.append(temp);
directorydownloadimage.append(".jpg");
#endif // SWITCH
printf("# %d imagen: %s \n",selectchapter,directorydownloadimage.c_str());
TPreview.loadFromFileCustom(directorydownloadimage.c_str(), sizeportraitx, sizeportraity);
tempimage = directorydownloadimage;
}
void callimagesearch()
{

#ifdef __SWITCH__
std::string directorydownloadimage = "sdmc:/RipJKAnime/s";
directorydownloadimage.append(std::to_string(searchchapter));
std::string temp = arraysearchimages[searchchapter];
replace(temp,"https://cdn.jkanime.net/assets/images/animes/image/","");
replace(temp,".jpg0", "");
replace(temp,".jpg", "");
std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/";
directorydownloadimage.append(temp);
directorydownloadimage.append(".jpg");
#else
std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/s";
directorydownloadimage.append(std::to_string(searchchapter));
std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/";
directorydownloadimage.append(temp);
directorydownloadimage.append(".jpg");
#endif // SWITCH


TSearchPreview.loadFromFileCustom(directorydownloadimage.c_str(), sizeportraitx, sizeportraity);
tempimage = directorydownloadimage;

Expand All @@ -311,10 +218,7 @@ int refrescarpro(void* data)
activatefirstimage = true;
reloading = true;
porcentajereload = 0;
int val1 = 1;
int val2;
int val3, val4;
int val0 = 0;
int val0 = 0, val1 = 1, val2, val3, val4;
std::string temporal = "";
std::string content = gethtml("https://jkanime.net");
while (val0 != -1) {
Expand All @@ -330,57 +234,39 @@ int refrescarpro(void* data)
val4 = content.find('"', val3);
std::string gpreview = content.substr(val3, val4 - val3);
arrayimages.push_back(gpreview);

//std::cout << arraycount << ". " << gdrive << std::endl;
temporal = temporal + gdrive + "\n";
temporal = temporal + gpreview + "\n";


val1++;

}
printf(temporal.c_str());

CURL *curl;
FILE *fp;
CURLcode res = CURLE_OK;

for (int x = 0; x < (int)arrayimages.size(); x++)
{

curl = curl_easy_init();
if (curl) {
std::string tempima = arrayimages[x];
std::cout << tempima << selectchapter << std::endl;
replace(tempima,"https://cdn.jkanime.net/assets/images/animes/image/","");
replace(tempima,".jpg0", "");
replace(tempima,".jpg", "");
#ifdef __SWITCH__
std::string directorydownloadimage = "sdmc:/RipJKAnime/";
directorydownloadimage.append(std::to_string(x));
std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/";
directorydownloadimage.append(tempima);
directorydownloadimage.append(".jpg");
#else
std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/" ;
directorydownloadimage.append(std::to_string(x));
directorydownloadimage.append(tempima);
directorydownloadimage.append(".jpg");
#endif // SWITCH

fp = fopen(directorydownloadimage.c_str(), "wb");
curl_easy_setopt(curl, CURLOPT_URL, tempima.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));}

}
printf("# %d imagen: %s \n",x,tempima.c_str());
if(!isFileExist(directorydownloadimage.c_str()))
downloadfile(arrayimages[x],directorydownloadimage,false);

porcentajereload = ((x+1) * 100) / arrayimages.size();
}

reloading = false;
preview = true;

return 0;
}

Expand Down Expand Up @@ -411,11 +297,6 @@ int searchjk(void* data)
int val2;
int val0 = 0;






while (val0 != -1) {
val0 = content.find("portada-title", val1);
if (val0 == -1) { break; }
Expand All @@ -436,40 +317,21 @@ int searchjk(void* data)
}

for (int x = 0; x < (int)arraysearchimages.size(); x++) {
CURL *curl;
FILE *fp;
CURLcode res = CURLE_OK;


curl = curl_easy_init();
if (curl) {
std::string tempima = arraysearchimages[x];
std::cout << tempima << selectchapter << std::endl;
replace(tempima,"https://cdn.jkanime.net/assets/images/animes/image/","");
replace(tempima,".jpg0", "");
replace(tempima,".jpg", "");
#ifdef __SWITCH__
std::string directorydownloadimage = "sdmc:/RipJKAnime/s";
directorydownloadimage.append(std::to_string(x));
std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/";
directorydownloadimage.append(tempima);
directorydownloadimage.append(".jpg");
#else
std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/s";
directorydownloadimage.append(std::to_string(x));
std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/";
directorydownloadimage.append(tempima);
directorydownloadimage.append(".jpg");
#endif // SWITCH

fp = fopen(directorydownloadimage.c_str(), "wb");
curl_easy_setopt(curl, CURLOPT_URL, tempima.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));}

}
if(!isFileExist(directorydownloadimage.c_str()))
downloadfile(arraysearchimages[x],directorydownloadimage,false);

porcentajereload = ((x + 1) * 100) / arraysearchimages.size();
}
Expand Down Expand Up @@ -574,4 +436,41 @@ std::string capit(std::string b) {
}


};
};

bool isFavorite(std::string fav){
static std::string limit = "";
if (limit == fav){
return gFAV;
} else limit = fav;
std::ifstream file(favoritosdirectory);
std::string str;
while (std::getline(file, str)) {
// std::cout << str << "\n";
if (str.find("jkanime"))
{printf("-%s-- -%s--\n",fav.c_str(),str.c_str());
if (fav == str){file.close(); return true;}
}
}
file.close();
return false;
}
void delFavorite(int inst = -1){

std::string tmp="";
if (inst > 0){//delete all if is -1 delFavorite();
std::ifstream file(favoritosdirectory);
std::string str = "";

int index = 0;
while (std::getline(file, str)) {
if (inst != index){tmp += str+"\n";}
index++;
}
file.close();
}

std::ofstream outfile(favoritosdirectory);
outfile << tmp;
outfile.close();
}
Loading

0 comments on commit d62d0fb

Please sign in to comment.