Better bounds checking and error handling when downloading

This commit is contained in:
_ 2020-11-29 15:17:19 -07:00
parent 5e0142783c
commit f805a28081

View File

@ -140,7 +140,13 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k
std::string srStr = DownloadSpotifyUrl("spclient.wg.spotify.com", std::string srStr = DownloadSpotifyUrl("spclient.wg.spotify.com",
"/storage-resolve/files/audio/interactive_prefetch/" + fileId + "?product=0", authToken); "/storage-resolve/files/audio/interactive_prefetch/" + fileId + "?product=0", authToken);
if (srStr.length() > 5 && srStr.substr(0, 5).compare("Error") == 0) if (srStr.length() <= 5)
{
std::cout << "Error: Couldn't fetch storage resolve!" << std::endl;
return;
}
if (srStr.substr(0, 5).compare("Error") == 0)
{ {
std::cout << srStr << std::endl; std::cout << srStr << std::endl;
return; return;
@ -174,13 +180,13 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k
// Download encrypted song data from Spotify // Download encrypted song data from Spotify
std::string songStr = DownloadSpotifyUrl(songHost, songPath, ""); std::string songStr = DownloadSpotifyUrl(songHost, songPath, "");
if (songStr.empty()) if (songStr.length() <= 6)
{ {
std::cout << "Error: Could not download audio" << std::endl; std::cout << "Error: Could not download audio!" << std::endl;
return; return;
} }
if (songStr.length() > 6 && songStr.substr(0, 6).compare("<HTML>") == 0) if (songStr.substr(0, 6).compare("<HTML>") == 0)
{ {
std::cout << "Error: " + songStr << std::endl; std::cout << "Error: " + songStr << std::endl;
return; return;