Update Track fields and file tag handling
Change Track members: artwork -> std::string, genre -> TagLib::String, and add year File::readFileTag now takes a Track& and fills artist/title/album/trackNr/year/genre/format/length importFolder sets artwork to <folder>/cover.png Rename Database::addSong to addTrack
This commit is contained in:
@@ -29,9 +29,10 @@ struct Track {
|
||||
TagLib::String album;
|
||||
unsigned int trackNr;
|
||||
unsigned int length;
|
||||
unsigned int year;
|
||||
std::string filePath;
|
||||
std::string_view artwork;
|
||||
std::string_view genre;
|
||||
std::string artwork;
|
||||
TagLib::String genre;
|
||||
std::string format;
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class Database {
|
||||
void fetch( const std::string& query ) const;
|
||||
void fetchAlbum( const std::string& album ) const;
|
||||
void fetchAll() const;
|
||||
void addSong( );
|
||||
void addTrack();
|
||||
private:
|
||||
sqlite3* db_;
|
||||
sqlite3_stmt* stmnt;
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ class File {
|
||||
public:
|
||||
void importFile( std::string fileName );
|
||||
void importFolder( const std::string& folderPath, std::vector<Track>& tracks );
|
||||
void readFileTag( const char* fileName );
|
||||
void readFileTag( Track& t );
|
||||
std::string parseFiletype( const std::string& path );
|
||||
|
||||
private:
|
||||
|
||||
+9
-5
@@ -12,19 +12,23 @@ void File::importFolder(const std::string& folderPath, std::vector<Track>& track
|
||||
for ( const auto& audioFile : fs::directory_iterator{ folderPath }) {
|
||||
Track t;
|
||||
t.filePath = static_cast<std::string>(audioFile.path());
|
||||
t.artwork = folderPath + "/" + "cover.png";
|
||||
readFileTag( t );
|
||||
tracks.push_back( t );
|
||||
}
|
||||
}
|
||||
|
||||
void File::readFileTag( const char* fileName, std::vector<Track>& tracks ) {
|
||||
TagLib::FileRef f( fileName );
|
||||
Track t;
|
||||
void File::readFileTag( Track& t ) {
|
||||
TagLib::FileRef f( reinterpret_cast<const char*>(&t.filePath ));
|
||||
if ( !f.isNull() ) {
|
||||
t.artist = ( f.tag()->artist().isEmpty() ) ? "" : ( f.tag()->artist());
|
||||
t.title = ( f.tag()->title().isEmpty() ) ? "" : ( f.tag()->title());
|
||||
t.album = ( f.tag()->album().isEmpty() ) ? "" : ( f.tag()->album());
|
||||
t.trackNr = ( f.tag()->track() );
|
||||
|
||||
t.year = ( f.tag()->track() );
|
||||
t.genre = ( f.tag()->genre().isEmpty() ) ? "" : ( f.tag()->genre() );
|
||||
t.format = parseFiletype( t.filePath );
|
||||
t.length = ( f.audioProperties()->lengthInSeconds() ) ? f.audioProperties()->lengthInSeconds() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,5 +37,5 @@ std::string File::parseFiletype( const std::string& path ){
|
||||
size_t length = path.size();
|
||||
size_t dot = path.find_last_of( ".");
|
||||
|
||||
return path.substr( dot + 1, length-dot );
|
||||
return path.substr( dot + 1, length - dot );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user