Detect erroneous song decryption and alert user when it happens

This commit is contained in:
_ 2020-12-01 01:13:00 -07:00
parent 030d857f58
commit f44d03b070

View File

@ -217,6 +217,13 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s
AES_init_ctx_iv(&ctx, reinterpret_cast<const uint8_t*>(&key[0]), IV);
AES_CTR_xcrypt_buffer(&ctx, reinterpret_cast<uint8_t*>(&downloadStr[0]), downloadStr.size());
// Check if decrypted song data has valid header
if (downloadStr.length() < 4 || downloadStr.compare(0, 4, "OggS") != 0)
{
std::cout << "Error: Could not properly decrypt song (try downloading again)!" << std::endl;
return;
}
// Remove custom Spotify Ogg page from beginning of file
downloadStr = downloadStr.substr(downloadStr.find("\xFF\xFF\xFF\xFFOggS") + 4);
@ -262,9 +269,17 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s
return;
}
// Download encrypted song data from Spotify
// Download episode data from Spotify
downloadStr = DownloadSpotifyUrl(songHost, songPath, "");
// TODO: MP3 files appear to have a variety of headers, not sure this is 100% reliable
// Check if downloaded episode data has valid header
/*if (downloadStr.length() < 3 || downloadStr.compare(0, 3, "ID3") != 0)
{
std::cout << "Error: Could not properly download podcast episode (try downloading again)!" << std::endl;
return;
}*/
// Download episode and show metadata from Spotify API
std::string metadata = DownloadSpotifyUrl("api.spotify.com", "/v1/episodes/"
+ uri.substr(uri.find("spotify:episode:") + 16), authToken);