Add track number to song filenames; better metadata parsing for podcasts
This commit is contained in:
parent
db125020db
commit
6492db58e9
@ -134,8 +134,8 @@ struct SongInfo
|
||||
std::string releaseDate{ std::string() };
|
||||
std::string isrc{ std::string() };
|
||||
unsigned int year{ 0 };
|
||||
unsigned int trackNum{ 1 };
|
||||
unsigned int totalTracks{ 1 };
|
||||
unsigned int trackNum{ 0 };
|
||||
unsigned int totalTracks{ 0 };
|
||||
unsigned int discNum{ 0 };
|
||||
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/"
|
||||
+ uri.substr(uri.find("spotify:episode:") + 16), authToken);
|
||||
|
||||
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->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->title = strtok((char*)(metadata.substr(metadata.find("name\" :") + 9)).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->coverUrl = strtok((char*)(metadata.substr(metadata.find("height\" :") + 28)).c_str(), "\"");
|
||||
songInfo->fileType = FileType::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));
|
||||
|
||||
songDir += L"\\" + tempDirArtist + std::wstring(L"\\") + tempDirAlbum + L".\\" + tempDirArtist + L" - "
|
||||
+ tempDirSong + songExtension;
|
||||
songDir += L"\\" + tempDirArtist + std::wstring(L"\\") + tempDirAlbum + L".\\";
|
||||
|
||||
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);
|
||||
songFileOut.write(downloadStr.c_str(), downloadStr.size());
|
||||
|
Loading…
Reference in New Issue
Block a user