mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 13:37:03 +03:00
new cspot/bell
This commit is contained in:
@@ -1,51 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <pb_encode.h>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "NanoPBHelper.h"
|
||||
#include "Utils.h"
|
||||
#include "pb_decode.h"
|
||||
#include "protobuf/spirc.pb.h"
|
||||
namespace cspot {
|
||||
|
||||
namespace cspot {
|
||||
struct TrackReference {
|
||||
static constexpr auto base62Alphabet =
|
||||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
TrackReference();
|
||||
|
||||
// Resolved track GID
|
||||
std::vector<uint8_t> gid;
|
||||
std::string uri, context;
|
||||
std::optional<bool> queued;
|
||||
|
||||
// Type identifier
|
||||
enum class Type { TRACK, EPISODE };
|
||||
|
||||
Type type;
|
||||
|
||||
static TrackReference fromTrackRef(TrackRef* ref) {
|
||||
TrackReference trackRef;
|
||||
if (ref->gid != nullptr) {
|
||||
// For tracks, the GID is already in the protobuf
|
||||
trackRef.gid = pbArrayToVector(ref->gid);
|
||||
trackRef.type = Type::TRACK;
|
||||
} else {
|
||||
// Episode GID is being fetched via base62 encoded URI
|
||||
auto uri = std::string(ref->uri);
|
||||
auto idString = uri.substr(uri.find_last_of(":") + 1, uri.size());
|
||||
trackRef.gid = {0};
|
||||
void decodeURI();
|
||||
|
||||
std::string_view alphabet(base62Alphabet);
|
||||
for (int x = 0; x < idString.size(); x++) {
|
||||
size_t d = alphabet.find(idString[x]);
|
||||
trackRef.gid = bigNumMultiply(trackRef.gid, 62);
|
||||
trackRef.gid = bigNumAdd(trackRef.gid, d);
|
||||
}
|
||||
}
|
||||
bool operator==(const TrackReference& other) const;
|
||||
|
||||
return trackRef;
|
||||
}
|
||||
// Encodes list of track references into a pb structure, used by nanopb
|
||||
static bool pbEncodeTrackList(pb_ostream_t* stream, const pb_field_t* field,
|
||||
void* const* arg);
|
||||
|
||||
static TrackReference fromGID(std::vector<uint8_t> gid, bool isEpisode) {
|
||||
TrackReference trackRef;
|
||||
trackRef.gid = gid;
|
||||
trackRef.type = isEpisode ? Type::EPISODE : Type::TRACK;
|
||||
return trackRef;
|
||||
}
|
||||
static bool pbDecodeTrackList(pb_istream_t* stream, const pb_field_t* field,
|
||||
void** arg);
|
||||
};
|
||||
} // namespace cspot
|
||||
} // namespace cspot
|
||||
|
||||
Reference in New Issue
Block a user