mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-05-03 03:49:31 +01:00
airplay artwork and CSpot leak fix (temporary)
This commit is contained in:
@@ -10,8 +10,8 @@ SpotifyTrack::SpotifyTrack(std::shared_ptr<MercuryManager> manager, std::shared_
|
||||
{
|
||||
this->manager = manager;
|
||||
this->fileId = std::vector<uint8_t>();
|
||||
episodeInfo = Episode_init_default;
|
||||
trackInfo = Track_init_default;
|
||||
episodeInfo = {};
|
||||
trackInfo = {};
|
||||
|
||||
mercuryCallback trackResponseLambda = [=](std::unique_ptr<MercuryResponse> res) {
|
||||
this->trackInformationCallback(std::move(res), position_ms, isPaused);
|
||||
@@ -53,18 +53,18 @@ bool SpotifyTrack::countryListContains(std::string countryList, std::string coun
|
||||
|
||||
bool SpotifyTrack::canPlayTrack()
|
||||
{
|
||||
for (int x = 0; x < trackInfo.restriction_count; x++)
|
||||
{
|
||||
if (trackInfo.restriction[x].countries_allowed != nullptr)
|
||||
{
|
||||
return countryListContains(std::string(trackInfo.restriction[x].countries_allowed), manager->countryCode);
|
||||
}
|
||||
|
||||
if (trackInfo.restriction[x].countries_forbidden != nullptr)
|
||||
{
|
||||
return !countryListContains(std::string(trackInfo.restriction[x].countries_forbidden), manager->countryCode);
|
||||
}
|
||||
}
|
||||
// for (int x = 0; x < trackInfo.restriction_count; x++)
|
||||
// {
|
||||
// if (strlen(trackInfo.restriction[x].countries_allowed) > 0)
|
||||
// {
|
||||
// return countryListContains(std::string(trackInfo.restriction[x].countries_allowed), manager->countryCode);
|
||||
// }
|
||||
//
|
||||
// if (strlen(trackInfo.restriction[x].countries_forbidden) > 0)
|
||||
// {
|
||||
// return !countryListContains(std::string(trackInfo.restriction[x].countries_forbidden), manager->countryCode);
|
||||
// }
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -77,35 +77,39 @@ void SpotifyTrack::trackInformationCallback(std::unique_ptr<MercuryResponse> res
|
||||
|
||||
pb_release(Track_fields, &trackInfo);
|
||||
pbDecode(trackInfo, Track_fields, response->parts[0]);
|
||||
//
|
||||
// CSPOT_LOG(info, "Track name: %s", trackInfo.name);
|
||||
// CSPOT_LOG(info, "Track duration: %d", trackInfo.duration);
|
||||
// CSPOT_LOG(debug, "trackInfo.restriction.size() = %d", trackInfo.restriction_count);
|
||||
// int altIndex = 0;
|
||||
// while (!canPlayTrack())
|
||||
// {
|
||||
// auto src = trackInfo.alternative[altIndex].restriction;
|
||||
//// std::copy(std::begin(src), std::end(src), std::begin(trackInfo.restriction));
|
||||
//// trackInfo.restriction_count = trackInfo.alternative[altIndex].restriction_count;
|
||||
////
|
||||
//// free(trackInfo.gid);
|
||||
// trackInfo.gid = trackInfo.alternative[altIndex].gid;
|
||||
// altIndex++;
|
||||
// CSPOT_LOG(info, "Trying alternative %d", altIndex);
|
||||
// }
|
||||
|
||||
CSPOT_LOG(info, "Track name: %s", trackInfo.name);
|
||||
CSPOT_LOG(info, "Track duration: %d", trackInfo.duration);
|
||||
CSPOT_LOG(debug, "trackInfo.restriction.size() = %d", trackInfo.restriction_count);
|
||||
int altIndex = 0;
|
||||
while (!canPlayTrack())
|
||||
{
|
||||
trackInfo.restriction = trackInfo.alternative[altIndex].restriction;
|
||||
trackInfo.restriction_count = trackInfo.alternative[altIndex].restriction_count;
|
||||
trackInfo.gid = trackInfo.alternative[altIndex].gid;
|
||||
trackInfo.file = trackInfo.alternative[altIndex].file;
|
||||
altIndex++;
|
||||
CSPOT_LOG(info, "Trying alternative %d", altIndex);
|
||||
}
|
||||
auto trackId = pbArrayToVector(trackInfo.gid);
|
||||
auto trackId = std::vector(trackInfo.gid.bytes, trackInfo.gid.bytes + trackInfo.gid.size);
|
||||
this->fileId = std::vector<uint8_t>();
|
||||
|
||||
for (int x = 0; x < trackInfo.file_count; x++)
|
||||
{
|
||||
if (trackInfo.file[x].format == configMan->format)
|
||||
{
|
||||
this->fileId = pbArrayToVector(trackInfo.file[x].file_id);
|
||||
this->fileId = std::vector(trackInfo.file[x].file_id.bytes, trackInfo.file[x].file_id.bytes + trackInfo.file[x].file_id.size);
|
||||
break; // If file found stop searching
|
||||
}
|
||||
}
|
||||
|
||||
if (trackInfoReceived != nullptr)
|
||||
{
|
||||
auto imageId = pbArrayToVector(trackInfo.album.cover_group.image[0].file_id);
|
||||
auto imageIdBytes = trackInfo.album.cover_group.image[0].file_id;
|
||||
auto imageId = std::vector(imageIdBytes.bytes, imageIdBytes.bytes + imageIdBytes.size);
|
||||
TrackInfo simpleTrackInfo = {
|
||||
.name = std::string(trackInfo.name),
|
||||
.album = std::string(trackInfo.album.name),
|
||||
@@ -139,14 +143,15 @@ void SpotifyTrack::episodeInformationCallback(std::unique_ptr<MercuryResponse> r
|
||||
{
|
||||
if (episodeInfo.audio[x].format == AudioFormat_OGG_VORBIS_96)
|
||||
{
|
||||
this->fileId = pbArrayToVector(episodeInfo.audio[x].file_id);
|
||||
this->fileId = std::vector(episodeInfo.audio[x].file_id.bytes, episodeInfo.audio[x].file_id.bytes + episodeInfo.audio[x].file_id.size);
|
||||
break; // If file found stop searching
|
||||
}
|
||||
}
|
||||
|
||||
if (trackInfoReceived != nullptr)
|
||||
{
|
||||
auto imageId = pbArrayToVector(episodeInfo.covers->image[0].file_id);
|
||||
auto imageFileId = episodeInfo.covers.image[0].file_id;
|
||||
auto imageId = std::vector(imageFileId.bytes, imageFileId.bytes + imageFileId.size);
|
||||
TrackInfo simpleTrackInfo = {
|
||||
.name = std::string(episodeInfo.name),
|
||||
.album = "",
|
||||
@@ -159,7 +164,7 @@ void SpotifyTrack::episodeInformationCallback(std::unique_ptr<MercuryResponse> r
|
||||
trackInfoReceived(simpleTrackInfo);
|
||||
}
|
||||
|
||||
this->requestAudioKey(pbArrayToVector(episodeInfo.gid), this->fileId, episodeInfo.duration, position_ms, isPaused);
|
||||
this->requestAudioKey(std::vector(episodeInfo.gid.bytes, episodeInfo.gid.bytes + episodeInfo.gid.size), this->fileId, episodeInfo.duration, position_ms, isPaused);
|
||||
}
|
||||
|
||||
void SpotifyTrack::requestAudioKey(std::vector<uint8_t> fileId, std::vector<uint8_t> trackId, int32_t trackDuration, uint32_t position_ms, bool isPaused)
|
||||
|
||||
Reference in New Issue
Block a user