diff --git a/core/tags.cpp b/core/tags.cpp index 0c2c316a..1f21dea6 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -20,13 +20,6 @@ Database track_db("track.db", false); * */ -Track :: Track(const std::string &f, Library *library) - : _album(NULL), _artist(NULL), _genre(NULL), _library(library), - _count(0), _path(f.substr(library->primary_key().size() + 1)) -{ - library->inc_size(); -} - void Track :: read(File &f) { unsigned int library_id, artist_id, album_id, genre_id; @@ -59,50 +52,6 @@ void Track :: write(File &f) f << std::endl << _path << std::endl; } -static inline const std::string format_tag(const TagLib::String &str) -{ - return str.stripWhiteSpace().to8Bit(true); -} - -template -static T *find_or_insert(const T &tag, Database &db) -{ - T *ret = db.find(tag.primary_key()); - if (!ret) - ret = db.insert(tag); - return ret; -} - -bool Track :: tag() -{ - TagLib :: Tag *tag; - TagLib :: AudioProperties *audio; - TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast); - - _library->inc_size(); - if (ref.isNull()) { - print("WARNING: Could not read tags for file %s\n", path().c_str()); - return false; - } - - tag = ref.tag(); - audio = ref.audioProperties(); - - _artist = tags :: get_artist(format_tag(tag->artist())); - _album = tags :: get_album(format_tag(tag->album()), tag->year()); - _genre = tags :: get_genre(format_tag(tag->genre())); - _track = tag->track(); - _length = audio->length(); - //_title = format_tag(tag->title()); - - //title_lower = filter :: add(title, index()); - - filter :: add(_artist->name(), index()); - filter :: add(_album->name(), index()); - - return true; -} - /* * Returns: @@ -181,11 +130,28 @@ void tagdb :: commit() Track *tagdb :: add_track(const std::string &filepath, Library *library) { - Track *track = track_db.insert(Track(filepath, library)); - if (track && !track->tag()) { - remove_track(track->index()); - track = NULL; + Track *track; + TagLib :: Tag *tag; + TagLib :: AudioProperties *audio; + TagLib :: FileRef ref(filepath.c_str(), true, TagLib::AudioProperties::Fast); + + if (ref.isNull()) { + print("WARNING: Could not read tags for file %s\n", filepath.c_str()); + return NULL; } + + tag = ref.tag(); + audio = ref.audioProperties(); + + track = track_db.insert(Track( + tags :: get_album(tag->album().stripWhiteSpace().to8Bit(true), tag->year()), + tags :: get_artist(tag->artist().stripWhiteSpace().to8Bit(true)), + tags :: get_genre(tag->genre().stripWhiteSpace().to8Bit(true)), + library, filepath, + tag->title().stripWhiteSpace().to8Bit(true), + audio->length(), tag->track()) + ); + return track; } diff --git a/core/tags/track.cpp b/core/tags/track.cpp index a471fcae..fce90994 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -22,6 +22,9 @@ Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library, _count(0), _length(length), _track(track), _path(filepath.substr(library->primary_key().size() + 1)) { + //filter :: add(name(), index()); + //filter :: add(_artist->name(), index()); + //filter :: add(_album->name(), index()); _library->inc_size(); } diff --git a/include/core/tags/track.h b/include/core/tags/track.h index deb43980..26bd8023 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -79,13 +79,6 @@ public: Track(Album *, Artist *, Genre *, Library *, const std::string &, const std::string &, unsigned int, unsigned int); - /** - * Track constructor - * @param filepath Filepath of the track - * @param library Library containing the track - */ - Track(const std::string &, Library *); - /** Track destructor */ ~Track(); @@ -137,13 +130,6 @@ public: */ void write(File &); - - /** - * Read the tags associated with this track - * @return True on success - */ - bool tag(); - /** * Compare two tracks based on a specific field. * @param rhs The other track to compare.