diff --git a/SpotifyKeyDumper/Utils.cpp b/SpotifyKeyDumper/Utils.cpp index cc24573..ed35d52 100644 --- a/SpotifyKeyDumper/Utils.cpp +++ b/SpotifyKeyDumper/Utils.cpp @@ -217,6 +217,13 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s AES_init_ctx_iv(&ctx, reinterpret_cast(&key[0]), IV); AES_CTR_xcrypt_buffer(&ctx, reinterpret_cast(&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);