track and disc numbers are now part of the song's metadata and saved to the database

This commit is contained in:
kdeng00
2019-08-28 22:16:33 -04:00
parent b885e3d2c8
commit 1255aa0ff7
10 changed files with 68 additions and 160 deletions
+18
View File
@@ -1,3 +1,4 @@
#include <algorithm>
#include <iostream>
#include <filesystem>
#include <fstream>
@@ -25,9 +26,24 @@ Song metadata_retriever::retrieve_metadata(std::string& song_path)
song.album = file.tag()->album().toCString();
song.genre = file.tag()->genre().toCString();
song.year = file.tag()->year();
song.track = file.tag()->track();
song.duration = file.audioProperties()->lengthInSeconds();
song.songPath = song_path;
// TODO: Move over to this eventually since at the moment
// I am only targetting mp3 files
// Used to retrieve disc
TagLib::MPEG::File sameFile(song_path.c_str());
auto tag = sameFile.ID3v2Tag();
auto frame = tag->frameList("TPOS");
if (frame.isEmpty()) {
song.disc = 1;
// TODO: set default disc to 1 if none found
} else {
song.disc = std::stoi(frame.front()->toString().toCString());
}
return song;
}
@@ -99,5 +115,7 @@ void metadata_retriever::update_metadata(Song sng_updated, const Song sng_old)
file.tag()->setYear(sng_updated.year);
}
// TODO: functionality to update the track number and disc number
file.save();
}