Add track number to song filenames; better metadata parsing for podcasts

This commit is contained in:
_ 2020-12-02 18:04:28 -07:00
parent db125020db
commit 6492db58e9

View File

@ -134,8 +134,8 @@ struct SongInfo
std::string releaseDate{ std::string() }; std::string releaseDate{ std::string() };
std::string isrc{ std::string() }; std::string isrc{ std::string() };
unsigned int year{ 0 }; unsigned int year{ 0 };
unsigned int trackNum{ 1 }; unsigned int trackNum{ 0 };
unsigned int totalTracks{ 1 }; unsigned int totalTracks{ 0 };
unsigned int discNum{ 0 }; unsigned int discNum{ 0 };
bool isExplicit{ false }; bool isExplicit{ false };
}; };
@ -432,10 +432,10 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s
std::string metadata = DownloadSpotifyUrl("api.spotify.com", "/v1/episodes/" std::string metadata = DownloadSpotifyUrl("api.spotify.com", "/v1/episodes/"
+ uri.substr(uri.find("spotify:episode:") + 16), authToken); + uri.substr(uri.find("spotify:episode:") + 16), authToken);
songInfo->title = strtok((char*)(metadata.substr(metadata.find("name") + 9)).c_str(), "\""); songInfo->title = strtok((char*)(metadata.substr(metadata.find("name\" :") + 9)).c_str(), "\"");
songInfo->artist = strtok((char*)(metadata.substr(metadata.find("publisher") + 14)).c_str(), "\""); songInfo->artist = strtok((char*)(metadata.substr(metadata.find("publisher\" :") + 14)).c_str(), "\"");
songInfo->album = strtok((char*)(metadata.substr(metadata.find("media_type") + 37)).c_str(), "\""); songInfo->album = strtok((char*)(metadata.substr(metadata.find("media_type\" :") + 37)).c_str(), "\"");
songInfo->coverUrl = strtok((char*)(metadata.substr(metadata.find("height") + 28)).c_str(), "\""); songInfo->coverUrl = strtok((char*)(metadata.substr(metadata.find("height\" :") + 28)).c_str(), "\"");
songInfo->fileType = FileType::MP3; songInfo->fileType = FileType::MP3;
songExtension = L".mp3"; songExtension = L".mp3";
@ -463,8 +463,17 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s
{ {
std::wstring tempDirSong = FixPathStr(Utf8ToUtf16(songInfo->title)); std::wstring tempDirSong = FixPathStr(Utf8ToUtf16(songInfo->title));
songDir += L"\\" + tempDirArtist + std::wstring(L"\\") + tempDirAlbum + L".\\" + tempDirArtist + L" - " songDir += L"\\" + tempDirArtist + std::wstring(L"\\") + tempDirAlbum + L".\\";
+ tempDirSong + songExtension;
if (songInfo->trackNum != 0)
{
std::wstring trackNumStr = std::to_wstring(songInfo->trackNum);
trackNumStr = std::wstring(2 - trackNumStr.length(), '0') + trackNumStr; // Pad with zeroes
songDir += trackNumStr + L". ";
}
songDir += tempDirArtist + L" - " + tempDirSong + songExtension;
std::ofstream songFileOut(songDir, std::ios_base::binary); std::ofstream songFileOut(songDir, std::ios_base::binary);
songFileOut.write(downloadStr.c_str(), downloadStr.size()); songFileOut.write(downloadStr.c_str(), downloadStr.size());