new cspot/bell

This commit is contained in:
philippe44
2023-05-06 23:50:26 +02:00
parent e0e7e718ba
commit 8bad480112
163 changed files with 6611 additions and 6739 deletions

View File

@@ -1,10 +1,10 @@
#include "ApResolve.h"
#include <initializer_list> // for initializer_list
#include <map> // for operator!=, operator==
#include <memory> // for allocator, unique_ptr
#include <string_view> // for string_view
#include <vector> // for vector
#include <initializer_list> // for initializer_list
#include <map> // for operator!=, operator==
#include <memory> // for allocator, unique_ptr
#include <string_view> // for string_view
#include <vector> // for vector
#include "HTTPClient.h" // for HTTPClient, HTTPClient::Response
#ifdef BELL_ONLY_CJSON
@@ -16,29 +16,27 @@
using namespace cspot;
ApResolve::ApResolve(std::string apOverride)
{
this->apOverride = apOverride;
ApResolve::ApResolve(std::string apOverride) {
this->apOverride = apOverride;
}
std::string ApResolve::fetchFirstApAddress()
{
if (apOverride != "")
{
return apOverride;
}
std::string ApResolve::fetchFirstApAddress() {
if (apOverride != "") {
return apOverride;
}
auto request = bell::HTTPClient::get("https://apresolve.spotify.com/");
std::string_view responseStr = request->body();
auto request = bell::HTTPClient::get("https://apresolve.spotify.com/");
std::string_view responseStr = request->body();
// parse json with nlohmann
// parse json with nlohmann
#ifdef BELL_ONLY_CJSON
cJSON* json = cJSON_Parse(responseStr.data());
auto ap_string = std::string(cJSON_GetArrayItem(cJSON_GetObjectItem(json, "ap_list"), 0)->valuestring);
cJSON_Delete(json);
return ap_string;
#else
auto json = nlohmann::json::parse(responseStr);
return json["ap_list"][0];
#endif
cJSON* json = cJSON_Parse(responseStr.data());
auto ap_string = std::string(
cJSON_GetArrayItem(cJSON_GetObjectItem(json, "ap_list"), 0)->valuestring);
cJSON_Delete(json);
return ap_string;
#else
auto json = nlohmann::json::parse(responseStr);
return json["ap_list"][0];
#endif
}