mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-12 22:47:15 +03:00
new cspot/bell
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user