remove submodule
This commit is contained in:
parent
498f95668d
commit
b942b58b34
|
@ -4,5 +4,5 @@ file(GLOB_RECURSE SOURCES "src/*.cpp")
|
|||
add_executable (rpc ${SOURCES})
|
||||
set_property(TARGET rpc PROPERTY CXX_STANDARD 20)
|
||||
add_subdirectory("vendor")
|
||||
target_link_libraries(rpc PUBLIC WindowsApp discord-rpc)
|
||||
target_link_libraries(rpc PUBLIC WindowsApp discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls)
|
||||
target_include_directories(rpc PRIVATE vendor)
|
17
src/main.cpp
17
src/main.cpp
|
@ -55,7 +55,7 @@ int main() {
|
|||
std::string currentMediaSource = mediaInformation->playbackSource;
|
||||
std::cout << currentMediaSource << std::endl;
|
||||
if (currentMediaSource != lastMediaSource)
|
||||
Discord_Shutdown(); //reinitialize with new client id
|
||||
Discord_Shutdown(); // reinitialize with new client id
|
||||
|
||||
std::string serviceName = utils::getAppName(lastMediaSource);
|
||||
DiscordRichPresence activity{};
|
||||
|
@ -63,19 +63,26 @@ int main() {
|
|||
activity.details = mediaInformation->songTitle.c_str();
|
||||
activity.state = std::string("by " + mediaInformation->songArtist).c_str();
|
||||
activity.smallImageText = serviceName.c_str();
|
||||
std::string artworkURL = utils::getArtworkURL(mediaInformation->songTitle + " " + mediaInformation->songArtist +
|
||||
" " + mediaInformation->songAlbum);
|
||||
|
||||
activity.smallImageKey = "icon";
|
||||
|
||||
if (artworkURL == "") {
|
||||
activity.smallImageKey = "";
|
||||
activity.largeImageText = "icon";
|
||||
} else {
|
||||
activity.largeImageText = mediaInformation->songAlbum.c_str();
|
||||
activity.largeImageKey = "";
|
||||
activity.largeImageKey = artworkURL.c_str();
|
||||
}
|
||||
|
||||
if(mediaInformation->songDuration != 0) {
|
||||
if (mediaInformation->songDuration != 0) {
|
||||
int64_t remainingTime = mediaInformation->songDuration - mediaInformation->songElapsedTime;
|
||||
activity.startTimestamp = time(nullptr) - mediaInformation->songElapsedTime;
|
||||
activity.endTimestamp = time(nullptr) + remainingTime;
|
||||
}
|
||||
std::string endpointURL = utils::getSearchEndpoint(lastMediaSource);
|
||||
|
||||
if(endpointURL != "") {
|
||||
if (endpointURL != "") {
|
||||
activity.button1name = std::string("Search on " + serviceName).c_str();
|
||||
std::string searchQuery = mediaInformation->songTitle + " " + mediaInformation->songArtist;
|
||||
activity.button1link = std::string(endpointURL + utils::urlEncode(searchQuery)).c_str();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifndef _UTILS_
|
||||
#define _UTILS_
|
||||
#include <curl/include/curl/curl.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <nlohmann-json/single_include/nlohmann/json.hpp>
|
||||
|
@ -11,6 +13,62 @@
|
|||
#define CONFIG_FILENAME "known.json"
|
||||
|
||||
namespace utils {
|
||||
inline std::string urlEncode(std::string str) {
|
||||
std::string new_str = "";
|
||||
char c;
|
||||
int ic;
|
||||
const char* chars = str.c_str();
|
||||
char bufHex[10];
|
||||
int len = strlen(chars);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
c = chars[i];
|
||||
ic = c;
|
||||
if (c == ' ')
|
||||
new_str += '+';
|
||||
else if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
|
||||
new_str += c;
|
||||
else {
|
||||
sprintf_s(bufHex, sizeof(bufHex), "%X", c);
|
||||
if (ic < 16)
|
||||
new_str += "%0";
|
||||
else
|
||||
new_str += "%";
|
||||
new_str += bufHex;
|
||||
}
|
||||
}
|
||||
return new_str;
|
||||
}
|
||||
inline size_t curlWriteCallback(char* contents, size_t size, size_t nmemb, void* userp) {
|
||||
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
inline std::string getRequest(std::string url) {
|
||||
CURL* curl;
|
||||
CURLcode res;
|
||||
std::string buf;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return buf;
|
||||
}
|
||||
inline std::string getArtworkURL(std::string query) {
|
||||
std::string response =
|
||||
getRequest("https://itunes.apple.com/search?media=music&entity=song&term=" + urlEncode(query));
|
||||
nlohmann::json j = nlohmann::json::parse(response);
|
||||
auto results = j["results"];
|
||||
if (results.size() > 0) {
|
||||
return results[0]["artworkUrl100"].get<std::string>();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
inline nlohmann::json getApp(std::string processName) {
|
||||
std::ifstream i("known.json");
|
||||
std::stringstream s;
|
||||
|
@ -52,33 +110,6 @@ namespace utils {
|
|||
auto app = getApp(processName);
|
||||
return app["search_endpoint"] == "" ? "" : app["search_endpoint"];
|
||||
}
|
||||
|
||||
inline std::string urlEncode(std::string str) {
|
||||
std::string new_str = "";
|
||||
char c;
|
||||
int ic;
|
||||
const char* chars = str.c_str();
|
||||
char bufHex[10];
|
||||
int len = strlen(chars);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
c = chars[i];
|
||||
ic = c;
|
||||
if (c == ' ')
|
||||
new_str += '+';
|
||||
else if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
|
||||
new_str += c;
|
||||
else {
|
||||
sprintf(bufHex, "%X", c);
|
||||
if (ic < 16)
|
||||
new_str += "%0";
|
||||
else
|
||||
new_str += "%";
|
||||
new_str += bufHex;
|
||||
}
|
||||
}
|
||||
return new_str;
|
||||
}
|
||||
} // namespace utils
|
||||
|
||||
#undef DEFAULT_APP_NAME
|
||||
|
|
|
@ -3,6 +3,7 @@ SET(ENABLE_PROGRAMS OFF)
|
|||
SET(ENABLE_TESTING OFF)
|
||||
add_subdirectory("mbedtls")
|
||||
SET(CURL_USE_MBEDTLS ON)
|
||||
SET(CURL_USE_LIBPSL OFF)
|
||||
SET(BUILD_STATIC_LIBS ON)
|
||||
SET(BUILD_SHARED_LIBS OFF)
|
||||
SET(BUILD_CURL_EXE OFF)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit d6b2214e96fdb7cad468cbe7fc100c0b80522d43
|
|
@ -1 +1 @@
|
|||
Subproject commit cd0fb1d17852077297816e30823b8125ba073357
|
||||
Subproject commit 107ea89daaefb9867ea9121002fbbdf926780e98
|
Loading…
Reference in New Issue