move to new cspot

This commit is contained in:
philippe44
2023-03-25 16:48:41 -07:00
parent c712b78931
commit 008c36facf
2983 changed files with 465270 additions and 13569 deletions

View File

@@ -1,33 +1,52 @@
#ifndef TRACKREFERENCE_H
#define TRACKREFERENCE_H
#pragma once
#include <string_view>
#include <vector>
#include "NanoPBHelper.h"
#include "Utils.h"
#include "protobuf/spirc.pb.h"
#include <NanoPBHelper.h>
#include <iostream>
#include <string>
namespace cspot {
class TrackReference
{
private:
std::string alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::vector<uint8_t> base62Decode(std::string uri);
struct TrackReference {
static constexpr auto base62Alphabet =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public:
TrackReference(TrackRef *ref);
~TrackReference();
// Resolved track GID
std::vector<uint8_t> gid;
std::vector<uint8_t> gid;
// Type identifier
enum class Type { TRACK, EPISODE };
Type type;
bool isEpisode = false;
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());
/**
* @brief Returns an uri that can be allowed to query track information.
*
* @return std::string
*/
std::string getMercuryRequestUri();
trackRef.gid = {0};
std::string_view alphabet(base62Alphabet);
for (int x = 0; x < uri.size(); x++) {
size_t d = alphabet.find(uri[x]);
trackRef.gid = bigNumMultiply(trackRef.gid, 62);
trackRef.gid = bigNumAdd(trackRef.gid, d);
}
}
return trackRef;
}
static TrackReference fromGID(std::vector<uint8_t> gid, bool isEpisode) {
TrackReference trackRef;
trackRef.gid = gid;
trackRef.type = isEpisode ? Type::EPISODE : Type::TRACK;
return trackRef;
}
};
#endif
} // namespace cspot