Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnVN committed Jul 11, 2024
1 parent 6ee6fd4 commit 398f18c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Release
run: |
gh release create release Release/libEGL.dll
gh release upload release --clobber Release/libEGL.dll
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void Config::LoadConfig() {

if (d.HasMember("downloadType")) {
DL::downloadType = d["downloadType"].GetInt();
if (DL::downloadType > 2 || DL::downloadType < 0) DL::downloadType = 2;
if (DL::downloadType > 1 || DL::downloadType < 0) DL::downloadType = 1;
}

if (d.HasMember("dontDownload")) DL::dontDownload = d["dontDownload"].GetBool();
Expand Down
96 changes: 57 additions & 39 deletions downloader.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "Downloader.h"
#include "downloader.h"
#include "logger.h"
#include "utils.h"
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <regex>
#include <time.h>

using namespace rapidjson;

const char *DL::DlTypeName[3] = {"Full Version", "No Video", "Mini"};
const char *DL::DlTypeName[2] = {"Full", "No Video"};
Lock DL::taskLock;
int DL::downloadType = MINI;
int DL::downloadType = NOVIDEO;
bool DL::dontDownload = false;
map<string, DlInfo> DL::tasks;
int DL::manualDlType = 0;
Expand Down Expand Up @@ -122,81 +124,97 @@ CURLcode DL::CurlDownload(const string url, const string fileName, MyProgress *p
return res;
}

// use sayobot api to parse sid,song name,category by osu beatmap url
int DL::SayobotParseInfo(string url, UINT32 &sid, string &songName, int &category) {
string parseApiUrl = "https://api.sayobot.cn/v2/beatmapinfo?0=" + url;
// use catboy api to parse sid,song name,category by osu beatmap url
int DL::CatboyParseInfo(string url, UINT32 &sid, string &artist, string &songName, string &category) {
string parseApiUrl;
string content;
Document jContent;
int status;

vector<regex> e;
e.push_back(regex("osu.ppy.sh/b/(\\d{1,})"));
e.push_back(regex("osu.ppy.sh/s/(\\d{1,})"));
e.push_back(regex("osu.ppy.sh/beatmapsets/(\\d{1,})"));
e.push_back(regex("osu.ppy.sh/beatmaps/(\\d{1,})"));
smatch m;
bool found = false;
int setid = 0, bid = 0;

for (int i = 0; i < 4; i++) {
found = regex_search(url, m, e[i]);

if (found) {
if (i == 0 || i == 3) {
bid = atoi(m.str(1).c_str());
} else {
setid = atoi(m.str(1).c_str());
}
break;
}
}

if (bid != 0) {
parseApiUrl = "https://catboy.best/api/v2/b/" + to_string(bid);
}

if (setid != 0) {
parseApiUrl = "https://catboy.best/api/v2/s/" + to_string(setid);
}

auto res = CurlGetReq(parseApiUrl, content);
if (res) {
logger::WriteLogFormat("[-] SayobotParseInfo: can't get json content, %s", curl_easy_strerror(res));
logger::WriteLogFormat("[-] CatboyParseInfo: can't get json content, %s", curl_easy_strerror(res));
return 1;
}

string utf8Content = GB2312toUTF8(content.c_str());
jContent.Parse(utf8Content.c_str());

if (jContent.HasParseError()) {
logger::WriteLogFormat("[-] SayobotParseInfo: unknown parsing error");
logger::WriteLogFormat("[-] CatboyParseInfo: unknown parsing error");
return 6;
}

if (!jContent.HasMember("status")) {
logger::WriteLogFormat("[-] SayobotParseInfo: Wrong json format: doesn't contain member 'status'");
return 2;
}

status = jContent["status"].GetInt();
if (status) {
logger::WriteLogFormat("[-] SayobotParseInfo: Sayobot err-code: %d", status);
return 3;
}

if (!jContent.HasMember("data")) {
logger::WriteLogFormat("[-] SayobotParseInfo: Wrong json format: doesn't contain member 'data'");
return 4;
if (jContent.HasMember("set")) {
jContent["set"].Swap(jContent);
}

if (!jContent["data"].HasMember("sid") || !jContent["data"].HasMember("title") || !jContent["data"].HasMember("approved")) {
logger::WriteLogFormat("[-] SayobotParseInfo: Wrong json format: doesn't contain member 'sid' or 'title' or 'approved'");
return 5;
if (!jContent.HasMember("id") || !jContent.HasMember("artist") || !jContent.HasMember("title") || !jContent.HasMember("status")) {
logger::WriteLogFormat("[-] CatboyParseInfo: Wrong json format: doesn't contain member 'id' or 'artist' or 'title' or 'status'");
return 2;
}

sid = jContent["data"]["sid"].GetUint();
songName = jContent["data"]["title"].GetString();
category = jContent["data"]["approved"].GetInt();
sid = jContent["id"].GetUint();
artist = jContent["artist"].GetString();
songName = jContent["title"].GetString();
category = jContent["status"].GetString();
return 0;
}

int DL::ParseInfo(string url, UINT32 &sid, string &songName, int &category) {
int DL::ParseInfo(string url, UINT32 &sid, string &artist, string &songName, string &category) {
logger::WriteLogFormat("[*] parsing %s", url.c_str());
return SayobotParseInfo(url, sid, songName, category);
return CatboyParseInfo(url, sid, artist, songName, category);
}

// download beatmap from sayobot server to file by using sid
int DL::SayobotDownload(string fileName, UINT32 sid, string taskKey) {
// download beatmap from catboy server to file by using sid
int DL::CatboyDownload(string fileName, UINT32 sid, string taskKey) {
string downloadApiUrl;

switch (DL::downloadType) {
case FULL:
downloadApiUrl = "https://txy1.sayobot.cn/beatmaps/download/full/" + to_string(sid);
break;
case NOVIDEO:
downloadApiUrl = "https://txy1.sayobot.cn/beatmaps/download/novideo/" + to_string(sid);
downloadApiUrl = "https://catboy.best/d/" + to_string(sid);
break;
case MINI:
default:
downloadApiUrl = "https://txy1.sayobot.cn/beatmaps/download/mini/" + to_string(sid);
case NOVIDEO:
downloadApiUrl = "https://catboy.best/d/" + to_string(sid) + "n";
break;
}

MyProgress *myp = new MyProgress();
myp->taskKey = taskKey;
auto res = DL::CurlDownload(downloadApiUrl, fileName, myp);
if (res) {
logger::WriteLogFormat("[-] SayobotDownload: err while downloading, %s", curl_easy_strerror(res));
logger::WriteLogFormat("[-] CatboyDownload: err while downloading, %s", curl_easy_strerror(res));
delete myp;
return 2;
}
Expand All @@ -207,7 +225,7 @@ int DL::SayobotDownload(string fileName, UINT32 sid, string taskKey) {

int DL::Download(string fileName, UINT32 sid, string taskKey) {
logger::WriteLogFormat("[*] downloading sid %lu", sid);
return SayobotDownload(fileName, sid, taskKey);
return CatboyDownload(fileName, sid, taskKey);
}

int DL::ManualDownload(string id, int idType) {
Expand Down
25 changes: 7 additions & 18 deletions downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ using namespace std;

enum DlType {
FULL,
NOVIDEO,
MINI
NOVIDEO
};

enum DlStatus {
Expand All @@ -19,22 +18,12 @@ enum DlStatus {
DOWNLOAD
};

enum Category {
UNKNOWN = -3,
GRAVEYARD = -2,
WIP = -1,
PENDING = 0,
RANKED = 1,
APPROVED = 2,
QUALIFIED = 3,
LOVED = 4
};

struct DlInfo {
DlStatus dlStatus = NONE;
UINT32 sid = 0;
string artist = "";
string songName = "";
Category category = UNKNOWN;
string category = "";
double fileSize = 0;
double downloaded = 0;
float percent = 0;
Expand All @@ -45,7 +34,7 @@ struct MyProgress {
};

namespace DL {
extern const char *DlTypeName[3];
extern const char *DlTypeName[2];
extern Lock taskLock;
extern int downloadType;
extern bool dontDownload;
Expand All @@ -55,9 +44,9 @@ namespace DL {

CURLcode CurlGetReq(const string url, string &response, const vector<string> extendHeader = vector<string>());
CURLcode CurlDownload(const string url, const string fileName, MyProgress *prog, const vector<string> extendHeader = vector<string>());
int SayobotParseInfo(string url, UINT32 &sid, string &songName, int &approved);
int ParseInfo(string url, UINT32 &sid, string &songName, int &category);
int SayobotDownload(string fileName, UINT32 sid, string taskKey);
int CatboyParseInfo(string url, UINT32 &sid, string &artist, string &songName, string &category);
int ParseInfo(string url, UINT32 &sid, string &artist, string &songName, string &category);
int CatboyDownload(string fileName, UINT32 sid, string taskKey);
int Download(string fileName, UINT32 sid, string taskKey);
int ManualDownload(string id, int idType);
int RemoveTaskInfo(string url);
Expand Down
10 changes: 6 additions & 4 deletions hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ DWORD WINAPI DownloadThread(LPVOID lpParam) {
int res;
char tmpPath[MAX_PATH];
UINT32 sid = 0;
string artist = "";
string songName = "";
string fileName = "";
int category = 0;
string category = "";
DL::SetTaskReadLock();
// already in process, skip
if (DL::tasks.count(url) > 0) {
Expand All @@ -82,21 +83,22 @@ DWORD WINAPI DownloadThread(LPVOID lpParam) {
DL::tasks[url].songName = url;
DL::UnsetTaskLock();
// parse sid, song name and category
res = DL::ParseInfo(url, sid, songName, category);
res = DL::ParseInfo(url, sid, artist, songName, category);
if (res || DL::tasks.count(url) <= 0 || DB::mapExist(sid)) {
CallOriShellExecuteExW(url);
goto finish;
}
DL::SetTaskWriteLock();
DL::tasks[url].dlStatus = DOWNLOAD;
DL::tasks[url].artist = artist;
DL::tasks[url].songName = songName;
DL::tasks[url].sid = sid;
DL::tasks[url].category = (Category)category;
DL::tasks[url].category = category;
DL::UnsetTaskLock();
// download map
GetTempPathA(MAX_PATH, tmpPath);
fileName.append(tmpPath);
fileName.append(to_string(sid));
fileName.append(to_string(sid) + " " + artist + " - " + songName);
fileName.append(".osz");
res = DL::Download(fileName, sid, url);
if (res) {
Expand Down
4 changes: 2 additions & 2 deletions map_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ bool DB::mapExistFast(string url) {
bool found = false;
int sid = 0, bid = 0;

for (int i = 0; i < 3; i++) {
for (int i = 0; i < 4; i++) {
found = regex_search(url, m, e[i]);

if (found) {
if (i == 0) {
if (i == 0 || i == 3) {
bid = atoi(m.str(1).c_str());
} else {
sid = atoi(m.str(1).c_str());
Expand Down
36 changes: 6 additions & 30 deletions overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,36 +144,12 @@ void Overlay::RenderOverlay(HDC hdc) {
break;
case DOWNLOAD:
ImGui::Text(" Status: Downloading %c", "|/-\\"[(int)(ImGui::GetTime() / 0.1f) & 3]);
ImGui::Text("MapsetID: %llu", keyIter->second.sid);
ImGui::Text("MapsetID: %lu", keyIter->second.sid);
ImGui::Text(" Artist: %s", keyIter->second.artist.c_str());
ImGui::Text("SongName: %s", keyIter->second.songName.c_str());
switch (keyIter->second.category) {
case GRAVEYARD:
ImGui::Text("Category: Graveyard");
break;
case WIP:
ImGui::Text("Category: WIP");
break;
case PENDING:
ImGui::Text("Category: Pending");
break;
case RANKED:
ImGui::Text("Category: Ranked");
break;
case APPROVED:
ImGui::Text("Category: Approved");
break;
case QUALIFIED:
ImGui::Text("Category: Qualified");
break;
case LOVED:
ImGui::Text("Category: Loved");
break;
default:
ImGui::Text("Category: Unkown");
break;
}
ImGui::Text("Category: %s", keyIter->second.category.c_str());
ImGui::Text("FileSize: %.2fMB / %.2fMB", keyIter->second.downloaded / 0x100000, keyIter->second.fileSize / 0x100000);
ImGui::ProgressBar(keyIter->second.percent, ImVec2(-1, 5));
ImGui::ProgressBar(keyIter->second.percent);
break;
default:
ImGui::Text(" Status: Idle");
Expand All @@ -195,9 +171,9 @@ void Overlay::RenderOverlay(HDC hdc) {
// downloader settings
ImGui::Checkbox("Disable in-game downloader", &DL::dontDownload);
ImGui::Text("- OSZ Version:");
ImGui::Combo("##oszVersion1", &DL::downloadType, DL::DlTypeName, 3);
ImGui::Combo("##oszVersion1", &DL::downloadType, DL::DlTypeName, 2);
ImGui::SameLine();
HelpMarker("1. <Full Version> is full version.\n2. <No Video> doesn't contain video.\n3. <Mini> doesn't contain video and keysound.");
HelpMarker("1. <Full> is full version.\n2. <No Video> doesn't contain video.");
// manual download
ImGui::Separator();
ImGui::Text("[ Manual Download ]");
Expand Down

0 comments on commit 398f18c

Please sign in to comment.