From de9db599b9b1f3c99a170dab5fba27f64a6cef2e Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Sun, 21 Jun 2026 11:47:29 +0200 Subject: [PATCH] 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 /cover.png Rename Database::addSong to addTrack --- include/Containers.h | 5 +++-- include/Database.h | 2 +- include/File.h | 2 +- src/File.cpp | 14 +++++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/Containers.h b/include/Containers.h index c27d057..36fe15f 100644 --- a/include/Containers.h +++ b/include/Containers.h @@ -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; }; diff --git a/include/Database.h b/include/Database.h index fdb0c5f..6306627 100644 --- a/include/Database.h +++ b/include/Database.h @@ -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; diff --git a/include/File.h b/include/File.h index 53bb902..90af39d 100644 --- a/include/File.h +++ b/include/File.h @@ -12,7 +12,7 @@ class File { public: void importFile( std::string fileName ); void importFolder( const std::string& folderPath, std::vector& tracks ); - void readFileTag( const char* fileName ); + void readFileTag( Track& t ); std::string parseFiletype( const std::string& path ); private: diff --git a/src/File.cpp b/src/File.cpp index b5a791a..d46b5cc 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -12,19 +12,23 @@ void File::importFolder(const std::string& folderPath, std::vector& track for ( const auto& audioFile : fs::directory_iterator{ folderPath }) { Track t; t.filePath = static_cast(audioFile.path()); + t.artwork = folderPath + "/" + "cover.png"; + readFileTag( t ); tracks.push_back( t ); } } -void File::readFileTag( const char* fileName, std::vector& tracks ) { - TagLib::FileRef f( fileName ); - Track t; +void File::readFileTag( Track& t ) { + TagLib::FileRef f( reinterpret_cast(&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 ); }