mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 05:27:01 +03:00
31 lines
736 B
C++
31 lines
736 B
C++
#include "ApResolve.h"
|
|
|
|
using namespace cspot;
|
|
|
|
ApResolve::ApResolve(std::string apOverride)
|
|
{
|
|
this->apOverride = apOverride;
|
|
}
|
|
|
|
std::string ApResolve::fetchFirstApAddress()
|
|
{
|
|
if (apOverride != "")
|
|
{
|
|
return apOverride;
|
|
}
|
|
|
|
auto request = bell::HTTPClient::get("https://apresolve.spotify.com/");
|
|
std::string_view responseStr = request->body();
|
|
|
|
// parse json with nlohmann
|
|
#if 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
|
|
}
|